mirror of
https://gitee.com/openharmony/third_party_rust_serde
synced 2024-11-23 15:01:05 +00:00
Add error type to use for RenameRule parsing
This commit is contained in:
parent
ed04824f10
commit
7db0982e58
@ -339,7 +339,7 @@ impl Container {
|
||||
rename_all_ser_rule.set(&m.path, rename_rule);
|
||||
rename_all_de_rule.set(&m.path, rename_rule);
|
||||
}
|
||||
Err(()) => cx.error_spanned_by(
|
||||
Err(_err) => cx.error_spanned_by(
|
||||
s,
|
||||
format!(
|
||||
"unknown rename rule for #[serde(rename_all = {:?})]",
|
||||
@ -356,7 +356,7 @@ impl Container {
|
||||
if let Some(ser) = ser {
|
||||
match RenameRule::from_str(&ser.value()) {
|
||||
Ok(rename_rule) => rename_all_ser_rule.set(&m.path, rename_rule),
|
||||
Err(()) => cx.error_spanned_by(
|
||||
Err(_err) => cx.error_spanned_by(
|
||||
ser,
|
||||
format!(
|
||||
"unknown rename rule for #[serde(rename_all = {:?})]",
|
||||
@ -368,7 +368,7 @@ impl Container {
|
||||
if let Some(de) = de {
|
||||
match RenameRule::from_str(&de.value()) {
|
||||
Ok(rename_rule) => rename_all_de_rule.set(&m.path, rename_rule),
|
||||
Err(()) => cx.error_spanned_by(
|
||||
Err(_err) => cx.error_spanned_by(
|
||||
de,
|
||||
format!(
|
||||
"unknown rename rule for #[serde(rename_all = {:?})]",
|
||||
@ -930,7 +930,7 @@ impl Variant {
|
||||
rename_all_ser_rule.set(&m.path, rename_rule);
|
||||
rename_all_de_rule.set(&m.path, rename_rule);
|
||||
}
|
||||
Err(()) => cx.error_spanned_by(
|
||||
Err(_err) => cx.error_spanned_by(
|
||||
s,
|
||||
format!(
|
||||
"unknown rename rule for #[serde(rename_all = {:?})]",
|
||||
@ -947,7 +947,7 @@ impl Variant {
|
||||
if let Some(ser) = ser {
|
||||
match RenameRule::from_str(&ser.value()) {
|
||||
Ok(rename_rule) => rename_all_ser_rule.set(&m.path, rename_rule),
|
||||
Err(()) => cx.error_spanned_by(
|
||||
Err(_err) => cx.error_spanned_by(
|
||||
ser,
|
||||
format!(
|
||||
"unknown rename rule for #[serde(rename_all = {:?})]",
|
||||
@ -959,7 +959,7 @@ impl Variant {
|
||||
if let Some(de) = de {
|
||||
match RenameRule::from_str(&de.value()) {
|
||||
Ok(rename_rule) => rename_all_de_rule.set(&m.path, rename_rule),
|
||||
Err(()) => cx.error_spanned_by(
|
||||
Err(_err) => cx.error_spanned_by(
|
||||
de,
|
||||
format!(
|
||||
"unknown rename rule for #[serde(rename_all = {:?})]",
|
||||
|
@ -34,7 +34,7 @@ pub enum RenameRule {
|
||||
}
|
||||
|
||||
impl RenameRule {
|
||||
pub fn from_str(rename_all_str: &str) -> Result<Self, ()> {
|
||||
pub fn from_str(rename_all_str: &str) -> Result<Self, ParseError> {
|
||||
match rename_all_str {
|
||||
"lowercase" => Ok(LowerCase),
|
||||
"UPPERCASE" => Ok(UPPERCASE),
|
||||
@ -44,7 +44,7 @@ impl RenameRule {
|
||||
"SCREAMING_SNAKE_CASE" => Ok(ScreamingSnakeCase),
|
||||
"kebab-case" => Ok(KebabCase),
|
||||
"SCREAMING-KEBAB-CASE" => Ok(ScreamingKebabCase),
|
||||
_ => Err(()),
|
||||
unknown => Err(ParseError { unknown }),
|
||||
}
|
||||
}
|
||||
|
||||
@ -104,6 +104,10 @@ impl RenameRule {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ParseError<'a> {
|
||||
unknown: &'a str,
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rename_variants() {
|
||||
for &(original, lower, upper, camel, snake, screaming, kebab, screaming_kebab) in &[
|
||||
|
Loading…
Reference in New Issue
Block a user