Partially revert previous changes

since they were preparing for something that's now not going to happen,
namely a use case for multiple meta items in one #[ruma_api(..)] attribute
This commit is contained in:
Jonas Platte 2019-11-16 00:40:24 +01:00
parent 1334b6c9d9
commit 4d8cc3624f
No known key found for this signature in database
GPG Key ID: 7D261D771D915378
3 changed files with 66 additions and 96 deletions

View File

@ -1,10 +1,7 @@
//! Details of the `#[ruma_api(...)]` attributes. //! Details of the `#[ruma_api(...)]` attributes.
use std::vec;
use syn::{ use syn::{
parse::{Parse, ParseStream}, parse::{Parse, ParseStream},
punctuated::{Pair, Punctuated},
Ident, Token, Ident, Token,
}; };
@ -25,26 +22,7 @@ pub enum Meta {
NameValue(MetaNameValue), NameValue(MetaNameValue),
} }
impl Parse for Meta { impl Meta {
fn parse(input: ParseStream) -> syn::Result<Self> {
let ident = input.parse()?;
if input.peek(Token![=]) {
let _ = input.parse::<Token![=]>();
Ok(Meta::NameValue(MetaNameValue {
name: ident,
value: input.parse()?,
}))
} else {
Ok(Meta::Word(ident))
}
}
}
/// List of `Meta`s
pub struct MetaList(Vec<Meta>);
impl MetaList {
/// Check if the given attribute is a ruma_api attribute. If it is, parse it. /// Check if the given attribute is a ruma_api attribute. If it is, parse it.
/// ///
/// # Panics /// # Panics
@ -70,22 +48,18 @@ impl MetaList {
} }
} }
impl Parse for MetaList { impl Parse for Meta {
fn parse(input: ParseStream) -> syn::Result<Self> { fn parse(input: ParseStream) -> syn::Result<Self> {
Ok(MetaList( let ident = input.parse()?;
Punctuated::<Meta, Token![,]>::parse_terminated(input)?
.into_pairs()
.map(Pair::into_value)
.collect(),
))
}
}
impl IntoIterator for MetaList { if input.peek(Token![=]) {
type Item = Meta; let _ = input.parse::<Token![=]>();
type IntoIter = vec::IntoIter<Meta>; Ok(Meta::NameValue(MetaNameValue {
name: ident,
fn into_iter(self) -> Self::IntoIter { value: input.parse()?,
self.0.into_iter() }))
} else {
Ok(Meta::Word(ident))
}
} }
} }

View File

@ -5,7 +5,7 @@ use quote::{quote, quote_spanned, ToTokens};
use syn::{spanned::Spanned, Field, Ident}; use syn::{spanned::Spanned, Field, Ident};
use crate::api::{ use crate::api::{
attribute::{Meta, MetaList, MetaNameValue}, attribute::{Meta, MetaNameValue},
strip_serde_attrs, strip_serde_attrs,
}; };
@ -133,12 +133,11 @@ impl From<Vec<Field>> for Request {
let mut header = None; let mut header = None;
field.attrs.retain(|attr| { field.attrs.retain(|attr| {
let meta_list = match MetaList::from_attribute(attr) { let meta = match Meta::from_attribute(attr) {
Some(list) => list, Some(m) => m,
None => return true, None => return true,
}; };
for meta in meta_list {
match meta { match meta {
Meta::Word(ident) => { Meta::Word(ident) => {
assert!( assert!(
@ -167,7 +166,6 @@ impl From<Vec<Field>> for Request {
field_kind = Some(RequestFieldKind::Header); field_kind = Some(RequestFieldKind::Header);
} }
} }
}
false false
}); });

View File

@ -5,7 +5,7 @@ use quote::{quote, quote_spanned, ToTokens};
use syn::{spanned::Spanned, Field, Ident}; use syn::{spanned::Spanned, Field, Ident};
use crate::api::{ use crate::api::{
attribute::{Meta, MetaList, MetaNameValue}, attribute::{Meta, MetaNameValue},
strip_serde_attrs, strip_serde_attrs,
}; };
@ -105,12 +105,11 @@ impl From<Vec<Field>> for Response {
let mut header = None; let mut header = None;
field.attrs.retain(|attr| { field.attrs.retain(|attr| {
let meta_list = match MetaList::from_attribute(attr) { let meta = match Meta::from_attribute(attr) {
Some(list) => list, Some(m) => m,
None => return true, None => return true,
}; };
for meta in meta_list {
match meta { match meta {
Meta::Word(ident) => { Meta::Word(ident) => {
assert!( assert!(
@ -138,7 +137,6 @@ impl From<Vec<Field>> for Response {
field_kind = Some(ResponseFieldKind::Header); field_kind = Some(ResponseFieldKind::Header);
} }
} }
}
false false
}); });