Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade Dependencies #212

Merged
merged 3 commits into from
Apr 7, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions gltf-derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ proc-macro = true

[dependencies]
inflections = "1.1"
quote = "0.3"
syn = "0.11"
proc-macro2 = "0.4"
quote = "0.6"
syn = "0.15"
27 changes: 14 additions & 13 deletions gltf-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,31 @@

#![recursion_limit = "128"]

#[macro_use]
extern crate quote;
extern crate proc_macro;

use proc_macro::TokenStream;
use syn::DeriveInput;

#[proc_macro_derive(Validate)]
pub fn derive_validate(input: TokenStream) -> TokenStream {
let source = input.to_string();
let ast = syn::parse_macro_input(&source).unwrap();
let tokens = expand(&ast);
tokens.parse().unwrap()
expand(&syn::parse_macro_input!(input as DeriveInput)).into()
}

fn expand(ast: &syn::MacroInput) -> quote::Tokens {
let fields = match ast.body {
syn::Body::Struct(syn::VariantData::Struct(ref fields)) => fields,
fn expand(ast: &DeriveInput) -> proc_macro2::TokenStream {
use proc_macro2::TokenStream;
use quote::quote;

let fields = match ast.data {
syn::Data::Struct(ref data_struct) => &data_struct.fields,
_ => panic!("#[derive(Validate)] only works on `struct`s"),
};
let ident = &ast.ident;
let minimal_validations: Vec<quote::Tokens> = fields.iter()
let minimal_validations: Vec<TokenStream> = fields
.iter()
.map(|f| f.ident.as_ref().unwrap())
.map(|ident| {
use inflections::Inflect;
let field = ident.as_ref().to_camel_case();
let field = ident.to_string().to_camel_case();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is to_string needed?

Copy link
Contributor Author

@nuew nuew Apr 1, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using .as_ref() to get a str was removed in syn 0.13, because proc_macro2 0.4 removed their Ident AsStr impl, as the normal proc_macro crate removed their AsStr impl, the rationale for which is explained here.

Using .to_string() is now the only supported way to get the name of the identifier.

quote!(
self.#ident.validate_minimally(
_root,
Expand All @@ -38,11 +38,12 @@ fn expand(ast: &syn::MacroInput) -> quote::Tokens {
)
})
.collect();
let complete_validations: Vec<quote::Tokens> = fields.iter()
let complete_validations: Vec<TokenStream> = fields
.iter()
.map(|f| f.ident.as_ref().unwrap())
.map(|ident| {
use inflections::Inflect;
let field = ident.as_ref().to_camel_case();
let field = ident.to_string().to_camel_case();
quote!(
self.#ident.validate_completely(
_root,
Expand Down