Rust connecting to mysql issue

hi friends,

I'm using rust for connecting to mysql, but I got block on this issue, the code is as follows:

struct APACmysql {
    pool: Pool,

impl APACmysql {
    fn new() -> Result<Self, mysql::Error> {
        let mysql_hostname = env::var("PRD_MYSQL_HOST").map_err(|_| "DB Hostname not set")?;
        let mysql_username = env::var("PRD_MYSQL_USER").map_err(|_| "DB username not set")?;
        let mysql_password = env::var("PRD_MYSQL_PASSED").map_err(|_| "DB password not set")?;
        let mysql_db = env::var("PRD_MYSQL_DB").map_err(|_| "DB database not set")?;
        let url = format!(
            mysql_username, mysql_password, mysql_hostname, mysql_db

        let pool = mysql::Pool::new_manual(1, 1, url.as_str())?;
        //let mut conn = pool.get_conn()?;
        Ok(Self { pool })

I don't know why it raised this error:

error[E0107]: type alias takes 1 generic argument but 2 generic arguments were supplied
   --> src/
30  |     fn new() -> Result<Self, mysql::Error> {
    |                 ^^^^^^       ------------ help: remove this generic argument
    |                 |
    |                 expected 1 generic argument

pls help... thanks in advance guys!

One of the libraries you're using probably defines a typealias of Result that uses the library's error type. You may have imported it with a glob import like use mysql::*; or imported it explicitly by choosing the wrong code completion if your editor supports that. If you remove the relevant import it should fix that error. I believe you could also explicitly re-import std::result::Result again as well.

yes! I did use use mysql::*;, and it works after using std::result::Result<Self, mysql::Error>, thanks for the help!

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.