Skip to content

Commit

Permalink
Updated documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
azriel91 committed Sep 18, 2018
1 parent efb27cc commit 20996e7
Showing 1 changed file with 43 additions and 8 deletions.
51 changes: 43 additions & 8 deletions strum/src/lib.rs
Expand Up @@ -14,8 +14,8 @@
//!
//! ```toml
//! [dependencies]
//! strum = "0.9.0"
//! strum_macros = "0.9.0"
//! strum = "0.11.0"
//! strum_macros = "0.11.0"
//! ```
//!
//! And add these lines to the root of your project, either lib.rs or main.rs.
Expand Down Expand Up @@ -79,10 +79,10 @@
//! # fn main() {}
//! ```
//!
//! Note that the implementation of `FromStr` only matches on the name of the variant.
//! Strum, where possible, avoids operations that have an unknown runtime cost, and parsing strings
//! is potentially an expensive operation. If you do need that behavior, consider the more powerful
//! Serde library for your serialization.
//! Note that the implementation of `FromStr` by default only matches on the name of the
//! variant. There is an option to match on different case conversions through the
//! `#[strum(serialize_all = "snake_case")]` type attribute. See the **Additional Attributes**
//! Section for more information on using this feature.
//!
//! 2. `Display`, `ToString`: both derives print out the given enum variant. This enables you to perform round trip
//! style conversions from enum into string and back again for unit style variants. `ToString` and `Display`
Expand Down Expand Up @@ -293,8 +293,43 @@
//!
//! # Additional Attributes
//!
//! Strum supports several custom attributes to modify the generated code. Custom attributes are
//! applied to a variant by adding #[strum(parameter="value")] to the variant.
//! Strum supports several custom attributes to modify the generated code. At the enum level, the
//! `#[strum(serialize_all = "snake_case")]` attribute can be used to change the case used when
//! serializing to and deserializing from strings:
//!
//! ```rust
//! extern crate strum;
//! #[macro_use]
//! extern crate strum_macros;
//!
//! #[derive(Debug, Eq, PartialEq, ToString)]
//! #[strum(serialize_all = "snake_case")]
//! enum Brightness {
//! DarkBlack,
//! Dim {
//! glow: usize,
//! },
//! #[strum(serialize = "bright")]
//! BrightWhite,
//! }
//!
//! fn main() {
//! assert_eq!(
//! String::from("dark_black"),
//! Brightness::DarkBlack.to_string().as_ref()
//! );
//! assert_eq!(
//! String::from("dim"),
//! Brightness::Dim { glow: 0 }.to_string().as_ref()
//! );
//! assert_eq!(
//! String::from("bright"),
//! Brightness::BrightWhite.to_string().as_ref()
//! );
//! }
//! ```
//!
//! Custom attributes are applied to a variant by adding #[strum(parameter="value")] to the variant.
//!
//! - `serialize="..."`: Changes the text that `FromStr()` looks for when parsing a string. This attribute can
//! be applied multiple times to an element and the enum variant will be parsed if any of them match.
Expand Down

0 comments on commit 20996e7

Please sign in to comment.