Skip to content

Commit 710d03a

Browse files
committed
Adress review comments
1 parent 8d0590e commit 710d03a

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

src/lib.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ impl Traits {
110110
let pattern = quote! { Self };
111111

112112
match &data.fields {
113-
Fields::Named(fields) => self.build_struct(debug_name, &pattern, None, fields),
114-
Fields::Unnamed(fields) => self.generate_tuple(debug_name, &pattern, None, fields),
113+
Fields::Named(fields) => self.build_for_struct(debug_name, &pattern, None, fields),
114+
Fields::Unnamed(fields) => self.build_for_tuple(debug_name, &pattern, None, fields),
115115
fields @ Fields::Unit => return Err(Error::new(
116116
fields.span(),
117117
"Using `derive_where` on unit struct is not supported as unit structs don't support generics.")),
@@ -129,20 +129,20 @@ impl Traits {
129129
let pattern = quote! { Self::#debug_name };
130130

131131
match &variant.fields {
132-
Fields::Named(fields) => self.build_struct(
132+
Fields::Named(fields) => self.build_for_struct(
133133
debug_name,
134134
&pattern,
135135
Some((index, &variants)),
136136
fields,
137137
),
138-
Fields::Unnamed(fields) => self.generate_tuple(
138+
Fields::Unnamed(fields) => self.build_for_tuple(
139139
debug_name,
140140
&pattern,
141141
Some((index, &variants)),
142142
fields,
143143
),
144144
Fields::Unit => {
145-
self.generate_unit(debug_name, &pattern, Some((index, &variants)))
145+
self.build_for_unit(debug_name, &pattern, Some((index, &variants)))
146146
}
147147
}
148148
})
@@ -288,8 +288,10 @@ impl Traits {
288288
}
289289
}
290290

291-
/// Build method body if type is a structure.
292-
fn build_struct(
291+
/// Build method body if type is a structure. `pattern` is used to
292+
/// generalize over matching against a `struct` or an `enum`: `Self` for
293+
/// `struct`s and `Self::Variant` for `enum`s.
294+
fn build_for_struct(
293295
self,
294296
debug_name: &Ident,
295297
pattern: &TokenStream,
@@ -371,8 +373,9 @@ impl Traits {
371373
}
372374
}
373375

374-
/// Build method body if type is a tuple.
375-
fn generate_tuple(
376+
/// Build method body if type is a tuple. See description for `pattern` in
377+
/// [`Self::build_for_struct`].
378+
fn build_for_tuple(
376379
self,
377380
debug_name: &Ident,
378381
pattern: &TokenStream,
@@ -447,8 +450,9 @@ impl Traits {
447450
}
448451
}
449452

450-
/// Build method body if type is a unit.
451-
fn generate_unit(
453+
/// Build method body if type is a unit. See description for `pattern` in
454+
/// [`Self::build_for_struct`].
455+
fn build_for_unit(
452456
self,
453457
debug_name: &Ident,
454458
pattern: &TokenStream,

0 commit comments

Comments
 (0)