Trait Layer
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.
§Capability Validation
Operator validates correctness-critical options against
the outermost composed Service::capability before calling into the
service stack. Layers that add, restrict, or replace operation behavior must
reflect those changes in Service::capability.
Layers that dispatch operations to a separate Service whose capability
is not reflected in the outer stack’s Service::capability (for example,
a routing layer forwarding to target operators) must revalidate operation
arguments with the corresponding Op*::check method against the target
service’s capability before dispatch.
Provided Methods§
fn 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.
fn 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.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".