#enums #str #convert #derive #ref #static

macro str_to_enum_derive

provide a simple way to convert static str ref to enum

2 unstable releases

Uses old Rust 2015

0.2.0 Jan 21, 2018
0.1.0 Sep 16, 2017

#40 in #ref

BSD-3-Clause

4KB

Rust compiler level Latest Version License

example

cargo.toml

[dependencies]
str_to_enum_derive = "0.2.0"

main.rs

#[macro_use]
extern crate str_to_enum_derive;

#[derive(StrToEnum, Debug, PartialEq, Eq)]
enum HTTPMethod {
    GET,
    HEAD,
    POST,
    PUT,
    DELETE,
    CONNECT,
    OPTIONS,
    TRACE
}

fn main() {
    assert_eq!(HTTPMethod::GET, "GET".parse::<HTTPMethod>().unwrap());
    assert_eq!(HTTPMethod::HEAD, "HEAD".parse::<HTTPMethod>().unwrap());
}

Dependencies

~2MB
~48K SLoC