Trait runtime_injector_actix::Interface [−][src]
pub trait Interface: Service { fn downcast(
service: Arc<dyn Any + 'static + Sync + Send>
) -> Result<Arc<Self>, InjectError>; fn downcast_owned(
service: Box<dyn Any + 'static + Sync + Send, Global>
) -> Result<Box<Self, Global>, InjectError>; }
Expand description
Indicates functionality that can be implemented.
For example, each Sized
Service
type is an interface that
implements itself. This is done by requesting instances of itself from the
injector. However, the injector cannot provide instances of dynamic types
(dyn Trait
) automatically because they are unsized. For this reason, any
interfaces using traits must be declared explicitly before use. This trait
should usually be implemented by the interface!
macro in the same
module the trait was declared in.
Since implementations of interfaces must be services, interfaces should be
declared with a supertrait of Service
. This will ensure that the
implementors can be cast to dyn Any
, and with the “arc”
feature enabled, those implementors are also Send
+ Sync
.
Additionally, trait interfaces must be convertible to trait objects so they
can be used behind service pointers. You can read more about trait objects
here.
See the documentation for the interface!
macro for more information.
Required methods
fn downcast(
service: Arc<dyn Any + 'static + Sync + Send>
) -> Result<Arc<Self>, InjectError>
[src]
service: Arc<dyn Any + 'static + Sync + Send>
) -> Result<Arc<Self>, InjectError>
Expand description
Downcasts a dynamic service pointer into a service pointer of this interface type.
fn downcast_owned(
service: Box<dyn Any + 'static + Sync + Send, Global>
) -> Result<Box<Self, Global>, InjectError>
[src]
service: Box<dyn Any + 'static + Sync + Send, Global>
) -> Result<Box<Self, Global>, InjectError>
Expand description
Downcasts an owned dynamic service pointer into an owned service pointer of this interface type.