blackbeam / rust-mysql-simple

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

Add pool_constraints method to OptsBuilder to set pool_min and pool_max #368

Open Elcoid opened 8 months ago

Elcoid commented 8 months ago

Hello,

I added a method to OptsBuilder that sets pool_min and pool_max directly. This way, they can be set without having to instantiate a hashmap, then pass it to from_hash_map, then parse the strings in the map as integers. The method sets the two at the same time to ensure that pool_min <= pool_max (using a PoolConstraints).

blackbeam commented 8 months ago

Hi. I don't really think it's a good idea to increase the API surface. Why don't you use OptsBuilder::pool_opts?

Elcoid commented 8 months ago

Hello, Initially I searched for pool_min and pool_max in the sources, but the only thing I found was OptsBuilder::from_hash_map. That's why I thought an extra method would be good. However I just tried your suggestion and it works well (thanks for the idea). So I think my PR can be dismissed.

Here is what I ended up with, in case anyone else has the same problem as me:

let opts = OptsBuilder::new()
    /* [...] */
    .pool_opts(
        PoolOpts::default()
        .with_constraints(PoolConstraints::new(my_min, my_max).expect("Min is bigger than max!"))
    );