Skip to main content

ZonOptions

Struct ZonOptions 

Source
pub struct ZonOptions {
    pub char_as_number: bool,
    pub enum_tag: Option<String>,
}
Expand description

Plugin options. Default is the canonical Zon.defaults: character literals as one-character strings, enum literals as bare strings.

Fields§

§char_as_number: bool

Parse Zig character literals ('x') as numeric code points rather than as one-character strings.

§enum_tag: Option<String>

When set, wrap an enum literal used as a value (.foo) in { "<enumTag>": "foo" } instead of producing the bare string "foo". An empty string means unset, as in the Go port.

Implementations§

Source§

impl ZonOptions

Source

pub fn to_value(&self) -> Value

The options as the engine’s plugin option bag.

Source

pub fn from_value(value: &Value) -> Self

The options read from a plugin option bag. A missing field is its default and an unknown field is ignored, as the canonical plugin reads options.charAsNumber and options.enumTag and nothing else.

Each field is read ON ITS OWN, and by JavaScript truthiness, which is what !!options.charAsNumber and options.enumTag || null mean in ts/src/zon.ts. Deserializing the bag as a whole instead let one ill-typed field discard a well-typed one: the bag {"charAsNumber": true, "enumTag": false} failed to deserialize at enumTag and fell back to the DEFAULTS, so 'A' parsed as "A" where both other runtimes give 65.

The bag is read as the ENGINE value it is, never through Value::to_json. That projection turns a non-finite number into null, and null is falsy where Infinity is not: a charAsNumber of Infinity is true in the canonical runtime and would have read as false here, and an enumTag of Infinity names the key Infinity there and would have read as unset here.

The conversion is LOSSLESS for a string, the empty one included, so that from_value(&options.to_value()) returns the options it was given. tag applies the canonical || null filter at the point of use instead.

Trait Implementations§

Source§

impl Clone for ZonOptions

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 ZonOptions

Source§

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

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

impl Default for ZonOptions

Source§

fn default() -> Self

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

impl<'de> Deserialize<'de> for ZonOptions

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for ZonOptions

Source§

impl PartialEq for ZonOptions

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 Serialize for ZonOptions

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for ZonOptions

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> 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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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.