pub trait ServiceDependencyExt {
// Required method
fn service<T>(self) -> Self
where T: Service + 'static;
}Expand description
Extension trait for Dependencies to add service dependency declarations.
This trait provides a convenient method for declaring dependencies on services
within a Dependencies object.
Required Methods§
Sourcefn service<T>(self) -> Selfwhere
T: Service + 'static,
fn service<T>(self) -> Selfwhere
T: Service + 'static,
Adds a service dependency to the dependencies set.
This method allows declaring that a plugin or service depends on another service, ensuring the dependency will be built before the dependent component.
§Type Parameters
T- The service type to depend on. Must implementService + 'static.
§Returns
Returns Self for method chaining.
§Examples
use diode::{Dependencies, Service, ServiceDependencyExt, StdError};
use std::sync::Arc;
struct DatabaseService;
struct ApiService;
impl Service for DatabaseService {
type Handle = Arc<Self>;
async fn build(_app: &diode::AppBuilder) -> Result<Self::Handle, StdError> {
Ok(Arc::new(Self))
}
}
impl Service for ApiService {
type Handle = Arc<Self>;
async fn build(_app: &diode::AppBuilder) -> Result<Self::Handle, StdError> {
Ok(Arc::new(Self))
}
fn dependencies() -> Dependencies {
Dependencies::new().service::<DatabaseService>()
}
}Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.