Skip to main content

Context

Struct Context 

Source
pub struct Context<T = IriBuf, B = BlankIdBuf> { /* private fields */ }
Expand description

Active context: everything the algorithms need to expand or compact against the current scope.

Implementations§

Source§

impl<T, B> Context<T, B>

Source

pub fn new(base_iri: Option<T>) -> Self
where T: Clone,

Create a new context with the given base IRI.

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 set_processing_mode(&mut self, mode: ProcessingMode)

Sets the processing mode of this context.

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.

Source

pub fn set_normal( &mut self, key: Key, definition: Option<NormalTermDefinition<T, B>>, ) -> Option<NormalTermDefinition<T, B>>
where T: Clone, B: Clone,

Sets the normal definition for the given term key.

Source

pub fn set_type( &mut self, type_: Option<TypeTermDefinition>, ) -> Option<TypeTermDefinition>
where T: Clone, B: Clone,

Sets the @type definition.

Source

pub fn set_base_iri(&mut self, iri: Option<T>)

Sets the base IRI.

Source

pub fn set_vocabulary(&mut self, vocab: Option<Term<T, B>>)

Sets the @vocab value.

Source

pub fn set_default_language(&mut self, lang: Option<LenientLangTagBuf>)

Sets the default @language value.

Source

pub fn set_default_base_direction(&mut self, dir: Option<Direction>)

Sets the default @direction value.

Source

pub fn set_previous_context(&mut self, previous: Self)

Sets the previous context.

Source

pub fn into_syntax_definition( self, vocabulary: &impl Vocabulary<Iri = T, BlankId = B>, ) -> Result<Definition, InvalidContextError>
where T: Clone, B: Clone,

Converts this context into its syntactic definition.

§Errors

Returns an error when a term in the context cannot be represented in syntax form, which happens if the vocabulary has no IRI for an identifier it holds.

Source

pub fn map_ids<U, C>( self, map_iri: impl FnMut(T) -> U, map_id: impl FnMut(Id<T, B>) -> Id<U, C>, ) -> Context<U, C>
where T: Clone, B: Clone,

Rewrites every IRI and identifier of this context with the given functions.

Trait Implementations§

Source§

impl<T: Clone, B: Clone> Clone for Context<T, B>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T, B> Default for Context<T, B>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'a, T: Clone + Hash + Eq, B: Clone + Hash + Eq> From<&'a Context<T, B>> for InverseContext<T, B>

Source§

fn from(context: &'a Context<T, B>) -> Self

Converts to this type from the input type.
Source§

impl<T: Clone, B: Clone> IntoSyntax<T, B> for Context<T, B>

Source§

fn into_syntax( self, vocabulary: &impl Vocabulary<Iri = T, BlankId = B>, ) -> Result<Context, InvalidContextError>

Consumes this value, returning the equivalent syntactic context. The given vocabulary must be the one the context was built with, so its IRI handles can be resolved back to actual IRIs. Read more
Source§

impl<T: PartialEq, B: PartialEq> PartialEq for Context<T, B>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more

Auto Trait Implementations§

§

impl<T = Iri<String>, B = BlankIdBuf> !RefUnwindSafe for Context<T, B>

§

impl<T = Iri<String>, B = BlankIdBuf> !UnwindSafe for Context<T, B>

§

impl<T, B> Freeze for Context<T, B>

§

impl<T, B> Send for Context<T, B>

§

impl<T, B> Sync for Context<T, B>

§

impl<T, B> Unpin for Context<T, B>

§

impl<T, B> UnsafeUnpin for Context<T, B>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
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<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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