Skip to main content

NumericCoercionConfig

Struct NumericCoercionConfig 

Source
#[non_exhaustive]
pub struct NumericCoercionConfig { pub empty_string_to_zero: bool, pub null_to_zero: bool, pub bool_to_number: bool, pub reject_non_numeric: bool, }
Expand description

Knobs for the implicit value→number coercions arithmetic and comparison perform on non-numeric arguments.

See EvaluationConfig::numeric_coercion for how these flags interact when more than one would fire on the same value (short answer: reject_non_numeric overrides everything else; the rest are type-disjoint so they don’t conflict in practice).

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§empty_string_to_zero: bool

""0 in numeric context. Default: true. Disable to make {"+": ["", 1]} fail with a NaN error instead of returning 1.

§null_to_zero: bool

null0 in numeric context. Default: true.

§bool_to_number: bool

true1, false0 in numeric context. Default: true.

§reject_non_numeric: bool

Reject non-numeric values: a non-numeric value is a type error. Default: false. When true, this flag overrides every other flag in this struct — empty strings, nulls, and booleans all raise rather than coerce. Acts as a kill switch for the rest of the coercion knobs in this struct.

Note: earlier versions also declared a reserved undefined_to_zero flag here. It never had an effect (JSONLogic does not distinguish a missing key from an explicit null — the reference missing operator treats {"a": null} exactly like {}) and it has been removed. A missing var already coerces to 0 under the default Self::null_to_zero = true.

Implementations§

Source§

impl NumericCoercionConfig

Source

pub fn with_empty_string_to_zero(self, value: bool) -> Self

Source

pub fn with_null_to_zero(self, value: bool) -> Self

Source

pub fn with_bool_to_number(self, value: bool) -> Self

Source

pub fn with_reject_non_numeric(self, value: bool) -> Self

Set Self::reject_non_numeric. When true, this flag overrides every other flag — empty strings, nulls, and booleans all raise rather than coerce.

Trait Implementations§

Source§

impl Clone for NumericCoercionConfig

Source§

fn clone(&self) -> NumericCoercionConfig

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 NumericCoercionConfig

Source§

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

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

impl Default for NumericCoercionConfig

Source§

fn default() -> Self

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.