pub struct PioModule<T> { /* private fields */ }Expand description
One typed PowerIO compiler unit.
T has no PowerIO marker bound. Dynamic parsing and stored JSON register a
finite set elsewhere, while Rust applications can use any value here.
Implementations§
Source§impl<T> PioModule<T>
impl<T> PioModule<T>
pub fn new(value: T) -> Self
pub const fn value(&self) -> &T
pub fn into_value(self) -> T
pub const fn producer(&self) -> &Producer
pub fn sources(&self) -> &[SourceDescriptor]
pub fn source_map(&self) -> &[SourceMapEntry]
pub fn diagnostics(&self) -> &[Diagnostic]
pub fn history(&self) -> &[HistoryEntry]
pub const fn extensions(&self) -> &BTreeMap<String, Value>
pub const fn source(&self) -> Option<&Source>
pub fn with_producer(self, producer: Producer) -> Self
pub fn with_source(self, source: Source) -> Self
Sourcepub fn sever_source(self) -> Self
pub fn sever_source(self) -> Self
Drop the retained source owner: the operation that calls this changed the value, so a same format write must serialize the value rather than echo bytes the value no longer matches. Descriptors, diagnostics, and history stay.
Sourcepub fn with_diagnostic(self, diagnostic: Diagnostic) -> Result<Self, Error>
pub fn with_diagnostic(self, diagnostic: Diagnostic) -> Result<Self, Error>
Append a finding, applying the same duplicate identity and span
reference checks as PioModule::add_diagnostic. There is no unchecked
path onto a module’s records.
pub fn add_source_descriptor( &mut self, source: SourceDescriptor, ) -> Result<(), Error>
pub fn add_source_map_entry( &mut self, entry: SourceMapEntry, ) -> Result<(), Error>
pub fn add_diagnostic(&mut self, diagnostic: Diagnostic) -> Result<(), Error>
pub fn add_history_entry(&mut self, entry: HistoryEntry) -> Result<(), Error>
pub fn insert_extension( &mut self, namespace: impl Into<String>, value: Value, ) -> Result<Option<Value>, Error>
Sourcepub fn verify_records(&self) -> Result<(), Error>
pub fn verify_records(&self) -> Result<(), Error>
Verify cross-record references that cannot be checked by constructors.
Sourcepub fn sever_value_targets(&mut self)
pub fn sever_value_targets(&mut self)
Drop records that address the old value: the operation that calls this
replaced the value with one of a different kind, so RFC 6901 targets
into the old value no longer identify anything. Every diagnostic
keeps its code, message, severity, and spans but loses its target,
and the source map (whose entries are keyed by such targets) is
cleared. Pair this with PioModule::map_value in a kind changing
transform so the module still serializes.
Sourcepub fn map_value<U>(self, convert: impl FnOnce(T) -> U) -> PioModule<U>
pub fn map_value<U>(self, convert: impl FnOnce(T) -> U) -> PioModule<U>
Move the value and every module record into another typed module.
Sourcepub fn try_map_value<U, E>(
self,
convert: impl FnOnce(T) -> Result<U, E>,
) -> Result<PioModule<U>, E>
pub fn try_map_value<U, E>( self, convert: impl FnOnce(T) -> Result<U, E>, ) -> Result<PioModule<U>, E>
Move the value through a fallible conversion, keeping every module
record on success. On failure the conversion’s error is returned and
the records are dropped with the consumed value; a caller that must
keep the source or findings on the failure route takes them off the
module first (PioModule::take_source, PioModule::diagnostics).
Sourcepub fn take_source(&mut self) -> Option<Source>
pub fn take_source(&mut self) -> Option<Source>
Take the retained source owner off the module, leaving descriptors, diagnostics, and history in place. The module then reads as constructed in memory until a source is reattached.
Sourcepub fn parsed(
value: T,
source: Source,
diagnostics: Vec<Diagnostic>,
) -> Result<Self, Error>
pub fn parsed( value: T, source: Source, diagnostics: Vec<Diagnostic>, ) -> Result<Self, Error>
Assemble the module a parser returns: the typed value, one descriptor per acquired buffer of the retained source, and the reader’s findings.
§Errors
A duplicate acquired buffer identity, an invalid buffer name, or a
finding that fails the record checks of PioModule::add_diagnostic.