diff --git a/README.md b/README.md index 85482f0..f4cb25f 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,19 @@ extern crate strum; extern crate strum_macros; ``` +# Contributing + +Thanks for your interest in contributing. The project is divided into 3 parts, the traits are in the +`/strum` folder. The procedural macros are in the `/strum_macros` folder, and the integration tests are +in `/strum_tests`. Tests are still a work in progress, but they should be added in the test project to +verify that the macros are working correctly with the trait definitions. + +# Debugging + +To see the generated code, set the STRUM_DEBUG environment variable before compiling your code. +`STRUM_DEBUG=1` will dump all of the generated code for every type. `STRUM_DEBUG=YourType` will +only dump the code generated on a type named `YourType`. + # Strum Macros Strum has implemented the following macros: @@ -269,20 +282,7 @@ fn main() { Tokens::OpenParen, Tokens::CloseParen]); } -``` - -# Contributing - -Thanks for your interest in contributing. The project is divided into 3 parts, the traits are in the -`/strum` folder. The procedural macros are in the `/strum_macros` folder, and the integration tests are -in `/strum_tests`. Tests are still a work in progress, but they should be added in the test project to -verify that the macros are working correctly with the trait definitions. - -# Debugging - -To see the generated code, set the DEBUG_STRUM environment variable before compiling your code. -`DEBUG_STRUM=1` will dump all of the generated code for every type. `DEBUG_STRUM=YourType` will -only dump the code generated on a type named `YourType`. +`` # Name diff --git a/strum/Cargo.toml b/strum/Cargo.toml index ae6c993..729820f 100644 --- a/strum/Cargo.toml +++ b/strum/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "strum" -version = "0.2.1" +version = "0.2.2" authors = ["Peter Glotfelty "] license = "MIT" @@ -13,7 +13,7 @@ homepage = "https://github.com/Peternator7/strum" readme = "../README.md" [dev-dependencies] -strum_macros = "0.2.1" +strum_macros = "0.2.2" [badges] travis-ci = { repository = "Peternator7/strum" } \ No newline at end of file diff --git a/strum/src/lib.rs b/strum/src/lib.rs index aaa70b4..9e07bb3 100644 --- a/strum/src/lib.rs +++ b/strum/src/lib.rs @@ -64,9 +64,9 @@ //! /* //! //The generated code will look like: //! impl ::std::str::FromStr for Color { -//! type Err = strum::ParseError; +//! type Err = ::strum::ParseError; //! -//! fn from_str(s: &str) -> Result { +//! fn from_str(s: &str) -> ::std::result::Result { //! match s { //! "Red" => ::std::result::Result::Ok(Color::Red), //! "Green" => ::std::result::Result::Ok(Color::Green { range:Default::default() }), @@ -282,16 +282,10 @@ //! //! # Debugging //! -//! To see the generated code, set the DEBUG_STRUM environment variable before compiling your code. -//! `DEBUG_STRUM=1` will dump all of the generated code for every type. `DEBUG_STRUM=YourType` will +//! To see the generated code, set the STRUM_DEBUG environment variable before compiling your code. +//! `STRUM_DEBUG=1` will dump all of the generated code for every type. `STRUM_DEBUG=YourType` will //! only dump the code generated on a type named YourType. //! -//! # Name -//! -//! Strum is short for STRing enUM because it's a library for augmenting enums with additional -//! information through strings. -//! -//! Strumming is also a very whimsical motion, much like writing Rust code. /// The ParseError enum is a collection of all the possible reasons /// an enum can fail to parse from a string. @@ -302,6 +296,8 @@ pub enum ParseError { impl std::fmt::Display for ParseError { fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> { + // We could use our macro here, but this way we don't take a dependency on the + // macros crate. match self { &ParseError::VariantNotFound => write!(f, "Matching variant not found"), } diff --git a/strum_macros/Cargo.toml b/strum_macros/Cargo.toml index 9d1e895..9bc84d5 100644 --- a/strum_macros/Cargo.toml +++ b/strum_macros/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "strum_macros" -version = "0.2.1" +version = "0.2.2" authors = ["Peter Glotfelty "] license = "MIT" diff --git a/strum_tests/tests/from_str.rs b/strum_tests/tests/from_str.rs index 3499aeb..9969f22 100644 --- a/strum_tests/tests/from_str.rs +++ b/strum_tests/tests/from_str.rs @@ -74,3 +74,14 @@ enum Lifetime<'a> { fn lifetime_test() { assert_eq!(Lifetime::Life(""), Lifetime::from_str("Life").unwrap()); } + +#[derive(Debug,Eq,PartialEq,EnumString)] +enum Generic { + Gen(T), + None, +} + +#[test] +fn generic_test() { + assert_eq!(Generic::Gen(""), Generic::from_str("Gen").unwrap()); +}