removed non-serious cases and added serde aliases
This commit is contained in:
parent
b41bfc7134
commit
d750d4942a
|
@ -29,22 +29,26 @@ impl ContainerAttributes {
|
||||||
let ident = meta.path.require_ident()?;
|
let ident = meta.path.require_ident()?;
|
||||||
match ident.to_string().as_str() {
|
match ident.to_string().as_str() {
|
||||||
"rename_all" => {
|
"rename_all" => {
|
||||||
|
// The matched case are all useful variants from `convert_case` with aliases
|
||||||
|
// that `serde` uses.
|
||||||
let case: LitStr = meta.value()?.parse()?;
|
let case: LitStr = meta.value()?.parse()?;
|
||||||
let case = match case.value().as_str() {
|
let case = match case.value().as_str() {
|
||||||
"UPPER CASE" => Case::Upper,
|
"UPPER CASE" | "UPPER WITH SPACES CASE" => Case::Upper,
|
||||||
"lower case" => Case::Lower,
|
"lower case" | "lower with spaces case" => Case::Lower,
|
||||||
"Title Case" => Case::Title,
|
"Title Case" => Case::Title,
|
||||||
"tOGGLE cASE" => Case::Toggle,
|
|
||||||
"camelCase" => Case::Camel,
|
"camelCase" => Case::Camel,
|
||||||
"PascalCase" | "UpperCamelCase" => Case::Pascal,
|
"PascalCase" | "UpperCamelCase" => Case::Pascal,
|
||||||
"snake_case" => Case::Snake,
|
"snake_case" => Case::Snake,
|
||||||
"UPPER_SNAKE_CASE" | "SCREAMING_SNAKE_CASE" => Case::UpperSnake,
|
"UPPER_SNAKE_CASE" | "SCREAMING_SNAKE_CASE" => Case::UpperSnake,
|
||||||
"kebab-case" => Case::Kebab,
|
"kebab-case" => Case::Kebab,
|
||||||
"COBOL-CASE" | "UPPER-KEBAB-CASE" => Case::Cobol,
|
"COBOL-CASE" | "UPPER-KEBAB-CASE" | "SCREAMING-KEBA-CASE" => {
|
||||||
|
Case::Cobol
|
||||||
|
}
|
||||||
"Train-Case" => Case::Train,
|
"Train-Case" => Case::Train,
|
||||||
"flatcase" => Case::Flat,
|
"flatcase" | "lowercase" => Case::Flat,
|
||||||
"UPPERFLATCASE" => Case::UpperFlat,
|
"UPPERFLATCASE" | "UPPERCASE" => Case::UpperFlat,
|
||||||
"aLtErNaTiNg CaSe" => Case::Alternating,
|
// Although very funny, we don't support `Case::{Toggle, Alternating}`,
|
||||||
|
// as we see no real benefit.
|
||||||
c => {
|
c => {
|
||||||
err = Err(DeriveError::InvalidAttributeValue {
|
err = Err(DeriveError::InvalidAttributeValue {
|
||||||
value_span: case.span(),
|
value_span: case.span(),
|
||||||
|
|
|
@ -27,8 +27,11 @@ use std::{
|
||||||
/// The expected value representation will be the name of the variant as a [`Value::String`].
|
/// The expected value representation will be the name of the variant as a [`Value::String`].
|
||||||
/// By default, variant names will be expected in ["snake_case"](convert_case::Case::Snake).
|
/// By default, variant names will be expected in ["snake_case"](convert_case::Case::Snake).
|
||||||
/// You can customize the case conversion using `#[nu_value(rename_all = "kebab-case")]` on the enum.
|
/// You can customize the case conversion using `#[nu_value(rename_all = "kebab-case")]` on the enum.
|
||||||
/// All deterministic case conversions provided by [`convert_case::Case`] are supported by
|
/// All deterministic and useful case conversions provided by [`convert_case::Case`] are supported
|
||||||
/// specifying the case name followed by "case".
|
/// by specifying the case name followed by "case".
|
||||||
|
/// Also all values for
|
||||||
|
/// [`#[serde(rename_all = "...")]`](https://serde.rs/container-attrs.html#rename_all) are valid
|
||||||
|
/// here.
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// # use nu_protocol::{FromValue, Value, ShellError};
|
/// # use nu_protocol::{FromValue, Value, ShellError};
|
||||||
|
|
|
@ -18,8 +18,11 @@ use crate::{Record, ShellError, Span, Value};
|
||||||
/// The resulting value representation will be the name of the variant as a [`Value::String`].
|
/// The resulting value representation will be the name of the variant as a [`Value::String`].
|
||||||
/// By default, variant names will be converted to ["snake_case"](convert_case::Case::Snake).
|
/// By default, variant names will be converted to ["snake_case"](convert_case::Case::Snake).
|
||||||
/// You can customize the case conversion using `#[nu_value(rename_all = "kebab-case")]` on the enum.
|
/// You can customize the case conversion using `#[nu_value(rename_all = "kebab-case")]` on the enum.
|
||||||
/// All deterministic case conversions provided by [`convert_case::Case`] are supported by
|
/// All deterministic and useful case conversions provided by [`convert_case::Case`] are supported
|
||||||
/// specifying the case name followed by "case".
|
/// by specifying the case name followed by "case".
|
||||||
|
/// Also all values for
|
||||||
|
/// [`#[serde(rename_all = "...")]`](https://serde.rs/container-attrs.html#rename_all) are valid
|
||||||
|
/// here.
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// # use nu_protocol::{IntoValue, Value, Span};
|
/// # use nu_protocol::{IntoValue, Value, Span};
|
||||||
|
|
|
@ -327,7 +327,7 @@ fn enum_incorrect_type() {
|
||||||
assert!(res.is_err());
|
assert!(res.is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate the `Enum` from before but with all possible `rename_all` variants
|
// Generate the `Enum` from before but with all possible `rename_all` variants.
|
||||||
macro_rules! enum_rename_all {
|
macro_rules! enum_rename_all {
|
||||||
($($ident:ident: $case:literal => [$a1:literal, $b2:literal, $c3:literal]),*) => {
|
($($ident:ident: $case:literal => [$a1:literal, $b2:literal, $c3:literal]),*) => {
|
||||||
$(
|
$(
|
||||||
|
@ -374,7 +374,6 @@ enum_rename_all! {
|
||||||
Upper: "UPPER CASE" => ["ALPHA ONE", "BETA TWO", "CHARLIE THREE"],
|
Upper: "UPPER CASE" => ["ALPHA ONE", "BETA TWO", "CHARLIE THREE"],
|
||||||
Lower: "lower case" => ["alpha one", "beta two", "charlie three"],
|
Lower: "lower case" => ["alpha one", "beta two", "charlie three"],
|
||||||
Title: "Title Case" => ["Alpha One", "Beta Two", "Charlie Three"],
|
Title: "Title Case" => ["Alpha One", "Beta Two", "Charlie Three"],
|
||||||
Toggle: "tOGGLE cASE" => ["aLPHA oNE", "bETA tWO", "cHARLIE tHREE"],
|
|
||||||
Camel: "camelCase" => ["alphaOne", "betaTwo", "charlieThree"],
|
Camel: "camelCase" => ["alphaOne", "betaTwo", "charlieThree"],
|
||||||
Pascal: "PascalCase" => ["AlphaOne", "BetaTwo", "CharlieThree"],
|
Pascal: "PascalCase" => ["AlphaOne", "BetaTwo", "CharlieThree"],
|
||||||
Snake: "snake_case" => ["alpha_one", "beta_two", "charlie_three"],
|
Snake: "snake_case" => ["alpha_one", "beta_two", "charlie_three"],
|
||||||
|
@ -383,6 +382,5 @@ enum_rename_all! {
|
||||||
Cobol: "COBOL-CASE" => ["ALPHA-ONE", "BETA-TWO", "CHARLIE-THREE"],
|
Cobol: "COBOL-CASE" => ["ALPHA-ONE", "BETA-TWO", "CHARLIE-THREE"],
|
||||||
Train: "Train-Case" => ["Alpha-One", "Beta-Two", "Charlie-Three"],
|
Train: "Train-Case" => ["Alpha-One", "Beta-Two", "Charlie-Three"],
|
||||||
Flat: "flatcase" => ["alphaone", "betatwo", "charliethree"],
|
Flat: "flatcase" => ["alphaone", "betatwo", "charliethree"],
|
||||||
UpperFlat: "UPPERFLATCASE" => ["ALPHAONE", "BETATWO", "CHARLIETHREE"],
|
UpperFlat: "UPPERFLATCASE" => ["ALPHAONE", "BETATWO", "CHARLIETHREE"]
|
||||||
Alternating: "aLtErNaTiNg CaSe" => ["aLpHa OnE", "bEtA tWo", "cHaRlIe ThReE"]
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user