pub enum Case {
Lower,
Upper,
Pascal,
Camel,
Snake,
ScreamingSnake,
Kebab,
ScreamingKebab,
}Expand description
Case convention for case-renaming actions.
During serialization, if you use serde’s #[derive(Serialize)] and #[serde(rename=...)] or
#[serde(rename_all=...)], those will be applied at compile time. This means any case
conversions you perform at runtime will need to operate on the results of serde’s renames.
This can lead to unsolvable corner cases. For example, imagine you’ve got an enum renamed like this:
#[derive(Serialize)]
#[serde(rename_all = "UPPERCASE")]
enum Reason {
JustInCase,
}At runtime, the JustInCase variant will be serialized as "JUSTINCASE". Trying to change
its case convention to snake case will yield "justincase" instead of maybe expected
"just_in_case". This happens because at runtime there is no way to figure out word
boundaries after serde has transformed everything to uppercase.
Variants§
Lower
lowercase
Upper
UPPERCASE
Pascal
PascalCase
Camel
camelCase
Snake
snake_case
ScreamingSnake
SCREAMING_SNAKE_CASE
Kebab
kebab-case
ScreamingKebab
SCREAMING-KEBAB-CASE
Trait Implementations§
Source§impl From<&str> for Case
impl From<&str> for Case
Source§fn from(value: &str) -> Self
fn from(value: &str) -> Self
Convert from a string literal to Case.
This function accepts the same case convention identifiers, as #[serde rename_all=...]:
"lowercase",
"UPPERCASE",
"PascalCase",
"camelCase",
"snake_case",
"SCREAMING_SNAKE_CASE",
"kebab-case",
"SCREAMING-KEBAB-CASE".
Panics on unknown identifiers.