Skip to main content

Emit

Struct Emit 

Source
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

Source

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.

Source

pub const fn new() -> Self

The defaults. Same as Emit::default(), usable in const.

Source

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.

Source

pub const fn quote_style(self, style: QuoteStyle) -> Self

Preferred quote style (default QuoteStyle::Single).

Source

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.

Source

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).

Source

pub const fn layout(self, layout: Layout) -> Self

Output layout (default Layout::Default).

Source

pub const fn get_indent(&self) -> usize

The indentation width.

Source

pub const fn get_quote_style(&self) -> QuoteStyle

The preferred quote style.

Source

pub const fn get_line_width(&self) -> Option<usize>

The wrap width; None never wraps.

Source

pub const fn get_indent_sequences(&self) -> bool

Whether block sequences are indented under their key.

Source

pub const fn get_layout(&self) -> Layout

The output layout.

Trait Implementations§

Source§

impl Clone for Emit

Source§

fn clone(&self) -> Self

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 Emit

Source§

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

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

impl Default for Emit

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for Emit

Source§

impl Hash for Emit

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Emit

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Emit

Auto Trait Implementations§

§

impl Freeze for Emit

§

impl RefUnwindSafe for Emit

§

impl Send for Emit

§

impl Sync for Emit

§

impl Unpin for Emit

§

impl UnsafeUnpin for Emit

§

impl UnwindSafe for Emit

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> 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> 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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.