#[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
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: boolnull → 0 in numeric context. Default: true.
bool_to_number: booltrue → 1, false → 0 in numeric context. Default: true.
reject_non_numeric: boolReject 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
impl NumericCoercionConfig
Sourcepub fn with_empty_string_to_zero(self, value: bool) -> Self
pub fn with_empty_string_to_zero(self, value: bool) -> Self
Sourcepub fn with_null_to_zero(self, value: bool) -> Self
pub fn with_null_to_zero(self, value: bool) -> Self
Set Self::null_to_zero.
Sourcepub fn with_bool_to_number(self, value: bool) -> Self
pub fn with_bool_to_number(self, value: bool) -> Self
Set Self::bool_to_number.
Sourcepub fn with_reject_non_numeric(self, value: bool) -> Self
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
impl Clone for NumericCoercionConfig
Source§fn clone(&self) -> NumericCoercionConfig
fn clone(&self) -> NumericCoercionConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more