pub struct Serializer { /* private fields */ }Expand description
Configured Serializer instance
A Serializer provides methods for converting documents to various formats using the configuration specified by the SerializerBuilder.
Implementations§
Source§impl Serializer
impl Serializer
Sourcepub fn serialize(&self, doc: &DxDocument) -> String
pub fn serialize(&self, doc: &DxDocument) -> String
Serialize a DxDocument to LLM format string
This is the primary serialization method that produces the token-efficient LLM format.
§Example
use serializer::{SerializerBuilder, DxDocument, DxLlmValue};
let mut doc = DxDocument::new();
doc.context.insert("name".to_string(), DxLlmValue::Str("MyApp".to_string()));
let serializer = SerializerBuilder::new().build();
let text = serializer.serialize(&doc);Sourcepub fn deserialize(&self, input: &str) -> Result<DxDocument, ConvertError>
pub fn deserialize(&self, input: &str) -> Result<DxDocument, ConvertError>
Deserialize LLM format string to DxDocument
Parses the token-efficient LLM format back into a structured document.
§Errors
Returns a ConvertError if the input is not valid LLM format.
Sourcepub fn format_human(&self, doc: &DxDocument) -> Result<String, PrettyPrintError>
pub fn format_human(&self, doc: &DxDocument) -> Result<String, PrettyPrintError>
Format a DxDocument to human-readable format
Produces clean, hand-editable format using the configured options. The output is validated if validation is enabled in the builder.
§Example
use serializer::{SerializerBuilder, DxDocument, DxLlmValue};
let mut doc = DxDocument::new();
doc.context.insert("name".to_string(), DxLlmValue::Str("MyApp".to_string()));
let serializer = SerializerBuilder::new()
.for_humans()
.build();
let human_text = serializer.format_human(&doc).unwrap();Sourcepub fn format_human_unchecked(&self, doc: &DxDocument) -> String
pub fn format_human_unchecked(&self, doc: &DxDocument) -> String
Format a DxDocument to human format without validation
Faster than format_human() but provides no guarantees about the output being parseable.
Sourcepub fn generate_files(
&self,
doc: &DxDocument,
source_path: &Path,
) -> Result<SerializerResult, SerializerOutputError>
pub fn generate_files( &self, doc: &DxDocument, source_path: &Path, ) -> Result<SerializerResult, SerializerOutputError>
Generate output files for a DxDocument
Creates .human and .machine files in the configured output directory.
§Example
use serializer::{SerializerBuilder, DxDocument};
use std::path::Path;
let doc = DxDocument::new();
let serializer = SerializerBuilder::new()
.output_dir("build/serializer")
.build();
let result = serializer.generate_files(&doc, Path::new("config.sr")).unwrap();
println!("Generated {} bytes LLM, {} bytes machine",
result.llm_size, result.machine_size);Sourcepub fn pretty_printer(&self) -> &PrettyPrinter
pub fn pretty_printer(&self) -> &PrettyPrinter
Get the pretty printer instance
Provides access to the underlying PrettyPrinter for advanced use cases.
Sourcepub fn output_generator(&self) -> &SerializerOutput
pub fn output_generator(&self) -> &SerializerOutput
Get the output generator instance
Provides access to the underlying SerializerOutput for advanced use cases.
Auto Trait Implementations§
impl Freeze for Serializer
impl RefUnwindSafe for Serializer
impl Send for Serializer
impl Sync for Serializer
impl Unpin for Serializer
impl UnsafeUnpin for Serializer
impl UnwindSafe for Serializer
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.