Skip to main content

Options

Struct Options 

Source
pub struct Options {
Show 22 fields pub name: Option<String>, pub indent: Option<String>, pub compact: bool, pub sparse: bool, pub fatal: bool, pub maxnum: Option<usize>, pub maxlevel: Option<usize>, pub maxlength: Option<i64>, pub nocode: bool, pub nohuge: bool, pub comment: Option<usize>, pub sortkeys: bool, pub sortfn: Option<SortFn>, pub fixradix: bool, pub metatostring: Option<bool>, pub numformat: Option<String>, pub valignore: Option<HashSet<Ident>>, pub valignore_scalar: Option<Vec<Value>>, pub keyallow: Option<Vec<Key>>, pub keyignore: Option<Vec<Key>>, pub valtypeignore: Option<HashSet<String>>, pub custom: Option<CustomFn>,
}
Expand description

Options controlling serialization.

Field names and defaults follow serpent. Booleans use Lua truthiness unless a field notes an exact comparison. Set fields directly, or start from Options::dump, Options::line, or Options::block.

Fields§

§name: Option<String>

Variable name. When set, output is wrapped in a do ... return name end block with a self-reference section. dump sets _.

§indent: Option<String>

Indentation unit. When set, output is multi-line. block sets two spaces.

§compact: bool

Remove spaces around separators. dump sets true.

§sparse: bool

Force sparse array encoding, skipping nil holes. dump sets true.

§fatal: bool

Raise an error on non-serializable values instead of emitting a fallback.

§maxnum: Option<usize>

Maximum number of array-part elements to emit.

§maxlevel: Option<usize>

Maximum table nesting depth to expand. Deeper tables emit {}.

§maxlength: Option<i64>

Maximum cumulative length of emitted element strings.

§nocode: bool

Replace functions with an empty-body stub instead of bytecode.

§nohuge: bool

Disable the special 1/0, -1/0, 0/0 forms for inf and nan.

§comment: Option<usize>

Append --[[...]] comments up to this depth. The gate is level < n, so a table at level l gets a comment when l < n. Some(0) disables comments, matching serpent’s numeric depth 0. Some(usize::MAX) comments every level, standing in for serpent’s math.huge. line and block set Some(usize::MAX).

§sortkeys: bool

Sort non-array keys. line and block set the default sort on.

§sortfn: Option<SortFn>

Custom key sort. Overrides the default alphanumsort when set.

§fixradix: bool

Force a . decimal separator. A no-op in this implementation because Rust float formatting is locale-independent.

§metatostring: Option<bool>

Use __tostring on tables. Only an explicit Some(false) disables it; None and Some(true) enable it, matching serpent’s ~= false gate.

§numformat: Option<String>

printf-style number format. Defaults to %.17g.

§valignore: Option<HashSet<Ident>>

Values to skip, matched by identity or scalar value.

§valignore_scalar: Option<Vec<Value>>

Scalar values to skip.

§keyallow: Option<Vec<Key>>

Allowlist of keys to serialize. Keys not in the list are dropped. Keyed by Key, so numeric and boolean keys work, not only strings.

§keyignore: Option<Vec<Key>>

Denylist of keys to skip. Keyed by Key, so numeric and boolean keys work, not only strings.

§valtypeignore: Option<HashSet<String>>

Value type names to skip, such as function or table.

§custom: Option<CustomFn>

Custom table formatter.

Implementations§

Source§

impl Options

Source

pub fn dump() -> Self

Options for full serialization: name = "_", compact, sparse.

Source

pub fn line() -> Self

Options for single-line pretty printing: sortkeys and comment on.

Source

pub fn block() -> Self

Options for multi-line pretty printing: two-space indent, sortkeys, and comment on.

Source

pub fn serialize() -> Self

Options for the raw serialize entry point: all defaults, nothing preset.

Trait Implementations§

Source§

impl Default for Options

Source§

fn default() -> Options

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