Hello
I think I have a very basic typical Rust error. But I don't understand it all. Can someone explain on how to solve this issue, and what's the cause of it?
Code:
//Function to establish (a pooled) connection with the MySQL database. This connection
//is stored in self.conn
pub fn init_connection(database_name : &String, database_user : &String, database_pass : &String) -> std::result::Result<mysql::Pool, mysql::Error> {
//Create connection with database
let conn_str : String = format!("mysql://{user}:{pass}@localhost:3307/{name}", user=database_user, pass=database_pass, name=database_name);
let conn : std::result::Result<mysql::Pool, mysql::Error> = mysql::Pool::new(conn_str);
//Check if connection was succesful
match conn {
Ok(t) => {
println!("Connection to {} succesfully made...", database_name);
conn
},
Err(e) => {
eprintln!("Connection to {} failed: {}", database_name, e.description());
std::process::exit(-1);
},
}
}
Error:
error[E0382]: use of moved value: `conn`
--> src/main.rs:327:21
|
325 | Ok(t) => {
| - value moved here
326 | println!("Connection to {} succesfully made...", database_name);
327 | conn
| ^^^^ value used here after partial move
|
= note: move occurs because value has type `mysql::Pool`, which does not implement the `Copy` trait
Thanks!