Skip to main content

PioModule

Struct PioModule 

Source
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>

Source

pub fn new(value: T) -> Self

Source

pub const fn value(&self) -> &T

Source

pub fn into_value(self) -> T

Source

pub const fn producer(&self) -> &Producer

Source

pub fn sources(&self) -> &[SourceDescriptor]

Source

pub fn source_map(&self) -> &[SourceMapEntry]

Source

pub fn diagnostics(&self) -> &[Diagnostic]

Source

pub fn history(&self) -> &[HistoryEntry]

Source

pub const fn extensions(&self) -> &BTreeMap<String, Value>

Source

pub const fn source(&self) -> Option<&Source>

Source

pub fn with_producer(self, producer: Producer) -> Self

Source

pub fn with_source(self, source: Source) -> Self

Source

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.

Source

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.

Source

pub fn add_source_descriptor( &mut self, source: SourceDescriptor, ) -> Result<(), Error>

Source

pub fn add_source_map_entry( &mut self, entry: SourceMapEntry, ) -> Result<(), Error>

Source

pub fn add_diagnostic(&mut self, diagnostic: Diagnostic) -> Result<(), Error>

Source

pub fn add_history_entry(&mut self, entry: HistoryEntry) -> Result<(), Error>

Source

pub fn insert_extension( &mut self, namespace: impl Into<String>, value: Value, ) -> Result<Option<Value>, Error>

Source

pub fn verify_records(&self) -> Result<(), Error>

Verify cross-record references that cannot be checked by constructors.

Source

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.

Source

pub fn map_value<U>(self, convert: impl FnOnce(T) -> U) -> PioModule<U>

Move the value and every module record into another typed module.

Source

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).

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.

Source

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.

Trait Implementations§

Source§

impl<T: Debug> Debug for PioModule<T>

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for PioModule<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for PioModule<T>
where T: RefUnwindSafe,

§

impl<T> Send for PioModule<T>
where T: Send,

§

impl<T> Sync for PioModule<T>
where T: Sync,

§

impl<T> Unpin for PioModule<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for PioModule<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for PioModule<T>
where T: UnwindSafe,

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

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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, <T as TryFrom<U>>::Error>

Performs the conversion.
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.