mirror of
https://github.com/danog/strum.git
synced 2024-11-26 20:14:40 +01:00
Update documentation to include listing all the supported case styles.
This commit is contained in:
parent
6119f107e2
commit
201d794fd6
@ -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::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()
|
||||
//! );
|
||||
//! ```
|
||||
//!
|
||||
//! 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.
|
||||
//!
|
||||
|
Loading…
Reference in New Issue
Block a user