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 fn into_value(self) -> T

Source

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

The typed value carried by this module.

Source

pub fn value_mut(&mut self) -> &mut T

The typed value, for an edit in place.

Taking the reference drops the retained source owner and the source map: bytes and RFC 6901 targets that describe the pre-edit value no longer describe what the module carries, so a same format write serializes the value instead of emitting them. Descriptors, diagnostics, and history stay. PioModule::stage_edit is the atomic form, which leaves the module untouched when an edit does not complete.

Source

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

Diagnostics produced while acquiring, validating, or deriving the value, in the order they were recorded.

Source

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

Source

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

Source

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

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 derive_value<U>( self, producer: Producer, history: HistoryEntry, derive: impl FnOnce(T) -> U, ) -> Result<PioModule<U>, Error>

Derive a semantically new value and record the operation that produced it. Source descriptors, diagnostics, prior history, and extensions stay with the module. Locators into the replaced value and retained bytes that no longer encode the result are invalidated.

Source

pub fn try_derive_value<U>( self, producer: Producer, history: HistoryEntry, derive: impl FnOnce(T) -> Result<U, Error>, ) -> Result<PioModule<U>, Error>

Fallible form of PioModule::derive_value.

Source

pub fn try_derive_from_source<U>( self, input_target: &str, source: Source, producer: Producer, history: HistoryEntry, derive: impl FnOnce(T, &Source) -> Result<(U, Vec<Diagnostic>), Error>, ) -> Result<PioModule<U>, Error>

Parse a value that depends on this module and one additional source.

Records that describe the input value are retargeted below input_target. The additional source receives distinct source IDs, becomes the retained source, and is mapped to the new value’s root. This is the shared module operation for readers whose document is not self contained, such as a solution file that must be interpreted against its calculation instance.

§Errors

The derived value cannot be built, a target is not an RFC 6901 pointer, or the combined records exceed a module bound.

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 with PioModule::take_source and the public diagnostics field.

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, a coarse root source map, and the reader’s findings.

§Errors

A duplicate acquired buffer identity, an invalid buffer name or span, or a finding that fails the record checks of PioModule::add_diagnostic.

Source§

impl<T: Clone> PioModule<T>

Source

pub fn stage_edit(&mut self) -> StagedEdit<'_, T>

Begin an atomic edit of this module’s value and findings.

The candidate uses T::clone; values backed by shared tables retain those tables until StagedEdit::value_mut performs their own copy on write detachment. Dropping the staged edit, or any failed operation on it, leaves this module untouched.

Trait Implementations§

Source§

impl<T: Clone> Clone for PioModule<T>

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

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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> 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 = Infallible

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.