#[StringEnum]
Expand description
This procedural macro generates JS ‘string-like’ enums, which support from and to string conversions on all members.
use map_enum::*;
use std::str::FromStr;
#[derive(Debug)]
#[StringEnum]
pub enum Method {
Get = "Hi",
Post,
}
assert_eq!(Method::Get.to_string(), "Hi".to_string());
assert_eq!(Method::Post.to_string(), "Post".to_string());
assert_eq!(Method::from_str("Hi").unwrap(), Method::Get);
assert_eq!(Method::from_str("Post").unwrap(), Method::Post);
assert!(Method::from_str("other").is_err());