1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
//! Rust macro crate to automatically generate conversions from variant types into the target enum. //! //! This crate requires Rust 1.15 or above to compile on stable. //! //! # Examples //! //! ```rust //! #[macro_use] //! extern crate from_variants; //! //! #[derive(Debug, Clone, PartialEq, Eq, FromVariants)] //! pub enum Lorem { //! Str(String), //! Num(u16), //! } //! //! fn main() { //! assert_eq!(Lorem::Num(10), Lorem::from(10)); //! } //! ``` //! //! You can skip variants to avoid type collisions: //! //! ```rust //! #[macro_use] //! extern crate from_variants; //! //! #[derive(Debug, Clone, PartialEq, Eq, FromVariants)] //! pub enum Ipsum { //! Hello(String), //! //! #[from_variants(skip)] //! Goodbye(String), //! } //! //! fn main() { //! assert_eq!(Ipsum::Hello("John".to_string()), Ipsum::from("John".to_string())); //! } //! ``` //! //! # Features //! * **Variant opt-out**: To skip a variant, add `#[from_variants(skip)]` to that variant. //! * **no_std support**: To generate conversions using `core::convert::From`, add `#[from_variants(no_std)]` at the struct level. extern crate core; #[allow(unused_imports)] #[macro_use] extern crate from_variants_impl; pub use from_variants_impl::*; #[doc(hidden)] pub mod export { pub use ::core::convert::From; pub use ::core::convert::Into; }