Trait spirit_tokio::base_traits::ResourceConsumer
source · pub trait ResourceConsumer<Config, O, C>: Sync + Send + 'staticwhere
Config: ResourceConfig<O, C>,{
type Error: Display;
type Future: Future<Item = (), Error = Self::Error> + Send + 'static;
fn build_future(
&self,
spirit: &Arc<Spirit<O, C>>,
config: &Arc<Config>,
resource: Config::Resource,
name: &str
) -> Self::Future;
fn install<N: Name>(builder: Builder<O, C>, _name: &N) -> Builder<O, C> { ... }
}
Expand description
The part that gets a resource and builds a future out of it.
This is the place where application specific code goes. It is given the created resource (or
resources ‒ see the details of construction on ResourceConfig
. It then produces a future
that gets spawned onto a runtime and is dropped when no longer needed.
A closure taking the right parameters (corresponding to build_future
) implements this
trait. In application code, you usually provide either a closure, or closure wrapped by some
decorator function (like per_connection
).
Warning
Errors returned from here are only logged. If some further action is needed to be taken as a result of an error (aborting the program, calling the admin…), it needs to be done as part of the returned future already.
Required Associated Types
Required Methods
sourcefn build_future(
&self,
spirit: &Arc<Spirit<O, C>>,
config: &Arc<Config>,
resource: Config::Resource,
name: &str
) -> Self::Future
fn build_future(
&self,
spirit: &Arc<Spirit<O, C>>,
config: &Arc<Config>,
resource: Config::Resource,
name: &str
) -> Self::Future
Turns the provided resource into a future that’ll get spawned onto a runtime.
Parameters
spirit
: The global spirit object managing the application.config
: The config that led to creation of this resource and implements theResourceConfig
trait. In case of the fragments in this crate, this is mostly useful only if it carries some extra configuration (specified by a type parameter). See theExtraCfgCarrier
trait. User-suppliedResourceConfig
s may of course offer additional interface to interact with them (like having public fields).resource
: The actual resource to use.name
: The name of the resource as it should appear in logs.
Provided Methods
sourcefn install<N: Name>(builder: Builder<O, C>, _name: &N) -> Builder<O, C>
fn install<N: Name>(builder: Builder<O, C>, _name: &N) -> Builder<O, C>
A hook called when this gets plugged into the Builder
.
The provided implementation does nothing (same as implementation for closures). This,
however, allows for further interaction with the Builder
, like installing additional
config_validator
to validate (or modify) the configuration. It is called before
installation of the validator that manages creation of the resource.