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 all commits
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
16 changes: 11 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,20 @@ travis-ci = { repository = "gltf-rs/gltf" }
members = ["gltf-derive", "gltf-json"]

[dev-dependencies]
approx = "0.1.1"
approx = "0.3"

[dependencies]
base64 = { optional = true, version = "0.6" }
base64 = { optional = true, version = "0.10" }
byteorder = "1.1"
cgmath = "0.15"
cgmath = "0.17"
gltf-json = { path = "gltf-json", version = "0.11.3" }
image = { optional = true, version = "0.19" }
lazy_static = "0.2"
lazy_static = "1"

[dependencies.image]
default-features = false
features = ["jpeg", "png_codec"]
Copy link
Member

Choose a reason for hiding this comment

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

This is better.

optional = true
version = "0.21"

[features]
default = ["import", "utils", "names"]
Expand All @@ -36,6 +41,7 @@ names = ["gltf-json/names"]
utils = []
import = ["base64", "image"]
KHR_materials_pbrSpecularGlossiness = ["gltf-json/KHR_materials_pbrSpecularGlossiness"]
image_jpeg_rayon = ["image/jpeg_rayon"]

[[example]]
name = "gltf-display"
Expand Down
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
10 changes: 9 additions & 1 deletion src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ pub enum Format {

/// Red, green, blue, alpha.
R8G8B8A8,

/// Blue, green, red.
B8G8R8,

/// Blue, green, red, alpha.
B8G8R8A8,
}

/// Describes an image data source.
Expand Down Expand Up @@ -127,12 +133,14 @@ impl Data {
/// Note: We don't implement `From<DynamicImage>` since we don't want
/// to expose such functionality to the user.
pub(crate) fn new(image: DynamicImage) -> Self {
use image_crate::GenericImage;
use image_crate::GenericImageView;
let format = match image {
DynamicImage::ImageLuma8(_) => Format::R8,
DynamicImage::ImageLumaA8(_) => Format::R8G8,
DynamicImage::ImageRgb8(_) => Format::R8G8B8,
DynamicImage::ImageRgba8(_) => Format::R8G8B8A8,
DynamicImage::ImageBgr8(_) => Format::B8G8R8,
DynamicImage::ImageBgra8(_) => Format::B8G8R8A8,
};
let (width, height) = image.dimensions();
let pixels = image.raw_pixels();
Expand Down