From 1ec35285a075f294da1446e0526a7ab997966ff8 Mon Sep 17 00:00:00 2001 From: Peter Glotfelty Date: Sun, 10 Oct 2021 12:45:19 -0700 Subject: [PATCH] Update documentation to include listing all the supported case styles. (#182) Co-authored-by: Peter Glotfelty --- strum/src/additional_attributes.rs | 86 ++++++++++++++++++------------ 1 file changed, 51 insertions(+), 35 deletions(-) diff --git a/strum/src/additional_attributes.rs b/strum/src/additional_attributes.rs index 8172a90f..a93f827e 100644 --- a/strum/src/additional_attributes.rs +++ b/strum/src/additional_attributes.rs @@ -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. //!