pub struct ClientHub { /* private fields */ }Expand description
Type-safe registry of clients keyed by interface type.
A hub is shared storage plus an optional owner gear. Self::for_gear
returns a view of the same storage owned by a gear; GearCtx::client_hub
hands each gear its own view. Plain and scoped registrations are shared by
all views. Remote proxies registered through a view belong to its owner.
Implementations§
Source§impl ClientHub
impl ClientHub
pub fn new() -> Self
Sourcepub fn for_gear(&self, gear: impl Into<Arc<str>>) -> Arc<Self> ⓘ
pub fn for_gear(&self, gear: impl Into<Arc<str>>) -> Arc<Self> ⓘ
A view of this hub’s storage owned by gear.
Local and scoped registrations are shared with every other view. A remote proxy registered through the view is seen only by this view and does not replace another gear’s proxy for the same contract.
Source§impl ClientHub
impl ClientHub
Sourcepub fn register<T>(&self, client: Arc<T>)
pub fn register<T>(&self, client: Arc<T>)
Register a client under the interface type T.
T can be a trait object like dyn my_gear::api::MyClient.
The registration is shared by every view and wins over any remote
proxy for T in Self::get, also when it is registered after one.
Sourcepub fn register_scoped<T>(&self, scope: ClientScope, client: Arc<T>)
pub fn register_scoped<T>(&self, scope: ClientScope, client: Arc<T>)
Register a scoped client under the interface type T.
This enables multiple implementations of the same interface to coexist,
distinguished by a caller-defined ClientScope (e.g., a GTS instance ID).
Sourcepub fn get<T>(&self) -> Result<Arc<T>, ClientHubError>
pub fn get<T>(&self) -> Result<Arc<T>, ClientHubError>
Fetch a client by interface type T.
Returns, in order: a local registration, this view’s remote proxy, a process-wide remote proxy.
§Errors
Returns ClientHubError::NotFound if no client is registered for the type.
Returns ClientHubError::TypeMismatch if the stored type doesn’t match.
Sourcepub fn try_get<T>(&self) -> Option<Arc<T>>
pub fn try_get<T>(&self) -> Option<Arc<T>>
Try to fetch a client by interface type T.
Same lookup order as Self::get; returns None if nothing is
registered or the stored type doesn’t match. Use Self::try_get_local
when the answer needs to mean “satisfied in-process”.
Sourcepub fn register_remote_proxy<T>(&self, client: Arc<T>)
pub fn register_remote_proxy<T>(&self, client: Arc<T>)
Register a client that is a discovery-resolving proxy to a remote provider, not an in-process implementation.
The proxy belongs to this view’s owner, or is process-wide when the hub
has no owner. It never hides a local registration of T.
Sourcepub fn try_get_local<T>(&self) -> Option<Arc<T>>
pub fn try_get_local<T>(&self) -> Option<Arc<T>>
Try to fetch a client by interface type T, ignoring remote proxies.
This is the short-circuit probe for consumer wiring: a compile-time
(local) registration takes priority over a discovery-based proxy, so the
wiring closure asks whether a local implementation exists before
registering one of its own. Seeing a proxy here would let a consumer
report its dependency as local and turn /readyz green before the
provider exists.
Sourcepub fn has_remote_proxy<T>(&self) -> bool
pub fn has_remote_proxy<T>(&self) -> bool
Whether this view already holds a remote proxy for interface type T:
its owner’s proxy, or the process-wide one for a hub without an owner.
Another gear’s proxy does not count, so each consumer builds a proxy from its own wiring settings.
Sourcepub fn get_scoped<T>(
&self,
scope: &ClientScope,
) -> Result<Arc<T>, ClientHubError>
pub fn get_scoped<T>( &self, scope: &ClientScope, ) -> Result<Arc<T>, ClientHubError>
Fetch a scoped client by interface type T and scope.
§Errors
Returns ClientHubError::ScopedNotFound if no client is registered for the (type, scope) pair.
Returns ClientHubError::ScopedTypeMismatch if the stored type doesn’t match.
Sourcepub fn try_get_scoped<T>(&self, scope: &ClientScope) -> Option<Arc<T>>
pub fn try_get_scoped<T>(&self, scope: &ClientScope) -> Option<Arc<T>>
Try to fetch a scoped client by interface type T and scope.
Returns None if not found or if the stored type doesn’t match.
Sourcepub fn remove<T>(&self) -> Option<Arc<T>>
pub fn remove<T>(&self) -> Option<Arc<T>>
Remove a local client by interface type; returns the removed client if it was present. Remote proxies are not touched.
Sourcepub fn remove_scoped<T>(&self, scope: &ClientScope) -> Option<Arc<T>>
pub fn remove_scoped<T>(&self, scope: &ClientScope) -> Option<Arc<T>>
Remove a scoped client by interface type + scope; returns the removed client if it was present.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for ClientHub
impl !UnwindSafe for ClientHub
impl Forget for ClientHub
impl Freeze for ClientHubwhere
*const ArcInner<Storage> is !null: Freeze,
PhantomData<ArcInner<Storage>>: Freeze,
*const ArcInner<str> is !null: Freeze,
PhantomData<ArcInner<str>>: Freeze,
impl Move for ClientHub
impl Send for ClientHub
impl Sync for ClientHub
impl Unpin for ClientHub
impl UnsafeUnpin for ClientHubwhere
*const ArcInner<Storage> is !null: UnsafeUnpin,
PhantomData<ArcInner<Storage>>: UnsafeUnpin,
*const ArcInner<str> is !null: UnsafeUnpin,
PhantomData<ArcInner<str>>: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ServiceExt for T
impl<T> ServiceExt for T
Source§fn decompression(self) -> Decompression<Self>where
Self: Sized,
fn decompression(self) -> Decompression<Self>where
Self: Sized,
Source§fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>where
Self: Sized,
fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>where
Self: Sized,
Source§fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>where
Self: Sized,
fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>where
Self: Sized,
Source§fn follow_redirects(self) -> FollowRedirect<Self>where
Self: Sized,
fn follow_redirects(self) -> FollowRedirect<Self>where
Self: Sized,
Source§fn set_request_id<M>(
self,
header_name: HeaderName,
make_request_id: M,
) -> SetRequestId<Self, M>where
Self: Sized,
M: MakeRequestId,
fn set_request_id<M>(
self,
header_name: HeaderName,
make_request_id: M,
) -> SetRequestId<Self, M>where
Self: Sized,
M: MakeRequestId,
Source§fn set_x_request_id<M>(self, make_request_id: M) -> SetRequestId<Self, M>where
Self: Sized,
M: MakeRequestId,
fn set_x_request_id<M>(self, make_request_id: M) -> SetRequestId<Self, M>where
Self: Sized,
M: MakeRequestId,
x-request-id as the header name. Read moreSource§fn propagate_request_id(
self,
header_name: HeaderName,
) -> PropagateRequestId<Self>where
Self: Sized,
fn propagate_request_id(
self,
header_name: HeaderName,
) -> PropagateRequestId<Self>where
Self: Sized,
Source§fn propagate_x_request_id(self) -> PropagateRequestId<Self>where
Self: Sized,
fn propagate_x_request_id(self) -> PropagateRequestId<Self>where
Self: Sized,
x-request-id as the header name. Read moreSource§fn catch_panic(self) -> CatchPanic<Self, DefaultResponseForPanic>where
Self: Sized,
fn catch_panic(self) -> CatchPanic<Self, DefaultResponseForPanic>where
Self: Sized,
500 Internal Server responses. Read moreSource§fn request_body_limit(self, limit: usize) -> RequestBodyLimit<Self>where
Self: Sized,
fn request_body_limit(self, limit: usize) -> RequestBodyLimit<Self>where
Self: Sized,
413 Payload Too Large responses. Read moreSource§impl<T> ServiceExt for T
impl<T> ServiceExt for T
Source§fn map_response_body<F>(self, f: F) -> MapResponseBody<Self, F>where
Self: Sized,
fn map_response_body<F>(self, f: F) -> MapResponseBody<Self, F>where
Self: Sized,
Source§fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>where
Self: Sized,
fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>where
Self: Sized,
Source§fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>where
Self: Sized,
fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>where
Self: Sized,
Source§fn follow_redirects(self) -> FollowRedirect<Self>where
Self: Sized,
fn follow_redirects(self) -> FollowRedirect<Self>where
Self: Sized,
Source§impl<T> WithSecurityContext for T
impl<T> WithSecurityContext for T
Source§fn security_ctx<'a>(&'a self, ctx: &'a SecurityContext) -> Secured<'a, T>where
T: Sized,
fn security_ctx<'a>(&'a self, ctx: &'a SecurityContext) -> Secured<'a, T>where
T: Sized,
Secured wrapper. Read more