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§

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: IntoDocument>( &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: IntoDocument>( &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: IntoDocument>(&mut self, value: T) -> Result<(), WriteError>

Write a value implementing IntoDocument 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

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.