pub trait FromClientShared {
// Required method
fn from_client_shared(client: &Client) -> Arc<Self>;
}Expand description
Trait for trait objects that can be constructed from a Client as an Arc.
Implementing this on dyn FooTrait makes Arc<dyn FooTrait> extractable via
FromClientPart, so a struct holding another feature client by trait object gets
wired up by #[derive(FromClient)]:
#[derive(FromClient)]
struct OuterClient {
inner: Arc<dyn FooTrait>,
}The impl is typically generated by #[client_trait(via = ...)] from the
bitwarden_core_macro crate. Write one by hand only when the construction shape is unusual.
§Why this trait exists
Orphan-rule workaround. impl FromClientPart<Arc<dyn FooTrait>> for Client would be the
natural way to wire this up, but Rust rejects it from any crate other than bitwarden-core:
both FromClientPart and Client are foreign there, and Arc<_> isn’t a fundamental
wrapper. impl FromClientShared for dyn FooTrait works because dyn FooTrait is a local
type; the blanket FromClientPart impl on Client bridges the two.
Required Methods§
Construct an Arc<Self> from a Client.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.