pub struct ReadyBinding<S> { /* private fields */ }Expand description
A service paired with persistent readiness.
Construct directly with Self::new or apply ReadyBindingMiddleware
to a factory to wrap each service it creates.
Ctx::ready and Ctx::call reuse the binding’s successful readiness
until a subscribed crate::ReadyNotifier invalidates it. Calls do not
consume readiness. Services whose readiness can change must subscribe through
BindCtx::subscribe in Service::bind and notify when it changes.
Direct Service::call also checks this binding’s cache through Ctx.
A binding owns its service, not pipeline state. Its scope is allocated lazily in the first pipeline that binds it. Rebinding within that pipeline reuses its scope and forwards binding to the wrapped service; binding the same instance to another pipeline panics.
Self::with_data assigns user data passed to every crate::ReadyCallback
registered in this binding’s scope. The default value is 0.
Cloning a binding preserves its data and clones the service into a fresh,
unbound scope.
Use std::rc::Rc<ReadyBinding<S>> to share readiness within one pipeline.
To share a gate across pipelines, use crate::Pipeline or
crate::pipeline::PipelineState and crate::ReadyLink instead.
Every enclosing service must forward Service::bind to this binding.
Runtime operations panic if the calling scope has not bound it, rather than
silently adding a dependency or losing readiness notifications.
Implementations§
Source§impl<S> ReadyBinding<S>
impl<S> ReadyBinding<S>
Sourcepub fn new(service: S) -> Self
pub fn new(service: S) -> Self
Pairs a service with a fresh readiness scope and callback data 0.
Its dependencies are wired when a pipeline or enclosing service binds it.
Sourcepub fn with_data(service: S, data: usize) -> Self
pub fn with_data(service: S, data: usize) -> Self
Pairs a service with a fresh readiness scope and user-defined callback data.
Every callback registered in this scope receives data, including when
notified by a dependency. The value is installed before the inner
service’s Service::bind hook and is preserved when the binding is
cloned or rebound. Construction does not allocate readiness storage.
Sourcepub fn map<T>(self, f: impl FnOnce(S) -> T) -> ReadyBinding<T>
pub fn map<T>(self, f: impl FnOnce(S) -> T) -> ReadyBinding<T>
Transforms the service while preserving its scope, cached readiness, and data.
The transformation must preserve the service’s readiness dependencies,
notification sources, and the validity of any cached readiness. This does
not rebind the service or invalidate its cache. Use Self::new for a
replacement with different dependencies.