Crate mysql - access a database

I'm new to Rust. I have read the Rust book, several tutorials, and worked my way through the rustlings exercises.
My problem is that I am trying to access a db on localhost by using the example code from the mysql crate
When building I receive the following error:

let pool = Pool::new(url)?;

17  | let pool = Pool::new(url)?;
    |            --------- ^^^ the trait `From<&str>` is not implemented for `Opts`
    |            |
    |            required by a bound introduced by this call

I supplied a correct username/password and the database exists.
I'm still trying to get my head around traits so this one has me baffled.
I'd appreciate some guidance.

It looks like the example code for that crate doesn't line up with the actual API - you're meant to pass an Opts struct into Pool::new instead.

You're spot on. The following worked:
let url = Opts::from_url("mysql://user:password@localhost:3307/db_test").unwrap();

Thanks for the response!

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.