Skip to main content

ContextRef

Enum ContextRef 

Source
pub enum ContextRef<'a, T = IriBuf, B = BlankIdBuf> {
    Borrowed(&'a Context<T, B>),
    Owned(Box<Context<T, B>>),
}
Expand description

Either a borrowed context or an owned one held behind a box.

Expansion and compaction repeatedly rebind an active context that may or may not have been replaced by a processed one. A Cow-like type is the natural fit, but Context is over 250 bytes and storing it inline makes every async state machine holding one that much larger — the value is memmoved on every recursion. Boxing the owned arm keeps this two words wide however Context grows, at the cost of one allocation on a path that has just built a whole context anyway.

Variants§

§

Borrowed(&'a Context<T, B>)

Borrowed from the caller.

§

Owned(Box<Context<T, B>>)

Owned by this value.

Implementations§

Source§

impl<T, B> ContextRef<'_, T, B>

Source

pub fn owned(context: Context<T, B>) -> Self

Takes ownership of context, boxing it.

Source

pub fn as_ref(&self) -> &Context<T, B>

Borrows the context, whichever arm holds it.

Source

pub fn is_owned(&self) -> bool

Returns true if the context is owned.

Expansion uses this to detect that scoped-context processing replaced the active context, and that cached key expansions must be recomputed.

Methods from Deref<Target = Context<T, B>>§

Source

pub fn with_private_caches(&self) -> Context<T, B>
where T: Clone, B: Clone,

Returns a copy of this context whose IRI memoisation caches are private to the copy.

Self::term_resolution_cache maps a term to an already-resolved Term, which carries T-typed identifiers. Sharing it across vocabulary forks is unsound: a term that one fork resolved by interning a new IRI would be served to another fork, where that identifier denotes something else entirely — or nothing. Concurrent expansion therefore gives each task a context of its own.

Only the caches are fresh. Definitions, prefix terms and keyword aliases are shared through their Arcs: they are derived from the context’s own definitions, whose identifiers every fork inherits, so they stay valid. The same reasoning covers the inverse context.

Source

pub fn processing_mode(&self) -> ProcessingMode

Returns the processing mode this context was processed under.

Source

pub fn get<Q>(&self, term: &Q) -> Option<TermDefinitionRef<'_, T, B>>
where Key: Borrow<Q>, KeywordType: Borrow<Q>, Q: ?Sized + Hash + Eq,

Returns a reference to the given term definition, if any.

Source

pub fn get_normal<Q>(&self, term: &Q) -> Option<&NormalTermDefinition<T, B>>
where Key: Borrow<Q>, Q: ?Sized + Hash + Eq,

Returns a reference to the given term normal definition, if any.

Source

pub fn get_type(&self) -> Option<&TypeTermDefinition>

Returns a reference to the @type definition, if any.

Source

pub fn contains_term<Q>(&self, term: &Q) -> bool
where Key: Borrow<Q>, KeywordType: Borrow<Q>, Q: ?Sized + Hash + Eq,

Checks if the given term is defined.

Source

pub fn original_base_url(&self) -> Option<&T>

Returns the original base URL of the context.

Source

pub fn base_iri(&self) -> Option<&T>

Returns the base IRI of the context.

Source

pub fn vocabulary(&self) -> Option<&Term<T, B>>

Returns the @vocab value, if any.

Source

pub fn default_language(&self) -> Option<&LenientLangTag>

Returns the default @language value.

Source

pub fn default_base_direction(&self) -> Option<Direction>

Returns the default @direction value.

Source

pub fn previous_context(&self) -> Option<&Self>

Returns a reference to the previous context.

Source

pub fn definitions_arc_ptr(&self) -> *const Definitions<T, B>

Returns the address of the Arc backing the term definitions.

Two contexts that share this pointer share the exact same definitions (copy-on-write via Arc::make_mut). Useful as a cheap fingerprint for memoization keys.

Source

pub fn previous_context_arc_ptr(&self) -> *const Self

Returns the address of the Arc backing the previous context, or null when there is none. See Self::definitions_arc_ptr.

Source

pub fn len(&self) -> usize

Returns the number of terms defined.

Source

pub fn is_empty(&self) -> bool

Checks if no terms are defined.

Source

pub fn definitions(&self) -> &Definitions<T, B>

Returns a handle to the term definitions.

Source

pub fn has_protected_items(&self) -> bool

Checks if the context has a protected definition.

Source

pub fn inverse(&self) -> &InverseContext<T, B>
where T: Clone + Hash + Eq, B: Clone + Hash + Eq,

Returns the inverse context, computing and caching it on first access.

Source

pub fn prefix_terms(&self) -> &[PrefixTerm<T, B>] ⓘ

Returns the term definitions whose prefix flag is true, each paired with its IRI mapping.

The mapping is carried alongside the key so that compaction’s candidate loop does not have to look the definition back up — which would re-hash the very key this list just handed it. Definitions with no IRI mapping cannot form a compact IRI and are left out.

Lazily computed and cached; invalidated whenever a definition is added, removed, or replaced.

Source

pub fn compact_iri_cache( &self, ) -> &ShardedMemo<CompactIriKey<T, B>, Option<Arc<str>>>

Returns the per-context memoization map for the compact-IRI algorithm.

The cache stores results keyed on (var, vocab, reverse, mode). It is invalidated whenever the context’s term definitions, base IRI, vocabulary, language, or direction change, since those affect compaction output.

Source

pub fn term_resolution_cache(&self) -> &ShardedMemo<Box<str>, Arc<Term<T, B>>>

Returns the per-context memoization map for IRI expansion of term keys.

Maps the input string to the resolved Arc<Term>. Populated only by the dominant key-expansion call shape (vocab=Some(Keep), document_relative=false); other shapes bypass this cache. Invalidated alongside the compact-IRI / inverse caches whenever the context’s term definitions, base IRI, vocabulary, language, or direction change.

Source

pub fn keyword_aliases_or_init<F: FnOnce() -> KeywordAliases>( &self, mode: ProcessingMode, init: F, ) -> &KeywordAliases

Returns the cached keyword aliases of this context for the given processing mode, computing them via init on first access. The closure runs once per (context, mode); subsequent calls return the cached value. Aliases are cached per mode because compact-IRI selection is mode-dependent.

Trait Implementations§

Source§

impl<T, B> Deref for ContextRef<'_, T, B>

Source§

type Target = Context<T, B>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.

Auto Trait Implementations§

§

impl<'a, T = Iri<String>, B = BlankIdBuf> !RefUnwindSafe for ContextRef<'a, T, B>

§

impl<'a, T = Iri<String>, B = BlankIdBuf> !UnwindSafe for ContextRef<'a, T, B>

§

impl<'a, T, B> Freeze for ContextRef<'a, T, B>
where &'a Context<T, B>: Freeze, Box<Context<T, B>>: Freeze,

§

impl<'a, T, B> Send for ContextRef<'a, T, B>
where &'a Context<T, B>: Send, Box<Context<T, B>>: Send,

§

impl<'a, T, B> Sync for ContextRef<'a, T, B>
where &'a Context<T, B>: Sync, Box<Context<T, B>>: Sync,

§

impl<'a, T, B> Unpin for ContextRef<'a, T, B>
where &'a Context<T, B>: Unpin, Box<Context<T, B>>: Unpin,

§

impl<'a, T, B> UnsafeUnpin for ContextRef<'a, T, B>
where &'a Context<T, B>: UnsafeUnpin, Box<Context<T, B>>: UnsafeUnpin,

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> BorrowUnordered for T

Source§

fn as_unordered(&self) -> &Unordered<T>

Views this value as an Unordered reference.
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, C> FromWithContext<T, C> for T

Source§

fn from_with(value: T, _context: &C) -> T

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, C> IntoWithContext<U, C> for T
where U: FromWithContext<T, C>,

Source§

fn into_with(self, context: &C) -> U

Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U, C> TryFromWithContext<U, C> for T
where U: IntoWithContext<T, C>,

Source§

type Error = !

Source§

fn try_from_with( value: U, context: &C, ) -> Result<T, <T as TryFromWithContext<U, C>>::Error>

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, U, C> TryIntoWithContext<U, C> for T
where U: TryFromWithContext<T, C>,

Source§

type Error = <U as TryFromWithContext<T, C>>::Error

Source§

fn try_into_with( self, context: &C, ) -> Result<U, <T as TryIntoWithContext<U, C>>::Error>

Source§

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

Source§

fn with<C>(&self, context: C) -> Contextual<&T, C>

Source§

fn into_with<C>(self, context: C) -> Contextual<T, C>
where T: Sized,

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