Skip to content

Commit 20e2995

Browse files
committed
Allow generic arguments in enum variants
1 parent 2f7eb49 commit 20e2995

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

Diff for: src/lib.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
//! }
7070
//! }
7171
//! }
72-
//!
72+
//!
7373
//! impl From<Cat> for Animal {
7474
//! fn from(from: Cat) -> Self {
7575
//! Animal::Cat(from)
@@ -250,7 +250,9 @@ fn implement_trait(
250250
}
251251
}
252252

253-
let match_block = gen_match_block(variants, |_| gen_static_method_call(quote! { #trait_ident }, sig));
253+
let match_block = gen_match_block(variants, |_| {
254+
gen_static_method_call(quote! { #trait_ident }, sig)
255+
});
254256
let tokens = quote! { #sig { #match_block } };
255257
parse2::<ImplItem>(tokens).unwrap()
256258
}
@@ -279,7 +281,7 @@ fn implement_raw(variants: &[WrapperVariant], pseudo_impl: &mut ItemImpl) {
279281

280282
let match_block = gen_match_block(variants, |variant| {
281283
let ty = &variant.wrapped;
282-
gen_static_method_call(quote! { #ty }, &method.sig)
284+
gen_static_method_call(quote! { <#ty> }, &method.sig)
283285
});
284286
let body = quote! { { #match_block } };
285287
method.block = syn::parse2(body).unwrap();
@@ -332,10 +334,13 @@ impl GenerateProxyImpl {
332334
.get(&path)
333335
.unwrap_or_else(|| panic!("missing declaration of trait `{}`", path))
334336
}
335-
337+
336338
fn impl_from_variants(&self, module: &mut ItemMod) {
337339
let proxy_enum = &self.proxy_enum;
338-
for WrapperVariant { variant, wrapped, .. } in self.get_variants() {
340+
for WrapperVariant {
341+
variant, wrapped, ..
342+
} in self.get_variants()
343+
{
339344
let variant = &variant.ident;
340345
let tokens = quote! {
341346
impl From<#wrapped> for #proxy_enum {
@@ -345,7 +350,7 @@ impl GenerateProxyImpl {
345350
}
346351
};
347352
let from_impl: ItemImpl = syn::parse2(tokens).unwrap();
348-
module.content.as_mut().unwrap().1.push(from_impl.into());
353+
module.content.as_mut().unwrap().1.push(from_impl.into());
349354
}
350355
}
351356
}

0 commit comments

Comments
 (0)