From f0f4f9bd17439f2ae4910b3f8b8c8b40edd93d7e Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Tue, 15 May 2018 22:57:06 -0700 Subject: [PATCH] Detect header attributes as name/value pairs. --- src/api/request.rs | 29 +++++++++++++++-------------- src/api/response.rs | 21 +++++++++++---------- 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/src/api/request.rs b/src/api/request.rs index bd90860b..2c9084fb 100644 --- a/src/api/request.rs +++ b/src/api/request.rs @@ -92,25 +92,26 @@ impl From> for Request { match meta_item { Meta::Word(ident) => { match ident.as_ref() { - "body" => { - has_newtype_body = true; - field_kind = RequestFieldKind::NewtypeBody; - } - "header" => field_kind = RequestFieldKind::Header, - "path" => field_kind = RequestFieldKind::Path, - "query" => field_kind = RequestFieldKind::Query, - _ => panic!( - "ruma_api! attribute meta item on requests must be: body, header, path, or query" - ), + "body" => { + has_newtype_body = true; + field_kind = RequestFieldKind::NewtypeBody; + } + "path" => field_kind = RequestFieldKind::Path, + "query" => field_kind = RequestFieldKind::Query, + _ => panic!("ruma_api! single-word attribute on requests must be: body, path, or query"), } } - _ => panic!( - "ruma_api! attribute meta item on requests cannot be a list or name/value pair" - ), + Meta::NameValue(name_value) => { + match name_value.ident.as_ref() { + "header" => field_kind = RequestFieldKind::Header, + _ => panic!("ruma_api! name/value pair attribute on requests must be: header"), + } + } + _ => panic!("ruma_api! attributes on requests must be a single word or a name/value pair"), } } NestedMeta::Literal(_) => panic!( - "ruma_api! attribute meta item on requests must be: body, header, path, or query" + "ruma_api! attributes on requests must be: body, header, path, or query" ), } } diff --git a/src/api/response.rs b/src/api/response.rs index 1b0105fd..d4388851 100644 --- a/src/api/response.rs +++ b/src/api/response.rs @@ -101,18 +101,19 @@ impl From> for Response { Meta::Word(ident) => { match ident.as_ref() { "body" => { - has_newtype_body = true; - field_kind = ResponseFieldKind::NewtypeBody; - } - "header" => field_kind = ResponseFieldKind::Header, - _ => panic!( - "ruma_api! attribute meta item on responses must be: header" - ), + has_newtype_body = true; + field_kind = ResponseFieldKind::NewtypeBody; + } + _ => panic!("ruma_api! single-word attribute on responses must be: body"), } } - _ => panic!( - "ruma_api! attribute meta item on responses cannot be a list or name/value pair" - ), + Meta::NameValue(name_value) => { + match name_value.ident.as_ref() { + "header" => field_kind = ResponseFieldKind::Header, + _ => panic!("ruma_api! name/value pair attribute on requests must be: header"), + } + } + _ => panic!("ruma_api! attributes on responses must be a single word or a name/value pair"), } } NestedMeta::Literal(_) => panic!(