Handling Master Slave database configuration in Rocket

Rocket provides a way to inject database pool using guards

However, I want have a master slave structure. 1 master for write and 4 slaves to read (slaves are selected at random to read)

so I guess my routes function will be like
fn register_user_handler(conn: DbConnMaster, conn1 : DbConnSlave1, conn2 : DbConnSlave2 ...)

Also, I have 5 such Databases with master slave configuration . So around 25 connection pools . Specifying all those connection as guard in handler seems verbose.

So I was wondering if there is a better way in which I can keep those connection pool and use it across my application safely?

Maybe you can wrap those connections into a struct?

pub struct DbCollection {
    pub conn1: DbConnMaster,
    pub conn2: DbConnSlave,

let newDbCollection = DbCollection {
    conn1: DbConnMaster::new(),
    conn2: DbConnSlave::new(),


fn something(db_collection: State<DbCollection>)
1 Like