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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
use syn::{LitBool, LitFloat, LitInt, LitStr, Result};

pub trait Converter<T>: syn::parse::Parse {
    fn convert(stream: &syn::parse::ParseStream) -> Result<T> {
        let origin: Self = stream.parse()?;
        Self::into(origin)
    }
    fn into(self) -> Result<T>;
}

impl<T, C: Converter<T>> Converter<Option<T>> for C {
    fn into(self) -> Result<Option<T>> {
        let result = C::into(self);
        result.map(|v| Some(v))
    }
}

impl Converter<String> for LitStr {
    fn into(self) -> Result<String> {
        Ok(self.value())
    }
}

impl Converter<bool> for LitBool {
    fn into(self) -> Result<bool> {
        Ok(self.value)
    }
}

impl Converter<f32> for LitFloat {
    fn into(self) -> Result<f32> {
        self.base10_parse()
    }
}

impl Converter<f64> for LitFloat {
    fn into(self) -> Result<f64> {
        self.base10_parse()
    }
}

impl Converter<i8> for LitInt {
    fn into(self) -> Result<i8> {
        self.base10_parse()
    }
}

impl Converter<i16> for LitInt {
    fn into(self) -> Result<i16> {
        self.base10_parse()
    }
}

impl Converter<i32> for LitInt {
    fn into(self) -> Result<i32> {
        self.base10_parse()
    }
}

impl Converter<i64> for LitInt {
    fn into(self) -> Result<i64> {
        self.base10_parse()
    }
}

impl Converter<usize> for LitInt {
    fn into(self) -> Result<usize> {
        self.base10_parse()
    }
}