A simple Rust macro to convert enums to
Options
| src | Prioritize pattern matching over path matching | |
| .gitignore | Initial commit | |
| .rustfmt.toml | Add support for expression-less syntax | |
| Cargo.toml | Update repository URL | |
| LICENSE | Initial commit | |
| README.md | Add README.md | |
as_variant
A simple Rust macro to convert enums with newtype variants to Options.
Basic example:
usestd::ops::Deref;useas_variant::as_variant;enum Value{Integer(i64),String(String),Array(Vec<Value>),}implValue{pubfn as_integer(&self)-> Option<i64>{as_variant!(self,Self::Integer).copied()}pubfn as_str(&self)-> Option<&str>{as_variant!(self,Self::String).map(Deref::deref)}pubfn as_array(&self)-> Option<&[Value]>{as_variant!(self,Self::Array).map(Deref::deref)}pubfn into_string(self)-> Option<String>{as_variant!(self,Self::String)}pubfn into_array(self)-> Option<Vec<Value>>{as_variant!(self,Self::Array)}}