procmeta-core 0.3.5

proc-macro helper
Documentation
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()
    }
}