Skip to main content

SerializerBuilder

Struct SerializerBuilder 

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

Builder for configuring serialization options

The SerializerBuilder provides a fluent API for customizing serialization behavior. It combines configuration from multiple internal types into a single, easy-to-use interface.

Implementations§

Source§

impl SerializerBuilder

Source

pub fn new() -> Self

Create a new SerializerBuilder with default settings

Source

pub fn indent_size(self, size: usize) -> Self

Set the indentation size for formatted output

Controls the minimum padding for keys in human format. Set to 0 for no padding (default).

§Example
use serializer::SerializerBuilder;

let serializer = SerializerBuilder::new()
    .indent_size(4)
    .build();
Source

pub fn expand_keys(self, expand: bool) -> Self

Set whether to expand abbreviated keys to full names

When true (default), keys like “nm” become “name” in human format. When false, abbreviated keys are preserved.

§Example
use serializer::SerializerBuilder;

let serializer = SerializerBuilder::new()
    .expand_keys(false)  // Keep "nm" instead of expanding to "name"
    .build();
Source

pub fn use_list_format(self, use_list: bool) -> Self

Set whether to use list format for arrays

When true (default), arrays are formatted as:

items:
- first
- second

When false, arrays are formatted inline:

items = first | second
Source

pub fn space_around_equals(self, space: bool) -> Self

Set whether to add spaces around equals signs

When true (default): key = value When false: key=value

Source

pub fn validate_output(self, validate: bool) -> Self

Set whether to validate output by parsing it back

When enabled, the serializer will parse the formatted output to ensure it’s valid. This catches formatting bugs but is slower.

Note: Currently disabled by default since V3 format round-trip is not fully implemented.

Source

pub fn check_round_trip(self, check: bool) -> Self

Set whether to check round-trip consistency

When enabled (requires validate_output), the serializer will verify that parsing the formatted output produces an equivalent document to the original.

Source

pub fn output_dir<P: Into<PathBuf>>(self, dir: P) -> Self

Set the output directory for generated files

When set, the serializer can generate .human and .machine files in the specified directory. Default is “.dx/serializer”.

§Example
use serializer::SerializerBuilder;

let serializer = SerializerBuilder::new()
    .output_dir("build/serializer")
    .build();
Source

pub fn generate_llm(self, generate: bool) -> Self

Set whether to generate LLM format files

When true (default), .llm files are generated in .dx/serializer.

Source

pub fn generate_machine(self, generate: bool) -> Self

Set whether to generate machine format files

When true (default), .machine files are generated for runtime use.

Source

pub fn preserve_comments(self, preserve: bool) -> Self

Set whether to preserve comments in output

Note: Comment preservation is not yet fully implemented. This option is reserved for future use.

Source

pub fn compact_arrays(self, compact: bool) -> Self

Set whether to use compact array formatting

When true, arrays are formatted more compactly. This is equivalent to setting use_list_format(false).

Source

pub fn for_tables(self) -> Self

Create a configuration optimized for tables and rules

This preset is useful for multi-row sections like lint rules. It sets appropriate padding and formatting for tabular data.

§Example
use serializer::SerializerBuilder;

let serializer = SerializerBuilder::new()
    .for_tables()
    .build();
Source

pub fn for_compact(self) -> Self

Create a configuration optimized for compact output

This preset minimizes whitespace and uses abbreviated keys. Useful for token-efficient LLM format.

Source

pub fn for_humans(self) -> Self

Create a configuration optimized for human readability

This preset maximizes readability with expanded keys, proper spacing, and list formatting for arrays.

Source

pub fn build(self) -> Serializer

Build the configured Serializer

Creates a Serializer instance with all the specified options.

Trait Implementations§

Source§

impl Clone for SerializerBuilder

Source§

fn clone(&self) -> SerializerBuilder

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 Debug for SerializerBuilder

Source§

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

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

impl Default for SerializerBuilder

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

Source§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
Source§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
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> 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> LayoutRaw for T

Source§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Returns the layout of the type.
Source§

impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
where T: SharedNiching<N1, N2>, N1: Niching<T>, N2: Niching<T>,

Source§

unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool

Returns whether the given value has been niched. Read more
Source§

fn resolve_niched(out: Place<NichedOption<T, N1>>)

Writes data to out indicating that a T is niched.
Source§

impl<T> Pointee for T

Source§

type Metadata = ()

The metadata type for pointers and references to this type.
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.