Skip to main content

Context

Struct Context 

Source
pub struct Context {
    pub content: Arc<Mutex<ContentMap>>,
    pub lookup_handler: LookupHandler<Id, ContentStatus, Error>,
    pub loaded: AtomicUsize,
}
Expand description

Registry and loading context for DOM content, tracking declared content entries, de-duplicating in-flight load requests and counting loaded items.

Fields§

§content: Arc<Mutex<ContentMap>>

Map of registered content entries keyed by their id.

§lookup_handler: LookupHandler<Id, ContentStatus, Error>

Coordinates concurrent load requests so that each content id is only loaded once while other callers await the shared result.

§loaded: AtomicUsize

Running count of content entries that have been loaded.

Implementations§

Source§

impl Context

Source

pub fn declare(&self, content: ContentList<'_>)

Register the given content entries with this context, making them available for later loading by id.

Source

pub fn get(&self, id: &Id) -> Option<Arc<Content>>

Return the registered Content entry for the given id, if any.

Source

pub async fn load_content( self: &Arc<Self>, content: Arc<Content>, ) -> Result<ContentStatus>

Load a single content entry, injecting it into the DOM. Concurrent requests for the same content are de-duplicated via the lookup handler, and already-loaded content resolves immediately as ContentStatus::Exists.

Source

pub async fn load_ids(self: &Arc<Self>, list: &[Id]) -> Result<()>

Load all content entries identified by the given list of ids, resolving and injecting each into the DOM, and log the total number of references loaded along with the elapsed time.

Trait Implementations§

Source§

impl Default for Context

Source§

fn default() -> Self

Returns the “default value” for a 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> Any for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Source§

fn type_name(&self) -> &'static str

Source§

impl<T> AnySync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

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.
Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more