aboutsummaryrefslogtreecommitdiff
path: root/src/interfaces/async_injectable.rs
blob: fb5452b3c99265560553707242dc274fddfbfcc9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
//! Interface for structs that can be injected into or be injected to.
//!
//! *This module is only available if Syrette is built with the "async" feature.*
use std::fmt::Debug;
use std::sync::Arc;

use async_trait::async_trait;

use crate::async_di_container::AsyncDIContainer;
use crate::errors::injectable::InjectableError;
use crate::libs::intertrait::CastFromSync;
use crate::ptr::TransientPtr;

/// Interface for structs that can be injected into or be injected to.
#[async_trait]
pub trait AsyncInjectable: CastFromSync
{
    /// Resolves the dependencies of the injectable.
    ///
    /// # Errors
    /// Will return `Err` if resolving the dependencies fails.
    async fn resolve(
        di_container: &Arc<AsyncDIContainer>,
        dependency_history: Vec<&'static str>,
    ) -> Result<TransientPtr<Self>, InjectableError>
    where
        Self: Sized;
}

impl Debug for dyn AsyncInjectable
{
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result
    {
        f.write_str("{}")
    }
}