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