Crate match_eq[][src]

Expand description

A match-like macro that uses PartialEq to “match” each “patten”.

Crate feature

  • no-core: Make this crate #![no_core].

    #![no_core] example
    #![feature(no_core, lang_items, start)]
    #![no_core]
    
    #[cfg_attr(not(windows), link(name = "c"))]
    #[cfg_attr(windows, link(name = "msvcrt"))]
    extern "C" {}
    
    use match_eq::prelude::*;
    
    #[lang = "sized"]
    trait Sized {}
    
    #[lang = "copy"]
    trait Copy {}
    
    impl Copy for i32 {}
    
    #[lang = "receiver"]
    trait Receiver {}
    
    impl<T: ?Sized> Receiver for &T {}
    
    #[lang = "eh_personality"]
    fn eh_personality() -> ! {
        loop {}
    }
    
    #[lang = "eq"]
    trait CustomPartialEq<T> {
        fn eq(&self, _: &T) -> bool;
    }
    
    impl CustomPartialEq<i32> for i32 {
        fn eq(&self, _: &i32) -> bool {
            loop {}
        }
    }
    
    #[start]
    fn main(_: isize, _: *const *const u8) -> isize {
        match_eq!(1 => {
            1, 2 => if matches_eq!(3, 3, 4) {
                if matches_eq!(5, 6, 7) { 1 } else { 0 }
            } else {
                1
            },
            _ => 1,
        })
    }

Example

use std::ffi::{OsStr, OsString};

assert_eq!(
    match_eq!(OsString::from("🎉") => {
        "🎃" => 0,
        "🚀", "🎉" => -1,
        s = OsStr::new("🎉") => {
            drop::<OsString>(s);
            -2
        }
        ref s = "🎉", OsStr::new("🚀") => {
            let _: &OsString = s;
            -3
        }
        _ = "🎉" => unreachable!(),
        _ => -5,
    }),
    -1
);

Modules

prelude

The prelude.

Macros

match_eq

The main macro of this crate.

matches_eq

match_eq version of matches.