Skip to content

Commit

Permalink
Merge pull request #212 from nuew/upgrade_deps
Browse files Browse the repository at this point in the history
Upgrade Dependencies
  • Loading branch information
alteous authored Apr 7, 2019
2 parents dc2676a + 6b4f7f9 commit acf33a9
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 21 deletions.
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"]
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();
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

0 comments on commit acf33a9

Please sign in to comment.