| 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 { |
| 7 | fn from_field(field: &Field) -> Result<Self>; |
| 8 | } |
| 9 | |
| 10 | impl FromField for () { |
| 11 | fn from_field(_: &Field) -> Result<Self> { |
| 12 | Ok(()) |
| 13 | } |
| 14 | } |
| 15 | |
| 16 | impl FromField for Field { |
| 17 | fn from_field(field: &Field) -> Result<Self> { |
| 18 | Ok(field.clone()) |
| 19 | } |
| 20 | } |
| 21 | |
| 22 | impl FromField for syn::Type { |
| 23 | fn from_field(field: &Field) -> Result<Self> { |
| 24 | Ok(field.ty.clone()) |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | impl FromField for syn::Visibility { |
| 29 | fn from_field(field: &Field) -> Result<Self> { |
| 30 | Ok(field.vis.clone()) |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | impl FromField for Vec<syn::Attribute> { |
| 35 | fn from_field(field: &Field) -> Result<Self> { |
| 36 | Ok(field.attrs.clone()) |
| 37 | } |
| 38 | } |
| 39 | |