[][src]Struct arithmetic_eval::fns::Assert

pub struct Assert;

Assertion function.

Type

fn(bool)

Examples

let program = r#"
    assert(1 + 2 == 3); # this assertion is fine
    assert(3^2 == 10); # this one will fail
"#;
let block = F32Grammar::parse_statements(Span::new(program)).unwrap();

let mut interpreter = Interpreter::new();
interpreter.insert_native_fn("assert", fns::Assert);
let err = interpreter.evaluate(&block).unwrap_err();
assert_eq!(err.main_span().fragment, "assert(3^2 == 10)");
assert_matches!(
    err.source(),
    EvalError::NativeCall(ref msg) if msg == "Assertion failed"
);

Trait Implementations

impl Clone for Assert[src]

impl Copy for Assert[src]

impl Debug for Assert[src]

impl<T: Grammar> NativeFn<T> for Assert[src]

Auto Trait Implementations

impl RefUnwindSafe for Assert

impl Send for Assert

impl Sync for Assert

impl Unpin for Assert

impl UnwindSafe for Assert

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> From<T> for T[src]

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

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

type Owned = T

The resulting type after obtaining ownership.

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.