pub trait Layer:
Send
+ Sync
+ Debug
+ Unpin
+ 'static {
// Provided methods
fn apply_service(&self, srv: Arc<dyn ServiceDyn>) -> Arc<dyn ServiceDyn> ⓘ { ... }
fn apply_context(
&self,
srv: Arc<dyn ServiceDyn>,
inner: OperationContext,
) -> OperationContext { ... }
}Expand description
Layer intercepts an operator’s composed runtime resources.
A layer receives the current stack for each plane and returns the stack that should be used by operators built with this layer. Implementations can wrap the operation service, the operation context (HTTP transport and executor), or both.
Operator applies layers by first composing the service
stack with Layer::apply_service, then composing OperationContext with
Layer::apply_context. The context hook receives the final service stack
so resource wrappers can observe service identity or capability when needed.
Hooks take &self, so layers that keep mutable state must use interior
mutability. That state must remain Send and Sync because layers are
shared across cloned operators and concurrent operations.
Provided Methods§
Sourcefn apply_service(&self, srv: Arc<dyn ServiceDyn>) -> Arc<dyn ServiceDyn> ⓘ
fn apply_service(&self, srv: Arc<dyn ServiceDyn>) -> Arc<dyn ServiceDyn> ⓘ
Intercept the operation service stack.
Operation layers should return a service that forwards unchanged
operations to inner.
Sourcefn apply_context(
&self,
srv: Arc<dyn ServiceDyn>,
inner: OperationContext,
) -> OperationContext
fn apply_context( &self, srv: Arc<dyn ServiceDyn>, inner: OperationContext, ) -> OperationContext
Intercept the operation context (HTTP transport and executor).
Return inner unchanged for layers that do not affect HTTP requests or
spawned tasks.