darling_core/
from_field.rs

1use syn::Field;
2
3use crate::Result;
4
5/// Creates an instance by parsing an individual field and its attributes.
6pub trait FromField: Sized {
7    fn from_field(field: &Field) -> Result<Self>;
8}
9
10impl FromField for () {
11    fn from_field(_: &Field) -> Result<Self> {
12        Ok(())
13    }
14}
15
16impl FromField for Field {
17    fn from_field(field: &Field) -> Result<Self> {
18        Ok(field.clone())
19    }
20}
21
22impl FromField for syn::Type {
23    fn from_field(field: &Field) -> Result<Self> {
24        Ok(field.ty.clone())
25    }
26}
27
28impl FromField for syn::Visibility {
29    fn from_field(field: &Field) -> Result<Self> {
30        Ok(field.vis.clone())
31    }
32}
33
34impl FromField for Vec<syn::Attribute> {
35    fn from_field(field: &Field) -> Result<Self> {
36        Ok(field.attrs.clone())
37    }
38}