[−][src]Crate async_injector_derive
Helper derive to implement a provider.
Examples
use async_injector::{Provider, Injector, Key, async_trait}; use serde::Serialize; /// Fake database connection. #[derive(Clone)] struct Database; /// Provider that describes how to construct a database. #[derive(Serialize)] pub enum Tag { DatabaseUrl, ConnectionLimit, } #[derive(Provider)] struct DatabaseProvider { #[dependency(tag = "Tag::DatabaseUrl")] url: String, #[dependency(tag = "Tag::ConnectionLimit")] connection_limit: u32, } #[async_trait] impl Provider for DatabaseProvider { type Output = Database; /// Constructor a new database and supply it to the injector. async fn build(self) -> Option<Self::Output> { println!("Url: {:?}", self.url); println!("Connection Limit: {:?}", self.connection_limit); None } }
Derive Macros
Provider | Helper derive to implement a provider. |