0.2.4 |
|
---|---|
0.2.3 |
|
0.2.1 |
|
0.1.5 |
|
0.1.4 |
|
#21 in #eq
15KB
303 lines
This project is no longer maintained.
lib.rs
:
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 { fn eq(&self, _: &T) -> bool; }
impl CustomPartialEq 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, }) }
</details>
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
);