sfackler/r2d2

Why example use `let pool = pool.clone()` in a for loop ?

linrongbin16 opened this issue · 2 comments

I want to use r2d2 with diesel for connecting mysql and sqlite3.

In example code:

use std::thread;

extern crate r2d2;
extern crate r2d2_foodb;

fn main() {
    let manager = r2d2_foodb::FooConnectionManager::new("localhost:1234");
    let pool = r2d2::Pool::builder()
        .max_size(15)
        .build(manager)
        .unwrap();

    for _ in 0..20 {
        let pool = pool.clone();
        thread::spawn(move || {
            let conn = pool.get().unwrap();
            // use the connection
            // it will be returned to the pool when it falls out of scope.
        })
    }
}

I don't get the meaning of the pool.clone, can I simply remove this line ?

What happens when you try to remove the line?