1 | use syn::Generics; |
2 | |
3 | use crate::Result; |
4 | |
5 | /// Creates an instance by parsing an entire generics declaration, including the |
6 | /// `where` clause. |
7 | pub trait FromGenerics: Sized { |
8 | fn from_generics(generics: &Generics) -> Result<Self>; |
9 | } |
10 | |
11 | impl FromGenerics for () { |
12 | fn from_generics(_generics: &Generics) -> Result<Self> { |
13 | Ok(()) |
14 | } |
15 | } |
16 | |
17 | impl FromGenerics for Generics { |
18 | fn from_generics(generics: &Generics) -> Result<Self> { |
19 | Ok(generics.clone()) |
20 | } |
21 | } |
22 | |
23 | impl<T: FromGenerics> FromGenerics for Result<T> { |
24 | fn from_generics(generics: &Generics) -> Result<Self> { |
25 | Ok(FromGenerics::from_generics(generics)) |
26 | } |
27 | } |
28 | |