Skip to content

Commit

Permalink
Update documentation to include listing all the supported case styles. (
Browse files Browse the repository at this point in the history
#182)

Co-authored-by: Peter Glotfelty <[email protected]>
  • Loading branch information
Peternator7 and Peter Glotfelty authored Oct 10, 2021
1 parent 07f9fe3 commit 1ec3528
Showing 1 changed file with 51 additions and 35 deletions.
86 changes: 51 additions & 35 deletions strum/src/additional_attributes.rs
Original file line number Diff line number Diff line change
@@ -1,41 +1,57 @@
//! # Documentation for Additional Attributes
//!
//! ## Attributes on Enums
//!
//! 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:
//! Strum supports several custom attributes to modify the generated code. At the enum level, the following attributes are supported:
//!
//! - `#[strum(serialize_all = "case_style")]` attribute can be used to change the case used when serializing to and deserializing
//! from strings. This feature is enabled by [withoutboats/heck](https://github.com/withoutboats/heck) and supported case styles are:
//!
//! - `camelCase`
//! - `PascalCase`
//! - `kebab-case`
//! - `snake_case`
//! - `SCREAMING_SNAKE_CASE`
//! - `SCREAMING-KEBAB-CASE`
//! - `lowercase`
//! - `UPPERCASE`
//! - `title_case`
//! - `mixed_case`
//!
//! ```rust
//! use std::string::ToString;
//! use strum;
//! use strum_macros;
//!
//! #[derive(Debug, Eq, PartialEq, strum_macros::ToString)]
//! #[strum(serialize_all = "snake_case")]
//! enum Brightness {
//! DarkBlack,
//! Dim {
//! glow: usize,
//! },
//! #[strum(serialize = "bright")]
//! BrightWhite,
//! }
//!
//! 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()
//! );
//! ```
//!
//! ```rust
//! use std::string::ToString;
//! use strum;
//! use strum_macros;
//!
//! #[derive(Debug, Eq, PartialEq, strum_macros::Display)]
//! #[strum(serialize_all = "snake_case")]
//! enum Brightness {
//! DarkBlack,
//! Dim {
//! glow: usize,
//! },
//! #[strum(serialize = "bright")]
//! BrightWhite,
//! }
//!
//! 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()
//! );
//! ```
//!
//! You can also apply the `#[strum(ascii_case_insensitive)]` attribute to the enum,
//! and this has the same effect of applying it to every variant.
//! - You can also apply the `#[strum(ascii_case_insensitive)]` attribute to the enum,
//! and this has the same effect of applying it to every variant.
//!
//! ## Attributes on Variants
//!
//! Custom attributes are applied to a variant by adding `#[strum(parameter="value")]` to the variant.
//!
Expand Down

0 comments on commit 1ec3528

Please sign in to comment.