Skip to main content

ContextRegistry

Struct ContextRegistry 

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

The extension-side concrete representation of a Context.

This can be considered the actual context instance, while Context serves as an abstract handle or outer wrapper around it.

Can only be constructed through [CurrentContext::with_context_initializer].

Implementations§

Source§

impl ContextRegistry

Source

pub fn context_type(&self) -> Option<UCStr>

Returns the context type associated with the context.

This corresponds to the contextType argument passed to ExtensionContext.createExtensionContext.

Returns None if that argument was null.

Source

pub fn context_data(&self) -> Option<&dyn Any>

Returns an immutable reference to the Context Data associated with the context.

Context Data is user-defined data bound to the context, sharing the same lifetime as the context itself.

It can only be set via the first return value of ContextInitializer.

Source

pub fn context_data_mut(&mut self) -> Option<&mut dyn Any>

Returns a mutable reference to the Context Data associated with the context.

Context Data is user-defined data bound to the context, sharing the same lifetime as the context itself.

It can only be set via the first return value of ContextInitializer.

Source

pub fn with_extension_data<F, R>(&self, f: F) -> Option<R>
where F: FnOnce(&mut dyn Any) -> R,

Provides access to the Extension Data.

The Extension Data is set from the return value of Initializer. It can be accessed across threads and is synchronized via a Mutex, providing exclusive access on each call.

Calling this method within nested Function invocations can lead to deadlocks. It is recommended to avoid accessing it within a Function call stack, and instead perform synchronization between Context Data and Extension Data in ContextInitializer and ContextFinalizer.

Trait Implementations§

Source§

impl Debug for ContextRegistry

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. 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, 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.