pub struct Context<T = Iri<String>, 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>
impl<T, B> Context<T, B>
Sourcepub fn new(base_iri: Option<T>) -> Context<T, B>where
T: Clone,
pub fn new(base_iri: Option<T>) -> Context<T, B>where
T: Clone,
Create a new context with the given base IRI.
Sourcepub fn with_private_caches(&self) -> Context<T, B>
pub fn with_private_caches(&self) -> Context<T, B>
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.
Sourcepub fn processing_mode(&self) -> ProcessingMode
pub fn processing_mode(&self) -> ProcessingMode
Returns the processing mode this context was processed under.
Sourcepub fn set_processing_mode(&mut self, mode: ProcessingMode)
pub fn set_processing_mode(&mut self, mode: ProcessingMode)
Sets the processing mode of this context.
Sourcepub fn get<Q>(&self, term: &Q) -> Option<TermDefinitionRef<'_, T, B>>
pub fn get<Q>(&self, term: &Q) -> Option<TermDefinitionRef<'_, T, B>>
Returns a reference to the given term definition, if any.
Sourcepub fn get_normal<Q>(&self, term: &Q) -> Option<&NormalTermDefinition<T, B>>
pub fn get_normal<Q>(&self, term: &Q) -> Option<&NormalTermDefinition<T, B>>
Returns a reference to the given term normal definition, if any.
Sourcepub fn get_type(&self) -> Option<&TypeTermDefinition>
pub fn get_type(&self) -> Option<&TypeTermDefinition>
Returns a reference to the @type definition, if any.
Sourcepub fn contains_term<Q>(&self, term: &Q) -> bool
pub fn contains_term<Q>(&self, term: &Q) -> bool
Checks if the given term is defined.
Sourcepub fn original_base_url(&self) -> Option<&T>
pub fn original_base_url(&self) -> Option<&T>
Returns the original base URL of the context.
Sourcepub fn vocabulary(&self) -> Option<&Term<T, B>>
pub fn vocabulary(&self) -> Option<&Term<T, B>>
Returns the @vocab value, if any.
Sourcepub fn default_language(&self) -> Option<&LenientLangTag>
pub fn default_language(&self) -> Option<&LenientLangTag>
Returns the default @language value.
Sourcepub fn default_base_direction(&self) -> Option<Direction>
pub fn default_base_direction(&self) -> Option<Direction>
Returns the default @direction value.
Sourcepub fn previous_context(&self) -> Option<&Context<T, B>>
pub fn previous_context(&self) -> Option<&Context<T, B>>
Returns a reference to the previous context.
Sourcepub fn definitions_arc_ptr(&self) -> *const Definitions<T, B>
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.
Sourcepub fn previous_context_arc_ptr(&self) -> *const Context<T, B>
pub fn previous_context_arc_ptr(&self) -> *const Context<T, B>
Returns the address of the Arc backing the previous context, or null
when there is none. See Self::definitions_arc_ptr.
Sourcepub fn definitions(&self) -> &Definitions<T, B>
pub fn definitions(&self) -> &Definitions<T, B>
Returns a handle to the term definitions.
Sourcepub fn has_protected_items(&self) -> bool
pub fn has_protected_items(&self) -> bool
Checks if the context has a protected definition.
Sourcepub fn inverse(&self) -> &InverseContext<T, B>
pub fn inverse(&self) -> &InverseContext<T, B>
Returns the inverse context, computing and caching it on first access.
Sourcepub fn prefix_terms(&self) -> &[(Key, Arc<Term<T, B>>)]
pub fn prefix_terms(&self) -> &[(Key, Arc<Term<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.
Sourcepub fn compact_iri_cache(
&self,
) -> &ShardedMemo<(Term<T, B>, bool, bool, ProcessingMode), Option<Arc<str>>>
pub fn compact_iri_cache( &self, ) -> &ShardedMemo<(Term<T, B>, bool, bool, ProcessingMode), 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.
Sourcepub fn term_resolution_cache(&self) -> &ShardedMemo<Box<str>, Arc<Term<T, B>>>
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.
Sourcepub fn keyword_aliases_or_init<F>(
&self,
mode: ProcessingMode,
init: F,
) -> &KeywordAliaseswhere
F: FnOnce() -> KeywordAliases,
pub fn keyword_aliases_or_init<F>(
&self,
mode: ProcessingMode,
init: F,
) -> &KeywordAliaseswhere
F: FnOnce() -> 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.
Sourcepub fn set_normal(
&mut self,
key: Key,
definition: Option<NormalTermDefinition<T, B>>,
) -> Option<NormalTermDefinition<T, B>>
pub fn set_normal( &mut self, key: Key, definition: Option<NormalTermDefinition<T, B>>, ) -> Option<NormalTermDefinition<T, B>>
Sets the normal definition for the given term key.
Sourcepub fn set_type(
&mut self,
type_: Option<TypeTermDefinition>,
) -> Option<TypeTermDefinition>
pub fn set_type( &mut self, type_: Option<TypeTermDefinition>, ) -> Option<TypeTermDefinition>
Sets the @type definition.
Sourcepub fn set_base_iri(&mut self, iri: Option<T>)
pub fn set_base_iri(&mut self, iri: Option<T>)
Sets the base IRI.
Sourcepub fn set_vocabulary(&mut self, vocab: Option<Term<T, B>>)
pub fn set_vocabulary(&mut self, vocab: Option<Term<T, B>>)
Sets the @vocab value.
Sourcepub fn set_default_language(&mut self, lang: Option<LenientLangTagBuf>)
pub fn set_default_language(&mut self, lang: Option<LenientLangTagBuf>)
Sets the default @language value.
Sourcepub fn set_default_base_direction(&mut self, dir: Option<Direction>)
pub fn set_default_base_direction(&mut self, dir: Option<Direction>)
Sets the default @direction value.
Sourcepub fn set_previous_context(&mut self, previous: Context<T, B>)
pub fn set_previous_context(&mut self, previous: Context<T, B>)
Sets the previous context.
Sourcepub fn into_syntax_definition(
self,
vocabulary: &impl Vocabulary<Iri = T, BlankId = B>,
) -> Result<Definition, InvalidContextError>
pub fn into_syntax_definition( self, vocabulary: &impl Vocabulary<Iri = T, BlankId = B>, ) -> Result<Definition, InvalidContextError>
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.
Trait Implementations§
Source§impl<T, B> IntoSyntax<T, B> for Context<T, B>
impl<T, B> IntoSyntax<T, B> for Context<T, B>
Source§fn into_syntax(
self,
vocabulary: &impl Vocabulary<Iri = T, BlankId = B>,
) -> Result<Context, InvalidContextError>
fn into_syntax( self, vocabulary: &impl Vocabulary<Iri = T, BlankId = B>, ) -> Result<Context, InvalidContextError>
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>where
Option<T>: Freeze,
Option<Term<T, B>>: Freeze,
Option<Arc<Context<T, B>>>: Freeze,
Arc<Definitions<T, B>>: Freeze,
Arc<OnceCell<InverseContext<T, B>>>: Freeze,
Arc<OnceCell<Vec<(Key, Arc<Term<T, B>>)>>>: Freeze,
Arc<OnceCell<ShardedMemo<(Term<T, B>, bool, bool, ProcessingMode), Option<Arc<str>>>>>: Freeze,
Arc<OnceCell<ShardedMemo<Box<str>, Arc<Term<T, B>>>>>: Freeze,
impl<T, B> Send for Context<T, B>where
Option<T>: Send,
Option<Term<T, B>>: Send,
Option<Arc<Context<T, B>>>: Send,
Arc<Definitions<T, B>>: Send,
Arc<OnceCell<InverseContext<T, B>>>: Send,
Arc<OnceCell<Vec<(Key, Arc<Term<T, B>>)>>>: Send,
Arc<OnceCell<ShardedMemo<(Term<T, B>, bool, bool, ProcessingMode), Option<Arc<str>>>>>: Send,
Arc<OnceCell<ShardedMemo<Box<str>, Arc<Term<T, B>>>>>: Send,
impl<T, B> Sync for Context<T, B>where
Option<T>: Sync,
Option<Term<T, B>>: Sync,
Option<Arc<Context<T, B>>>: Sync,
Arc<Definitions<T, B>>: Sync,
Arc<OnceCell<InverseContext<T, B>>>: Sync,
Arc<OnceCell<Vec<(Key, Arc<Term<T, B>>)>>>: Sync,
Arc<OnceCell<ShardedMemo<(Term<T, B>, bool, bool, ProcessingMode), Option<Arc<str>>>>>: Sync,
Arc<OnceCell<ShardedMemo<Box<str>, Arc<Term<T, B>>>>>: Sync,
impl<T, B> Unpin for Context<T, B>where
Option<T>: Unpin,
Option<Term<T, B>>: Unpin,
Option<Arc<Context<T, B>>>: Unpin,
Arc<Definitions<T, B>>: Unpin,
Arc<OnceCell<InverseContext<T, B>>>: Unpin,
Arc<OnceCell<Vec<(Key, Arc<Term<T, B>>)>>>: Unpin,
Arc<OnceCell<ShardedMemo<(Term<T, B>, bool, bool, ProcessingMode), Option<Arc<str>>>>>: Unpin,
Arc<OnceCell<ShardedMemo<Box<str>, Arc<Term<T, B>>>>>: Unpin,
impl<T, B> UnsafeUnpin for Context<T, B>where
Option<T>: UnsafeUnpin,
Option<Term<T, B>>: UnsafeUnpin,
Option<Arc<Context<T, B>>>: UnsafeUnpin,
Arc<Definitions<T, B>>: UnsafeUnpin,
Arc<OnceCell<InverseContext<T, B>>>: UnsafeUnpin,
Arc<OnceCell<Vec<(Key, Arc<Term<T, B>>)>>>: UnsafeUnpin,
Arc<OnceCell<ShardedMemo<(Term<T, B>, bool, bool, ProcessingMode), Option<Arc<str>>>>>: UnsafeUnpin,
Arc<OnceCell<ShardedMemo<Box<str>, Arc<Term<T, B>>>>>: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> BorrowUnordered for T
impl<T> BorrowUnordered for T
Source§fn as_unordered(&self) -> &Unordered<T>
fn as_unordered(&self) -> &Unordered<T>
Unordered reference.