Skip to main content

MonoThreadGuard

Struct MonoThreadGuard 

Source
pub struct MonoThreadGuard { /* private fields */ }
Expand description

A RAII guard that keeps the current thread attached to the Mono runtime.

Constructing this guard calls mono_thread_attach, registering the thread with the Mono GC and enabling the use of all Mono handle types. Dropping it calls mono_thread_detach, releasing the thread’s entry in the runtime.

§!Send + !Sync

This type deliberately does not implement Send or Sync. mono_thread_detach must be called from the same operating-system thread that called mono_thread_attach. If the guard were moved to another thread and dropped there, it would detach the wrong thread, leaving the original thread permanently registered and causing the detaching thread to corrupt Mono’s internal bookkeeping.

The !Send bound also creates a natural pairing with the handle types in this crate: since all Mono handles are !Send + !Sync, they cannot escape the thread on which they were obtained, and that thread is guaranteed to hold a live guard.

§Panics

The Drop implementation does not panic. If the Mono API is unavailable at drop time (which cannot happen under normal use since the guard can only be constructed after a successful init), a warning is emitted via tracing and the detach is skipped.

Implementations§

Source§

impl MonoThreadGuard

Source

pub unsafe fn attach() -> Result<Self>

Attaches the current thread to the Mono runtime.

This registers the thread with Mono’s garbage collector. Any Mono handle type obtained after this call is safe to use on the current thread for as long as this guard is live.

Prefer creating one guard per thread at the top of the thread’s entry point and keeping it alive for the entire duration of Mono usage on that thread.

§Errors

Returns MonoError::Uninitialized if init has not been called yet.

§Safety

The returned guard must be dropped on the same thread that called attach. Dropping it on a different thread would call mono_thread_detach for the wrong thread, corrupting Mono’s internal thread registry.

Trait Implementations§

Source§

impl Drop for MonoThreadGuard

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more