Update to latest 'derive_utils'.

This commit is contained in:
Sergio Benitez 2018-09-14 23:15:31 -07:00
parent cfdb2a404b
commit 1f2f38ea5f
9 changed files with 33 additions and 36 deletions

View File

@ -21,7 +21,7 @@ proc-macro = true
[dependencies.derive_utils] [dependencies.derive_utils]
git = "https://github.com/SergioBenitez/derive-utils" git = "https://github.com/SergioBenitez/derive-utils"
rev = "160da392" rev = "5fad71394"
[dependencies] [dependencies]
quote = "0.6" quote = "0.6"

View File

@ -22,7 +22,7 @@ rocket_http = { version = "0.4.0-dev", path = "../http/" }
[dependencies.derive_utils] [dependencies.derive_utils]
git = "https://github.com/SergioBenitez/derive-utils" git = "https://github.com/SergioBenitez/derive-utils"
rev = "160da392" rev = "5fad71394"
[dev-dependencies] [dev-dependencies]
rocket = { version = "0.4.0-dev", path = "../lib" } rocket = { version = "0.4.0-dev", path = "../lib" }

View File

@ -1,5 +1,5 @@
use proc_macro::{Span, TokenStream}; use proc_macro::{Span, TokenStream};
use derive_utils::{*, syn, ext::{TypeExt, Split3}}; use derive_utils::{*, ext::{TypeExt, Split3}};
#[derive(FromMeta)] #[derive(FromMeta)]
struct Form { struct Form {
@ -23,13 +23,13 @@ fn is_valid_field_name(s: &str) -> bool {
} }
impl FromMeta for FormField { impl FromMeta for FormField {
fn from_meta(meta: &syn::Meta) -> Result<Self> { fn from_meta(meta: MetaItem) -> Result<Self> {
let string = <SpanWrapped<String>>::from_meta(meta)?; let string = String::from_meta(meta)?;
if !is_valid_field_name(&string.value) { if !is_valid_field_name(&string) {
return Err(string.value_span.error("invalid form field name")); return Err(meta.value_span().error("invalid form field name"));
} }
Ok(FormField { span: string.value_span, name: string.value }) Ok(FormField { span: meta.value_span(), name: string })
} }
} }

View File

@ -1,7 +1,6 @@
use syn;
use quote::ToTokens; use quote::ToTokens;
use proc_macro2::TokenStream as TokenStream2; use proc_macro2::TokenStream as TokenStream2;
use derive_utils::{SpanWrapped, FromMeta, Result, ext::Split2}; use derive_utils::{FromMeta, MetaItem, Result, ext::Split2};
use rocket_http as http; use rocket_http as http;
pub struct ContentType(http::ContentType); pub struct ContentType(http::ContentType);
@ -11,13 +10,13 @@ pub struct Status(http::Status);
struct MediaType(http::MediaType); struct MediaType(http::MediaType);
impl FromMeta for Status { impl FromMeta for Status {
fn from_meta(meta: &syn::Meta) -> Result<Self> { fn from_meta(meta: MetaItem) -> Result<Self> {
let num = <SpanWrapped<usize>>::from_meta(meta)?; let num = usize::from_meta(meta)?;
if num.value < 100 || num.value >= 600 { if num < 100 || num >= 600 {
return Err(num.value_span.error("status must be in range [100, 600)")); return Err(meta.value_span().error("status must be in range [100, 600)"));
} }
Ok(Status(http::Status::raw(num.value as u16))) Ok(Status(http::Status::raw(num as u16)))
} }
} }
@ -29,12 +28,10 @@ impl ToTokens for Status {
} }
impl FromMeta for ContentType { impl FromMeta for ContentType {
fn from_meta(meta: &syn::Meta) -> Result<Self> { fn from_meta(meta: MetaItem) -> Result<Self> {
let s = <SpanWrapped<String>>::from_meta(meta)?; http::ContentType::parse_flexible(&String::from_meta(meta)?)
let parsed = http::ContentType::parse_flexible(&s.value) .map(ContentType)
.ok_or_else(|| s.value_span.error("invalid or unknown content-type"))?; .ok_or(meta.value_span().error("invalid or unknown content-type"))
Ok(ContentType(parsed))
} }
} }

View File

@ -10,7 +10,7 @@ extern crate rocket_http;
mod derive; mod derive;
mod http_codegen; mod http_codegen;
crate use derive_utils::{syn, proc_macro2}; crate use derive_utils::proc_macro2;
use proc_macro::TokenStream; use proc_macro::TokenStream;

View File

@ -74,14 +74,14 @@ struct MyForm1 {
#[derive(FromForm)] #[derive(FromForm)]
struct MyForm2 { struct MyForm2 {
#[form("blah")] #[form("blah")]
//~^ ERROR unexpected literal //~^ ERROR expected key/value
my_field: String, my_field: String,
} }
#[derive(FromForm)] #[derive(FromForm)]
struct MyForm3 { struct MyForm3 {
#[form(123)] #[form(123)]
//~^ ERROR unexpected literal //~^ ERROR expected key/value
my_field: String, my_field: String,
} }
@ -110,7 +110,7 @@ struct MyForm6 {
#[derive(FromForm)] #[derive(FromForm)]
struct MyForm7 { struct MyForm7 {
#[form(field)] #[form(field)]
//~^ ERROR malformed parameter //~^ ERROR expected literal or key/value
my_field: String, my_field: String,
} }

View File

@ -133,20 +133,20 @@ note: error occurred while deriving `FromForm`
60 | #[derive(FromForm)] 60 | #[derive(FromForm)]
| ^^^^^^^^ | ^^^^^^^^
error: malformed attribute error: malformed attribute: expected list
--> $DIR/from_form.rs:69:7 --> $DIR/from_form.rs:69:7
| |
69 | #[form] 69 | #[form]
| ^^^^ | ^^^^
| |
= help: expected syntax: #[attr(key = value, ..)] = help: expected syntax: #[form(key = value, ..)]
note: error occurred while deriving `FromForm` note: error occurred while deriving `FromForm`
--> $DIR/from_form.rs:67:10 --> $DIR/from_form.rs:67:10
| |
67 | #[derive(FromForm)] 67 | #[derive(FromForm)]
| ^^^^^^^^ | ^^^^^^^^
error: unexpected literal error: expected key/value pair
--> $DIR/from_form.rs:76:12 --> $DIR/from_form.rs:76:12
| |
76 | #[form("blah")] 76 | #[form("blah")]
@ -158,7 +158,7 @@ note: error occurred while deriving `FromForm`
74 | #[derive(FromForm)] 74 | #[derive(FromForm)]
| ^^^^^^^^ | ^^^^^^^^
error: unexpected literal error: expected key/value pair
--> $DIR/from_form.rs:83:12 --> $DIR/from_form.rs:83:12
| |
83 | #[form(123)] 83 | #[form(123)]
@ -170,7 +170,7 @@ note: error occurred while deriving `FromForm`
81 | #[derive(FromForm)] 81 | #[derive(FromForm)]
| ^^^^^^^^ | ^^^^^^^^
error: unexpected attribute parameter: beep error: unexpected attribute parameter: `beep`
--> $DIR/from_form.rs:90:12 --> $DIR/from_form.rs:90:12
| |
90 | #[form(beep = "bop")] 90 | #[form(beep = "bop")]
@ -194,7 +194,7 @@ note: error occurred while deriving `FromForm`
95 | #[derive(FromForm)] 95 | #[derive(FromForm)]
| ^^^^^^^^ | ^^^^^^^^
error: invalid value: expected string error: invalid value: expected string literal
--> $DIR/from_form.rs:105:20 --> $DIR/from_form.rs:105:20
| |
105 | #[form(field = true)] 105 | #[form(field = true)]
@ -206,7 +206,7 @@ note: error occurred while deriving `FromForm`
103 | #[derive(FromForm)] 103 | #[derive(FromForm)]
| ^^^^^^^^ | ^^^^^^^^
error: malformed parameter: expected key/value pair error: expected literal or key/value pair
--> $DIR/from_form.rs:112:12 --> $DIR/from_form.rs:112:12
| |
112 | #[form(field)] 112 | #[form(field)]
@ -218,7 +218,7 @@ note: error occurred while deriving `FromForm`
110 | #[derive(FromForm)] 110 | #[derive(FromForm)]
| ^^^^^^^^ | ^^^^^^^^
error: invalid value: expected string error: invalid value: expected string literal
--> $DIR/from_form.rs:119:20 --> $DIR/from_form.rs:119:20
| |
119 | #[form(field = 123)] 119 | #[form(field = 123)]

View File

@ -40,6 +40,6 @@ enum Bar1 {
#[derive(FromFormValue)] #[derive(FromFormValue)]
enum Bar2 { enum Bar2 {
#[form(value)] #[form(value)]
//~^ ERROR malformed parameter //~^ ERROR expected literal or key/value
A, A,
} }

View File

@ -67,7 +67,7 @@ note: error occurred while deriving `FromFormValue`
27 | #[derive(FromFormValue)] 27 | #[derive(FromFormValue)]
| ^^^^^^^^^^^^^ | ^^^^^^^^^^^^^
error: invalid value: expected string error: invalid value: expected string literal
--> $DIR/from_form_value.rs:35:20 --> $DIR/from_form_value.rs:35:20
| |
35 | #[form(value = 123)] 35 | #[form(value = 123)]
@ -79,7 +79,7 @@ note: error occurred while deriving `FromFormValue`
33 | #[derive(FromFormValue)] 33 | #[derive(FromFormValue)]
| ^^^^^^^^^^^^^ | ^^^^^^^^^^^^^
error: malformed parameter: expected key/value pair error: expected literal or key/value pair
--> $DIR/from_form_value.rs:42:12 --> $DIR/from_form_value.rs:42:12
| |
42 | #[form(value)] 42 | #[form(value)]