Skip to main content

SpecBuilder

Struct SpecBuilder 

Source
pub struct SpecBuilder { /* private fields */ }
Expand description

Fluent builder for Spec.

Implementations§

Source§

impl SpecBuilder

Source

pub fn title(self, t: impl Into<String>) -> Self

Set the document title (literal string).

Source

pub fn title_binding(self, path: impl Into<String>) -> Self

Set the document title to a {"$data": "/path"} binding.

Source

pub fn layout(self, l: impl Into<String>) -> Self

Set the layout name.

Source

pub fn data(self, d: Value) -> Self

Attach the data payload.

Source

pub fn root(self, id: impl Into<String>) -> Self

Explicitly set the root element ID.

If omitted, the root defaults to the ID of the first element added.

Source

pub fn element(self, id: impl Into<String>, el: ElementBuilder) -> Self

Add an element to the spec. The first call (absent an explicit SpecBuilder::root) establishes the root.

Source

pub fn element_nested(self, id: impl Into<String>, el: NestedElement) -> Self

Add an element AND its nested children in a single call.

Children are flattened to the canonical flat Spec.elements map with IDs auto-generated by structural position: {parent_id}-0, {parent_id}-1, …, and so on recursively ({parent_id}-0-0, {parent_id}-0-1, …).

The first .element_nested call (absent an explicit SpecBuilder::root) establishes the root, just like SpecBuilder::element.

§D-07 contract

The runtime Spec shape is unchanged. After this method returns, the nested form is gone — the spec is the canonical flat element map.

Source

pub fn build(self) -> Result<Spec, SpecError>

Finalize the spec. Runs the same structural validation as Spec::from_json.

Trait Implementations§

Source§

impl Debug for SpecBuilder

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for SpecBuilder

Source§

fn default() -> SpecBuilder

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

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more