darling_core/
from_variant.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use syn::Variant;

use crate::Result;

/// Creates an instance from a specified `syn::Variant`.
pub trait FromVariant: Sized {
    /// Create an instance from `syn::Variant`, or return an error.
    fn from_variant(variant: &Variant) -> Result<Self>;
}

impl FromVariant for () {
    fn from_variant(_: &Variant) -> Result<Self> {
        Ok(())
    }
}

impl FromVariant for Variant {
    fn from_variant(variant: &Variant) -> Result<Self> {
        Ok(variant.clone())
    }
}

impl FromVariant for syn::Ident {
    fn from_variant(variant: &Variant) -> Result<Self> {
        Ok(variant.ident.clone())
    }
}

impl FromVariant for Vec<syn::Attribute> {
    fn from_variant(variant: &Variant) -> Result<Self> {
        Ok(variant.attrs.clone())
    }
}