Skip to main content

SharedHandle

Trait SharedHandle 

Source
pub trait SharedHandle<T: 'static>: Clone + 'static {
    // Required method
    fn get(&self) -> &T;
}
Expand description

Shared handle to a single owned-or-borrowed T.

One trait covering every “Server holds an Arc<T> for sharing between its run loop and consumer-side tasks” pattern in this crate. Replaces the three separate handle traits this crate shipped earlier (SocketHandle, SdStateHandle, EventPublisherHandle), each of which had the same shape with a different concrete T.

Two impls ship out of the box, both via blanket impls so any consumer-defined type wrapped in Arc<T> or &'static T satisfies the bound automatically:

  • Arc<T>: SharedHandle<T> on alloc-using builds (std or bare_metal-with-alloc). Arc::clone increments the refcount; get returns the inner reference.
  • &'static T: SharedHandle<T> on bare-metal-no-alloc. The reference is Copy + Clone + 'static; the user declares the underlying static storage at boot.

Clone + 'static only — neither Send nor Sync at the trait level. Method-level where clauses on Server add Send bounds at the use sites that need them (announcement_loop’s + Send return type, etc.).

T: 'static because both blanket impls require it: an Arc<T> is 'static only when T: 'static, and &'static T requires T: 'static by definition.

?Sized is intentionally NOT supported — the inline-construction path (WrappableSharedHandle::wrap) needs an owned T, which requires Sized.

Required Methods§

Source

fn get(&self) -> &T

Borrow the underlying T. Both blanket impls return a reference into the underlying storage; consumers should not assume more than a fresh borrow’s worth of lifetime.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<T: 'static> SharedHandle<T> for &'static T

Source§

fn get(&self) -> &T

Source§

impl<T: 'static> SharedHandle<T> for Arc<T>

Available on crate feature _alloc only.
Source§

fn get(&self) -> &T

Implementors§