Improve decl storage parsing (#4731)

* improve decl storage parsing

* remove hidding detail macro

* Apply suggestions from code review

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
thiolliere
2020-01-24 20:04:11 +01:00
committed by Bastian Köcher
parent fc99887de0
commit e4f3e85585
3 changed files with 116 additions and 119 deletions
@@ -164,39 +164,6 @@ impl ToTokens for OuterAttributes {
}
}
#[derive(Debug)]
pub struct Opt<P> {
pub inner: Option<P>,
}
impl<P: Parse> Parse for Opt<P> {
// Note that it cost a double parsing (same as enum derive)
fn parse(input: ParseStream) -> Result<Self> {
let inner = match input.fork().parse::<P>() {
Ok(_item) => Some(input.parse().expect("Same parsing ran before")),
Err(_e) => None,
};
Ok(Opt { inner })
}
}
impl<P: ToTokens> ToTokens for Opt<P> {
fn to_tokens(&self, tokens: &mut TokenStream) {
if let Some(ref p) = self.inner {
p.to_tokens(tokens);
}
}
}
impl <P: Clone> Clone for Opt<P> {
fn clone(&self) -> Self {
Self {
inner: self.inner.clone()
}
}
}
pub fn extract_type_option(typ: &syn::Type) -> Option<syn::Type> {
if let syn::Type::Path(ref path) = typ {
let v = path.path.segments.last()?;