Crates.io | enum_str |
lib.rs | enum_str |
version | 0.1.2 |
source | src |
created_at | 2018-04-11 05:28:23.517108 |
updated_at | 2018-04-12 03:08:21.536954 |
description | Creates a unitary enum and conversions from enum variants to string and vice versa |
homepage | |
repository | https://github.com/lambdasqd/enum_str-rs |
max_upload_size | |
id | 60052 |
size | 17,216 |
This crate provides a macro to create a unitary enum and conversions from enum variants to a string representation and vice versa.
The string representation does not need to be the same as the enum variant's identifier. See the example below for clarification.
#[macro_use] extern crate enum_str;
use std::str::FromStr;
use enum_str::{Error, AsStr};
fn main() {
enum_str! {
Fruit,
(Apple, "🍎"),
(Pineapple, "🍍"),
(Strawberry, "🍓"),
}
assert_eq!("🍎", Fruit::Apple.as_str());
assert_eq!(Fruit::Apple, Fruit::from_str("🍎").unwrap());
}