[][src]Enum arithmetic_eval::fns::Compare

#[non_exhaustive]pub enum Compare {
    Raw,
    Min,
    Max,
}

Comparator functions on two number arguments. All functions use Arithmetic to determine ordering between the args.

Type

fn(Num, Num) -> Ordering // for `Compare::Raw`
fn(Num, Num) -> Num // for `Compare::Min` and `Compare::Max`

Examples

Using min function:

let program = r#"
    // Finds a minimum number in an array.
    extended_min = |...xs| xs.fold(INFINITY, min);
    extended_min(2, -3, 7, 1, 3) == -3
"#;
let program = Untyped::<F32Grammar>::parse_statements(program)?;

let module = Environment::new()
    .insert("INFINITY", Value::Number(f32::INFINITY))
    .insert_native_fn("fold", fns::Fold)
    .insert_native_fn("min", fns::Compare::Min)
    .compile_module("test_min", &program)?;
assert_eq!(module.run()?, Value::Bool(true));

Using cmp function with Comparisons.

let program = r#"
    (1, -7, 0, 2).map(|x| cmp(x, 0)) == (GREATER, LESS, EQUAL, GREATER)
"#;
let program = Untyped::<F32Grammar>::parse_statements(program)?;

let module = Environment::from_iter(Comparisons.iter())
    .insert_native_fn("map", fns::Map)
    .compile_module("test_cmp", &program)?;
assert_eq!(module.run()?, Value::Bool(true));

Variants (Non-exhaustive)

Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
Raw

Returns an Ordering wrapped into an OpaqueRef, or Value::void() if the provided values are not comparable.

Min

Returns the minimum of the two numbers. If the numbers are equal, returns the first one.

Max

Returns the maximum of the two numbers. If the numbers are equal, returns the first one.

Trait Implementations

impl Clone for Compare[src]

impl Copy for Compare[src]

impl Debug for Compare[src]

impl<T> NativeFn<T> for Compare[src]

Auto Trait Implementations

impl RefUnwindSafe for Compare

impl Send for Compare

impl Sync for Compare

impl Unpin for Compare

impl UnwindSafe for Compare

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Conv for T

impl<T> Conv for T

impl<T> FmtForward for T

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Pipe for T where
    T: ?Sized

impl<T> Pipe for T

impl<T> PipeAsRef for T

impl<T> PipeBorrow for T

impl<T> PipeDeref for T

impl<T> PipeRef for T

impl<T> Tap for T

impl<T> Tap for T

impl<T, U> TapAsRef<U> for T where
    U: ?Sized

impl<T, U> TapBorrow<U> for T where
    U: ?Sized

impl<T> TapDeref for T

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> TryConv for T

impl<T> TryConv for T

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,