Skip to main content

Module algorithm

Module algorithm 

Source
Expand description

The context processing algorithm itself, and the pieces it is built from.

§Two implementations, one algorithm: keep sync.rs in step

This module, together with define.rs and iri.rs, holds the async implementation of the context processing algorithm — the one that can call the Loader to fetch remote contexts and @imported documents. sync.rs, in this same directory, holds a second, hand-maintained implementation of the same algorithm with async, .await and the boxed [Recursion] stripped out and recursion made direct. It is used as a fast path whenever requires_loader proves the input contains no remote @context IRI and no @import, which is the common case in real payloads.

Which of the two runs is invisible to callers: for any input both must produce the same active context and the same error. A change to the algorithm here therefore has to be mirrored in sync.rs, and a change there mirrored back here. Nothing enforces this — the two are separate function bodies with no shared code, so a fix applied to only one silently makes the result depend on whether the input happened to reference a remote context. The mirrored pairs are:

this modulesync.rs
process_context (mod.rs)process_context_sync
define (define.rs)define_sync
expand_iri_with (iri.rs)expand_iri_with_sync

sync.rs does guard the one class of divergence it can detect — reaching a code path that would need the loader — by returning Error::LoadingDocumentFailed. That protects against requires_loader drifting out of step with the algorithm body; it says nothing about the two implementations otherwise agreeing.

Structs§

DefinedTerm
A term’s state within a DefinedTerms tracker: either fully defined, or still being defined further up the recursion.
DefinedTerms
Tracks which terms of one context definition are already defined and which are still being defined, so that cyclic definitions can be detected.
MalformedIri
Warning reporting that a value expanded to something that is not a valid IRI.
Merged
A context definition viewed together with the definition it pulls in through @import.
MergedBindings
Iterator over the term definitions of a Merged context definition.
RejectVocab
A term could only be expanded through the vocabulary mapping, while Options::vocab was set to Action::Reject.

Enums§

Action
How strictly to treat a term whose expansion is questionable.

Functions§

define
Runs the create term definition algorithm for term, adding the resulting definition to active_context.
expand_iri_simple
Expands value into an IRI using only the term definitions active_context already has.
expand_iri_with
Runs the IRI expansion algorithm on value, defining terms of local_context on demand.

Type Aliases§

ExpandIriResult
Result of expand_iri_with.
IriExpansionResult
Result of expanding a term into an IRI without a loader.