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
use syn::Generics;

use Result;

/// Creates an instance by parsing an entire generics declaration, including the
/// `where` clause.
pub trait FromGenerics: Sized {
    fn from_generics(generics: &Generics) -> Result<Self>;
}

impl FromGenerics for () {
    fn from_generics(_generics: &Generics) -> Result<Self> {
        Ok(())
    }
}

impl FromGenerics for Generics {
    fn from_generics(generics: &Generics) -> Result<Self> {
        Ok(generics.clone())
    }
}

impl<T: FromGenerics> FromGenerics for Result<T> {
    fn from_generics(generics: &Generics) -> Result<Self> {
        Ok(FromGenerics::from_generics(generics))
    }
}