pub struct ServiceBuilder { /* private fields */ }
Expand description
A builder for Service
.
Implementations§
Source§impl ServiceBuilder
impl ServiceBuilder
Sourcepub fn new() -> Result<Self, ServiceError>
pub fn new() -> Result<Self, ServiceError>
Creates a new builder.
Returns an error if called within a Tokio runtime context.
Sourcepub fn on_runtime(runtime: Runtime) -> Self
pub fn on_runtime(runtime: Runtime) -> Self
Creates a new builder with the provided Tokio runtime. This method can be used if asynchronous tasks must be performed before the service is built.
However, it is not recommended to use this method to spawn any tasks that will not be managed
by the service itself, so whenever it can be avoided, using ServiceBuilder::new
is preferred.
Sourcepub fn runtime_handle(&self) -> Handle
pub fn runtime_handle(&self) -> Handle
Returns a handle to the Tokio runtime used by the service.
Sourcepub fn add_layer<T: WiringLayer>(&mut self, layer: T) -> &mut Self
pub fn add_layer<T: WiringLayer>(&mut self, layer: T) -> &mut Self
Adds a wiring layer.
During the run
call the service will invoke
wire
method of every layer in the order they were added.
This method may be invoked multiple times with the same layer type, but the layer will only be stored once (meaning that 2nd attempt to add the same layer will be ignored). This may be useful if the same layer is a prerequisite for multiple other layers: it is safe to add it multiple times, and it will only be wired once.