Skip to content

Commit

Permalink
Pass RenameRule, RenameAllRules by value
Browse files Browse the repository at this point in the history
  • Loading branch information
jplatte committed Oct 2, 2020
1 parent e377ec1 commit 0dd37a7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion serde_derive/src/internals/ast.rs
Expand Up @@ -89,7 +89,7 @@ impl<'a> Container<'a> {
has_flatten = true;
}
field.attrs.rename_by_rules(
&variant
variant
.attrs
.rename_all_rules()
.or(attrs.rename_all_fields_rules()),
Expand Down
22 changes: 11 additions & 11 deletions serde_derive/src/internals/attr.rs
Expand Up @@ -209,10 +209,10 @@ pub struct RenameAllRules {
impl RenameAllRules {
/// Returns a new `RenameAllRules` with the individual rules of `self` and
/// `other_rules` joined by `RenameRules::or`.
pub fn or(&self, other_rules: &Self) -> Self {
pub fn or(self, other_rules: Self) -> Self {
Self {
serialize: self.serialize.or(&other_rules.serialize),
deserialize: self.deserialize.or(&other_rules.deserialize),
serialize: self.serialize.or(other_rules.serialize),
deserialize: self.deserialize.or(other_rules.deserialize),
}
}
}
Expand Down Expand Up @@ -706,12 +706,12 @@ impl Container {
&self.name
}

pub fn rename_all_rules(&self) -> &RenameAllRules {
&self.rename_all_rules
pub fn rename_all_rules(&self) -> RenameAllRules {
self.rename_all_rules
}

pub fn rename_all_fields_rules(&self) -> &RenameAllRules {
&self.rename_all_fields_rules
pub fn rename_all_fields_rules(&self) -> RenameAllRules {
self.rename_all_fields_rules
}

pub fn transparent(&self) -> bool {
Expand Down Expand Up @@ -1156,7 +1156,7 @@ impl Variant {
self.name.deserialize_aliases()
}

pub fn rename_by_rules(&mut self, rules: &RenameAllRules) {
pub fn rename_by_rules(&mut self, rules: RenameAllRules) {
if !self.name.serialize_renamed {
self.name.serialize = rules.serialize.apply_to_variant(&self.name.serialize);
}
Expand All @@ -1165,8 +1165,8 @@ impl Variant {
}
}

pub fn rename_all_rules(&self) -> &RenameAllRules {
&self.rename_all_rules
pub fn rename_all_rules(&self) -> RenameAllRules {
self.rename_all_rules
}

pub fn ser_bound(&self) -> Option<&[syn::WherePredicate]> {
Expand Down Expand Up @@ -1528,7 +1528,7 @@ impl Field {
self.name.deserialize_aliases()
}

pub fn rename_by_rules(&mut self, rules: &RenameAllRules) {
pub fn rename_by_rules(&mut self, rules: RenameAllRules) {
if !self.name.serialize_renamed {
self.name.serialize = rules.serialize.apply_to_field(&self.name.serialize);
}
Expand Down
14 changes: 7 additions & 7 deletions serde_derive/src/internals/case.rs
Expand Up @@ -37,8 +37,8 @@ pub enum RenameRule {

impl RenameRule {
/// Apply a renaming rule to an enum variant, returning the version expected in the source.
pub fn apply_to_variant(&self, variant: &str) -> String {
match *self {
pub fn apply_to_variant(self, variant: &str) -> String {
match self {
None | PascalCase => variant.to_owned(),
LowerCase => variant.to_ascii_lowercase(),
UPPERCASE => variant.to_ascii_uppercase(),
Expand All @@ -62,8 +62,8 @@ impl RenameRule {
}

/// Apply a renaming rule to a struct field, returning the version expected in the source.
pub fn apply_to_field(&self, field: &str) -> String {
match *self {
pub fn apply_to_field(self, field: &str) -> String {
match self {
None | LowerCase | SnakeCase => field.to_owned(),
UPPERCASE => field.to_ascii_uppercase(),
PascalCase => {
Expand Down Expand Up @@ -92,10 +92,10 @@ impl RenameRule {
}

/// Returns the `RenameRule` if it is not `None`, `rule_b` otherwise.
pub fn or(&self, rule_b: &Self) -> Self {
pub fn or(self, rule_b: Self) -> Self {
match self {
None => *rule_b,
_ => *self,
None => rule_b,
_ => self,
}
}
}
Expand Down

0 comments on commit 0dd37a7

Please sign in to comment.