Macro konst::const_eq[][src]

macro_rules! const_eq {
    ($left:expr, $right:expr) => { ... };
}
This is supported on crate feature cmp only.

Compares two values for equality.

The arguments must implement the ConstCmpMarker trait. Non-standard library types must define a const_eq method taking a reference.

Limitations

The arguments must be concrete types, and have a fully inferred type. eg: if you pass an integer literal it must have a suffix to indicate its type.

Example

use konst::{const_eq, impl_cmp};

use std::ops::Range;

struct Fields<'a> {
    foo: u32,
    bar: Option<bool>,
    baz: Range<usize>,
    qux: &'a str,
}

impl_cmp!{
    impl['a] Fields<'a>;
    pub const fn const_eq(&self, other: &Self) -> bool {
        self.foo == other.foo &&
        const_eq!(self.bar, other.bar) &&
        const_eq!(self.baz, other.baz) &&
        const_eq!(self.qux, other.qux)
    }
}

const CMPS: [bool; 4] = {
    let foo = Fields {
        foo: 10,
        bar: None,
        baz: 10..20,
        qux: "hello",
    };
     
    let bar = Fields {
        foo: 99,
        bar: Some(true),
        baz: 0..5,
        qux: "world",
    };
     
    [const_eq!(foo, foo), const_eq!(foo, bar), const_eq!(bar, foo), const_eq!(bar, bar)]
};

assert_eq!(CMPS, [true, false, false, true]);