A simple Rust macro to convert enums with newtype variants to Option
s.
Basic example:
```rust use std::ops::Deref;
use asvariant::asvariant;
enum Value {
Integer(i64),
String(String),
Array(Vec
impl Value {
pub fn asinteger(&self) -> Option
pub fn as_str(&self) -> Option<&str> {
as_variant!(self, Self::String).map(Deref::deref)
}
pub fn as_array(&self) -> Option<&[Value]> {
as_variant!(self, Self::Array).map(Deref::deref)
}
pub fn into_string(self) -> Option<String> {
as_variant!(self, Self::String)
}
pub fn into_array(self) -> Option<Vec<Value>> {
as_variant!(self, Self::Array)
}
} ```