From 080cc42bb1da09059dbc35049a7ded0649961e0c Mon Sep 17 00:00:00 2001 From: HampusM Date: Mon, 29 Aug 2022 20:52:56 +0200 Subject: feat: implement async functionality --- src/interfaces/async_injectable.rs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/interfaces/async_injectable.rs (limited to 'src/interfaces/async_injectable.rs') diff --git a/src/interfaces/async_injectable.rs b/src/interfaces/async_injectable.rs new file mode 100644 index 0000000..badc3c5 --- /dev/null +++ b/src/interfaces/async_injectable.rs @@ -0,0 +1,35 @@ +//! 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 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: &AsyncDIContainer, + dependency_history: Vec<&'static str>, + ) -> Result, InjectableError> + where + Self: Sized; +} + +impl Debug for dyn AsyncInjectable +{ + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result + { + f.write_str("{}") + } +} -- cgit v1.2.3-18-g5258