pub struct Emit { /* private fields */ }Expand description
Output settings for the emitter and serializer.
Consumed by the serializer (to_string_with, to_writer_with, and
Serializer::with_settings in oneyaml). For an edited Document
they apply only to new nodes where style inference has no context.
Any indent value is accepted here; the serializer refuses
indent(0) (it cannot express nesting) and anything above
Emit::MAX_INDENT with Y1012 (never a panic or an
allocation blow-up for any value).
Defaults: 2-space indent, single quotes, never wrap, sequences indented under their key, oneyaml’s own layout.
§Examples
use oneyaml_core::{Emit, Layout, QuoteStyle};
let e = Emit::new()
.indent(4)
.quote_style(QuoteStyle::Double)
.line_width(None)
.indent_sequences(false)
.layout(Layout::Default);
assert_eq!(e.get_indent(), 4);
assert_eq!(e.get_quote_style(), QuoteStyle::Double);
assert_eq!(e.get_line_width(), None); // never wrap (wrapping is not implemented: `Some` is Y1017)
assert!(!e.get_indent_sequences());
assert_eq!(e.get_layout(), Layout::Default);Implementations§
Source§impl Emit
impl Emit
Sourcepub const MAX_INDENT: usize = 64
pub const MAX_INDENT: usize = 64
The widest indentation the serializer accepts (Y1012 above it).
Block output repeats the indentation once per nesting level on every line, so the width multiplies output size; the bound keeps any setting from turning into an allocation blow-up.
Sourcepub const fn new() -> Self
pub const fn new() -> Self
The defaults. Same as Emit::default(), usable in const.
Sourcepub const fn indent(self, spaces: usize) -> Self
pub const fn indent(self, spaces: usize) -> Self
Spaces per indentation level (default 2). The serializer accepts
1..=Emit::MAX_INDENT; other values are Y1012 there.
Sourcepub const fn quote_style(self, style: QuoteStyle) -> Self
pub const fn quote_style(self, style: QuoteStyle) -> Self
Preferred quote style (default QuoteStyle::Single).
Sourcepub const fn line_width(self, width: Option<usize>) -> Self
pub const fn line_width(self, width: Option<usize>) -> Self
Wrap long plain and quoted scalars at width columns; None (the
default) never wraps.
Wrapping is not implemented yet: the serializer refuses Some(_)
with Y1017 rather than ignoring it silently.
Sourcepub const fn indent_sequences(self, on: bool) -> Self
pub const fn indent_sequences(self, on: bool) -> Self
Indent a block sequence under its mapping key (key:\n - a, the
default) or not (key:\n- a).
Sourcepub const fn layout(self, layout: Layout) -> Self
pub const fn layout(self, layout: Layout) -> Self
Output layout (default Layout::Default).
Sourcepub const fn get_indent(&self) -> usize
pub const fn get_indent(&self) -> usize
The indentation width.
Sourcepub const fn get_quote_style(&self) -> QuoteStyle
pub const fn get_quote_style(&self) -> QuoteStyle
The preferred quote style.
Sourcepub const fn get_line_width(&self) -> Option<usize>
pub const fn get_line_width(&self) -> Option<usize>
The wrap width; None never wraps.
Sourcepub const fn get_indent_sequences(&self) -> bool
pub const fn get_indent_sequences(&self) -> bool
Whether block sequences are indented under their key.
Sourcepub const fn get_layout(&self) -> Layout
pub const fn get_layout(&self) -> Layout
The output layout.