blackbeam / rust-mysql-simple

Mysql client library implemented in rust.
Apache License 2.0
658 stars 144 forks source link

example code does not work in version 21 mysql crate #283

Closed haochiya closed 3 years ago

haochiya commented 3 years ago

CODE: use mysql::; use mysql::prelude::; fn main() { let url = "mysql://root:password@localhost:3307/db_name"; let pool = Pool::new(url).unwrap(); let mut conn = pool.get_conn().unwrap(); .... }

ERROR: let pool = Pool::new(url).unwrap(); the trait 'From<&str>' is not implemented for 'Opts'

blackbeam commented 3 years ago

Hi. The From<&str> for Opts impl was removed in v21, sorry for not mentioning in the release notes. I'll migrate to TryFrom in the future, but for now please use Opts::from_url:

use mysql::*;
use mysql::prelude::*;
fn main() {
let url = "mysql://root:password@localhost:3307/db_name";
let opts = Opts::from_url(url).unwrap();
let pool = Pool::new(opts).unwrap();
let mut conn = pool.get_conn().unwrap();
haochiya commented 3 years ago

Thank you!