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