1 | use syn::Variant; |
2 | |
3 | use crate::Result; |
4 | |
5 | /// Creates an instance from a specified `syn::Variant`. |
6 | pub trait FromVariant: Sized { |
7 | /// Create an instance from `syn::Variant`, or return an error. |
8 | fn from_variant(variant: &Variant) -> Result<Self>; |
9 | } |
10 | |
11 | impl FromVariant for () { |
12 | fn from_variant(_: &Variant) -> Result<Self> { |
13 | Ok(()) |
14 | } |
15 | } |
16 | |
17 | impl FromVariant for Variant { |
18 | fn from_variant(variant: &Variant) -> Result<Self> { |
19 | Ok(variant.clone()) |
20 | } |
21 | } |
22 | |
23 | impl FromVariant for syn::Ident { |
24 | fn from_variant(variant: &Variant) -> Result<Self> { |
25 | Ok(variant.ident.clone()) |
26 | } |
27 | } |
28 | |
29 | impl FromVariant for Vec<syn::Attribute> { |
30 | fn from_variant(variant: &Variant) -> Result<Self> { |
31 | Ok(variant.attrs.clone()) |
32 | } |
33 | } |
34 | |