one-of

version license ci

Macro to represent a type that can be converted either From or Into the given types

This crate only works on the nightly version of Rust

Documentation

Usage

```rust use oneof::{case, oneof};

// either u32 or char let x: oneof!(u32, char) = 42.into(); asserteq!(Some(42u32), x.into()); assert_eq!(Option::::None, x.into());

// some type of integer let x: oneof!(i8, i16, i32, i64, u8, u16, u32, u64) = 42.into(); asserteq!(Option::::None, x.into()); asserteq!(Option::::None, x.into()); asserteq!(Some(42i32), x.into()); asserteq!(Option::::None, x.into()); asserteq!(Option::::None, x.into()); asserteq!(Option::::None, x.into()); asserteq!(Option::::None, x.into()); assert_eq!(Option::::None, x.into());

// case macro is the match keyword for one_of types case!(

// &str
s if s.starts_with("Hello, ") => {
    assert_eq!(&s[7 ..], "world!");
}
_ => {
    panic!("not other strings");
};

// i64
_ => {
    panic!("not i64");
};

); ```

Changelog

See CHANGELOG.md