pub struct Handler<T> { /* private fields */ }Expand description
Heap-allocated, reference-counted holder for a callback the C client keeps and fires later, possibly many times, from the conductor thread.
C is handed a pointer to the value (Handler::as_raw), so the value must outlive
C’s use of it. Methods that register a retained callback store a clone in the
client’s dependencies: a close is asynchronous, and the conductor may still fire
the callback after the resource’s handle has dropped. The clones therefore live
until the client drops, one small Arc per registration.
For callbacks C fires only during the call, prefer the *_fn / *_once methods:
the closure stays on the stack, may borrow local state, and allocates nothing.
Send when T is; Sync only under the multi-threaded feature, since callbacks
fire on the conductor thread.
use rusteron_code_gen::Handler;
let handler = Handler::new(your_value);
// the value is freed when the last clone of `handler` goes out of scopeImplementations§
Trait Implementations§
impl<T: Send> Send for Handler<T>
Auto Trait Implementations§
impl<T> !RefUnwindSafe for Handler<T>
impl<T> !Sync for Handler<T>
impl<T> !UnwindSafe for Handler<T>
impl<T> Freeze for Handler<T>
impl<T> Unpin for Handler<T>
impl<T> UnsafeUnpin for Handler<T>
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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 more