Nashenas88/coi

Add support for generics

Closed this issue · 0 comments

It would be nice to have some injected structs that are generic, and the providers would be generic as well.

Example:

#[derive(Inject)]
#[provides(Pool<T> with Pool::new())]
struct Pool<T>(RealPoolType<T>);

impl<T> Pool<T> {
    fn new() -> Self {
      let pool = // construct pool with T
      Self(pool)
    }
}

let container = container! {
    pool => PoolProvider<Tls>
};

let pool = container.resolve::<Pool<Tls>>("pool");