Skip to main content

DocumentConstructor

Struct DocumentConstructor 

Source
pub struct DocumentConstructor { /* private fields */ }

Implementations§

Source§

impl DocumentConstructor

Source

pub fn new() -> Self

Source

pub fn current_node_id(&self) -> NodeId

Source

pub fn current_node(&self) -> &Node

Source

pub fn current_node_mut(&mut self) -> &mut Node

Source

pub fn current_path(&self) -> &[PathSegment]

Source

pub fn document(&self) -> &EureDocument

Source

pub fn document_mut(&mut self) -> &mut EureDocument

Source

pub fn finish(self) -> EureDocument

Source§

impl DocumentConstructor

Source

pub fn begin_scope(&mut self) -> Scope

Begin a new scope. Returns a scope handle that must be passed to end_scope. Scopes must be ended in LIFO order (most recent first).

Source

pub fn end_scope(&mut self, scope: Scope) -> Result<(), ScopeError>

End a scope, restoring the constructor to the state when the scope was created. Returns an error if the scope is not the most recent outstanding scope.

Source

pub fn navigate(&mut self, segment: PathSegment) -> Result<NodeId, InsertError>

Navigate to a child node by path segment. Creates the node if it doesn’t exist.

Source

pub fn require_hole(&self) -> Result<(), InsertError>

Validate that the current node is a Hole (unbound). Use this before binding a value to ensure the node hasn’t already been assigned.

Source

pub fn bind_hole( &mut self, label: Option<Identifier>, ) -> Result<(), InsertError>

Bind a hole (optionally labeled) to the current node.

Source

pub fn bind_primitive( &mut self, value: PrimitiveValue, ) -> Result<(), InsertError>

Bind a primitive value to the current node. Error if already bound.

Source

pub fn bind_from( &mut self, value: impl Into<PrimitiveValue>, ) -> Result<(), InsertError>

Bind a value to the current node using Into<PrimitiveValue>.

This is a convenience method for use with the eure! macro. It accepts any type that implements Into<PrimitiveValue>.

Source

pub fn bind_empty_map(&mut self) -> Result<(), InsertError>

Bind an empty map to the current node. Error if already bound.

Source

pub fn bind_empty_array(&mut self) -> Result<(), InsertError>

Bind an empty array to the current node. Error if already bound.

Source

pub fn bind_empty_tuple(&mut self) -> Result<(), InsertError>

Bind an empty tuple to the current node. Error if already bound.

Source

pub fn begin_eure_block(&mut self)

Enter a new EureSource block. No-op for DocumentConstructor.

Source

pub fn set_block_value(&mut self) -> Result<(), InsertError>

Set the value binding for current block. No-op for DocumentConstructor.

Source

pub fn end_eure_block(&mut self) -> Result<(), InsertError>

End current EureSource block. No-op for DocumentConstructor.

Source

pub fn begin_binding(&mut self)

Mark the start of a binding statement. No-op for DocumentConstructor.

Source

pub fn end_binding_value(&mut self) -> Result<(), InsertError>

End binding #1: path = value. No-op for DocumentConstructor.

Source

pub fn end_binding_block(&mut self) -> Result<(), InsertError>

End binding #2/#3: path { eure }. No-op for DocumentConstructor.

Source

pub fn begin_section(&mut self)

Start a section header. No-op for DocumentConstructor.

Source

pub fn begin_section_items(&mut self)

Begin section #4: items follow. No-op for DocumentConstructor.

Source

pub fn end_section_items(&mut self) -> Result<(), InsertError>

End section #4: finalize section with items. No-op for DocumentConstructor.

Source

pub fn end_section_block(&mut self) -> Result<(), InsertError>

End section #5/#6: block. No-op for DocumentConstructor.

Source§

impl DocumentConstructor

Source

pub fn record<F, T>(&mut self, f: F) -> Result<T, WriteError>
where F: FnOnce(&mut RecordWriter<'_>) -> Result<T, WriteError>,

Write a record (map with string keys) using a closure.

§Example
c.record(|rec| {
    rec.field("name", "Alice")?;
    rec.field("age", 30)?;
    Ok(())
})?;
Source

pub fn tuple<F, T>(&mut self, f: F) -> Result<T, WriteError>
where F: FnOnce(&mut TupleWriter<'_>) -> Result<T, WriteError>,

Write a tuple using a closure.

§Example
c.tuple(|t| {
    t.next("first")?;
    t.next(42)?;
    t.next(true)?;
    Ok(())
})?;
Source

pub fn set_extension<T: IntoEure>( &mut self, name: &str, value: T, ) -> Result<(), WriteError>

Set an extension value on the current node.

§Example
c.set_extension("optional", true)?;
Source

pub fn set_extension_optional<T: IntoEure>( &mut self, name: &str, value: Option<T>, ) -> Result<(), WriteError>

Set an optional extension value on the current node. Does nothing if the value is None.

§Example
c.set_extension_optional("default", self.default)?;
Source

pub fn set_variant(&mut self, variant: &str) -> Result<(), WriteError>

Set the $variant extension for union types.

§Example
match self {
    MyEnum::Foo(inner) => {
        c.set_variant("foo")?;
        inner.write_to(c)?;
    }
}
Source

pub fn write<T: IntoEure>(&mut self, value: T) -> Result<(), WriteError>

Write a value implementing IntoEure to the current node.

§Example
c.write(my_value)?;

Trait Implementations§

Source§

impl Default for DocumentConstructor

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl InterpreterSink for DocumentConstructor

Source§

type Error = InsertError

The error type for operations.
Source§

type Scope = Scope

The scope handle type returned by begin_scope.
Source§

fn begin_scope(&mut self) -> Self::Scope

Begin a new scope. Returns a handle that must be passed to end_scope. Scopes must be ended in LIFO order (most recent first).
Source§

fn end_scope(&mut self, scope: Self::Scope) -> Result<(), Self::Error>

End a scope, restoring the sink to the state when begin_scope was called.
Source§

fn navigate(&mut self, segment: PathSegment) -> Result<NodeId, Self::Error>

Navigate to a child node by path segment. Creates the node if it doesn’t exist.
Source§

fn require_hole(&self) -> Result<(), Self::Error>

Assert that the current node is unbound (a hole). Use this before binding a value to ensure the node hasn’t already been assigned.
Source§

fn bind_primitive(&mut self, value: PrimitiveValue) -> Result<(), Self::Error>

Bind a primitive value to the current node.
Source§

fn bind_hole(&mut self, label: Option<Identifier>) -> Result<(), Self::Error>

Bind a hole (with optional label) to the current node.
Source§

fn bind_empty_map(&mut self) -> Result<(), Self::Error>

Bind an empty map to the current node.
Source§

fn bind_empty_array(&mut self) -> Result<(), Self::Error>

Bind an empty array to the current node.
Source§

fn bind_empty_tuple(&mut self) -> Result<(), Self::Error>

Bind an empty tuple to the current node.
Source§

fn current_node_id(&self) -> NodeId

Get the current node ID.
Source§

fn current_path(&self) -> &[PathSegment]

Get the current path from root.
Source§

fn document(&self) -> &EureDocument

Get a reference to the document being built.
Source§

fn document_mut(&mut self) -> &mut EureDocument

Get a mutable reference to the document being built.
Source§

fn bind_from( &mut self, value: impl Into<PrimitiveValue>, ) -> Result<(), Self::Error>

Bind a value using Into<PrimitiveValue>. Convenience method for use with the eure! macro.
Source§

fn begin_eure_block(&mut self)

Enter a new EureSource block (for { eure } patterns). Pushes a new EureSource onto the builder stack. Default: no-op.
Source§

fn set_block_value(&mut self) -> Result<(), Self::Error>

Set the value binding for current EureSource (for { = value ... } patterns). Called after bind_* to record the value node. Returns error if called without a preceding bind operation. Default: no-op (returns Ok).
Source§

fn end_eure_block(&mut self) -> Result<(), Self::Error>

End current EureSource block. Pops from the builder stack. Returns error if the builder stack is in an invalid state. Default: no-op (returns Ok).
Source§

fn begin_binding(&mut self)

Start a binding statement (path ...). Default: no-op.
Source§

fn end_binding_value(&mut self) -> Result<(), Self::Error>

End binding #1: path = value. Adds BindingSource with BindSource::Value to current EureSource. Returns error if called without a preceding bind operation. Default: no-op (returns Ok).
Source§

fn end_binding_block(&mut self) -> Result<(), Self::Error>

End binding #2/#3: path { eure }. Adds BindingSource with BindSource::Block to current EureSource. The block’s EureSource was built between begin_eure_block/end_eure_block. Returns error if called without a preceding end_eure_block. Default: no-op (returns Ok).
Source§

fn begin_section(&mut self)

Start a section header (@ path ...). Default: no-op.
Source§

fn begin_section_items(&mut self)

Begin section #4: @ section (items follow). Begins collecting items into SectionBody::Items. Default: no-op.
Source§

fn end_section_items(&mut self) -> Result<(), Self::Error>

End section #4: finalize section with items body. Adds SectionSource with SectionBody::Items to current EureSource. Returns error if the builder stack is in an invalid state. Default: no-op (returns Ok).
Source§

fn end_section_block(&mut self) -> Result<(), Self::Error>

End section #5/#6: @ section { eure }. Adds SectionSource with SectionBody::Block to current EureSource. The block’s EureSource was built between begin_eure_block/end_eure_block. Returns error if called without a preceding end_eure_block. Default: no-op (returns Ok).
Source§

fn comment(&mut self, _comment: Comment)

Add a comment to the layout. Default: no-op.
Source§

fn blank_line(&mut self)

Add a blank line to the layout. Default: no-op.

Auto Trait Implementations§

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