Skip to content

Commit

Permalink
Merge pull request #321 from IcanDivideBy0/rustfmt
Browse files Browse the repository at this point in the history
rustfmt pass
  • Loading branch information
IcanDivideBy0 authored Jan 29, 2022
2 parents b08affb + 3823768 commit 7fe2af0
Show file tree
Hide file tree
Showing 66 changed files with 1,302 additions and 906 deletions.
3 changes: 2 additions & 1 deletion .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ before_test:
- git submodule update --init --recursive

test_script:
- cargo test --all --all-features --release
- cargo test --all --all-features --release
- cargo fmt --all -- --check
38 changes: 21 additions & 17 deletions examples/export/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ fn export(output: Output) {
extensions: Default::default(),
extras: Default::default(),
name: None,
uri: if output == Output::Standard { Some("buffer0.bin".into()) } else { None },
uri: if output == Output::Standard {
Some("buffer0.bin".into())
} else {
None
},
};
let buffer_view = json::buffer::View {
buffer: json::Index::new(0),
Expand All @@ -76,7 +80,9 @@ fn export(output: Output) {
buffer_view: Some(json::Index::new(0)),
byte_offset: 0,
count: triangle_vertices.len() as u32,
component_type: Valid(json::accessor::GenericComponentType(json::accessor::ComponentType::F32)),
component_type: Valid(json::accessor::GenericComponentType(
json::accessor::ComponentType::F32,
)),
extensions: Default::default(),
extras: Default::default(),
type_: Valid(json::accessor::Type::Vec3),
Expand All @@ -90,7 +96,9 @@ fn export(output: Output) {
buffer_view: Some(json::Index::new(0)),
byte_offset: (3 * mem::size_of::<f32>()) as u32,
count: triangle_vertices.len() as u32,
component_type: Valid(json::accessor::GenericComponentType(json::accessor::ComponentType::F32)),
component_type: Valid(json::accessor::GenericComponentType(
json::accessor::ComponentType::F32,
)),
extensions: Default::default(),
extras: Default::default(),
type_: Valid(json::accessor::Type::Vec3),
Expand Down Expand Up @@ -145,15 +153,13 @@ fn export(output: Output) {
buffer_views: vec![buffer_view],
meshes: vec![mesh],
nodes: vec![node],
scenes: vec![
json::Scene {
extensions: Default::default(),
extras: Default::default(),
name: None,
nodes: vec![json::Index::new(0)],
},
],
.. Default::default()
scenes: vec![json::Scene {
extensions: Default::default(),
extras: Default::default(),
name: None,
nodes: vec![json::Index::new(0)],
}],
..Default::default()
};

match output {
Expand All @@ -166,10 +172,9 @@ fn export(output: Output) {
let bin = to_padded_byte_vector(triangle_vertices);
let mut writer = fs::File::create("triangle/buffer0.bin").expect("I/O error");
writer.write_all(&bin).expect("I/O error");
},
}
Output::Binary => {
let json_string = json::serialize::to_string(&root)
.expect("Serialization error");
let json_string = json::serialize::to_string(&root).expect("Serialization error");
let mut json_offset = json_string.len() as u32;
align_to_multiple_of_four(&mut json_offset);
let glb = gltf::binary::Glb {
Expand All @@ -183,8 +188,7 @@ fn export(output: Output) {
};
let writer = std::fs::File::create("triangle.glb").expect("I/O error");
glb.to_writer(writer).expect("glTF binary output error");

},
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion examples/tree/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{fs, io};
use std::boxed::Box;
use std::error::Error as StdError;
use std::{fs, io};

fn print_tree(node: &gltf::Node, depth: i32) {
for _ in 0..(depth - 1) {
Expand Down
83 changes: 38 additions & 45 deletions gltf-json/src/accessor.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,24 @@
use crate::validation::{Checked, Error, Validate};
use crate::{buffer, extensions, Extras, Index, Path, Root};
use gltf_derive::Validate;
use serde_derive::{Serialize, Deserialize};
use crate::{buffer, extensions, Extras, Index, Root, Path};
use serde::{de, ser};
use serde_derive::{Deserialize, Serialize};
use serde_json::Value;
use std::fmt;
use crate::validation::{Checked, Error, Validate};

/// The component data type.
#[derive(Clone, Copy, Debug, Eq, PartialEq, Deserialize)]
pub enum ComponentType {
/// Corresponds to `GL_BYTE`.
I8 = 1,

/// Corresponds to `GL_UNSIGNED_BYTE`.
U8,

/// Corresponds to `GL_SHORT`.
I16,

/// Corresponds to `GL_UNSIGNED_SHORT`.
U16,

/// Corresponds to `GL_UNSIGNED_INT`.
U32,

/// Corresponds to `GL_FLOAT`.
F32,
}
Expand All @@ -33,22 +28,16 @@ pub enum ComponentType {
pub enum Type {
/// Scalar quantity.
Scalar = 1,

/// 2D vector.
Vec2,

/// 3D vector.
Vec3,

/// 4D vector.
Vec4,

/// 2x2 matrix.
Mat2,

/// 3x3 matrix.
Mat3,

/// 4x4 matrix.
Mat4,
}
Expand Down Expand Up @@ -82,22 +71,11 @@ pub const VALID_COMPONENT_TYPES: &'static [u32] = &[
];

/// All valid index component types.
pub const VALID_INDEX_TYPES: &'static [u32] = &[
UNSIGNED_BYTE,
UNSIGNED_SHORT,
UNSIGNED_INT,
];
pub const VALID_INDEX_TYPES: &'static [u32] = &[UNSIGNED_BYTE, UNSIGNED_SHORT, UNSIGNED_INT];

/// All valid accessor types.
pub const VALID_ACCESSOR_TYPES: &'static [&'static str] = &[
"SCALAR",
"VEC2",
"VEC3",
"VEC4",
"MAT2",
"MAT3",
"MAT4",
];
pub const VALID_ACCESSOR_TYPES: &'static [&'static str] =
&["SCALAR", "VEC2", "VEC3", "VEC4", "MAT2", "MAT3", "MAT4"];

/// Contains data structures for sparse storage.
pub mod sparse {
Expand Down Expand Up @@ -238,7 +216,7 @@ pub struct Accessor {
/// Specifies whether integer data values should be normalized.
#[serde(default, skip_serializing_if = "is_normalized_default")]
pub normalized: bool,

/// Sparse storage of attributes that deviate from their initialization
/// value.
#[serde(default)]
Expand All @@ -248,25 +226,34 @@ pub struct Accessor {

impl Validate for Accessor {
fn validate<P, R>(&self, root: &Root, path: P, report: &mut R)
where P: Fn() -> Path, R: FnMut(&dyn Fn() -> Path, Error)
where
P: Fn() -> Path,
R: FnMut(&dyn Fn() -> Path, Error),
{
if self.sparse.is_none() && self.buffer_view.is_none() {
// If sparse is missing, then bufferView must be present. Report that bufferView is
// missing since it is the more common one to require.
report(&|| path().field("bufferView"), Error::Missing);
}

self.buffer_view.validate(root, || path().field("bufferView"), report);
self.byte_offset.validate(root, || path().field("byteOffset"), report);
self.buffer_view
.validate(root, || path().field("bufferView"), report);
self.byte_offset
.validate(root, || path().field("byteOffset"), report);
self.count.validate(root, || path().field("count"), report);
self.component_type.validate(root, || path().field("componentType"), report);
self.extensions.validate(root, || path().field("extensions"), report);
self.extras.validate(root, || path().field("extras"), report);
self.component_type
.validate(root, || path().field("componentType"), report);
self.extensions
.validate(root, || path().field("extensions"), report);
self.extras
.validate(root, || path().field("extras"), report);
self.type_.validate(root, || path().field("type"), report);
self.min.validate(root, || path().field("min"), report);
self.max.validate(root, || path().field("max"), report);
self.normalized.validate(root, || path().field("normalized"), report);
self.sparse.validate(root, || path().field("sparse"), report);
self.normalized
.validate(root, || path().field("normalized"), report);
self.sparse
.validate(root, || path().field("sparse"), report);
}
}

Expand All @@ -285,7 +272,8 @@ pub struct GenericComponentType(pub ComponentType);

impl<'de> de::Deserialize<'de> for Checked<GenericComponentType> {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: de::Deserializer<'de>
where
D: de::Deserializer<'de>,
{
struct Visitor;
impl<'de> de::Visitor<'de> for Visitor {
Expand All @@ -296,7 +284,8 @@ impl<'de> de::Deserialize<'de> for Checked<GenericComponentType> {
}

fn visit_u64<E>(self, value: u64) -> Result<Self::Value, E>
where E: de::Error
where
E: de::Error,
{
use self::ComponentType::*;
use crate::validation::Checked::*;
Expand All @@ -317,7 +306,8 @@ impl<'de> de::Deserialize<'de> for Checked<GenericComponentType> {

impl<'de> de::Deserialize<'de> for Checked<IndexComponentType> {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: de::Deserializer<'de>
where
D: de::Deserializer<'de>,
{
struct Visitor;
impl<'de> de::Visitor<'de> for Visitor {
Expand All @@ -328,7 +318,8 @@ impl<'de> de::Deserialize<'de> for Checked<IndexComponentType> {
}

fn visit_u64<E>(self, value: u64) -> Result<Self::Value, E>
where E: de::Error
where
E: de::Error,
{
use self::ComponentType::*;
use crate::validation::Checked::*;
Expand All @@ -346,7 +337,8 @@ impl<'de> de::Deserialize<'de> for Checked<IndexComponentType> {

impl<'de> de::Deserialize<'de> for Checked<Type> {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: de::Deserializer<'de>
where
D: de::Deserializer<'de>,
{
struct Visitor;
impl<'de> de::Visitor<'de> for Visitor {
Expand All @@ -357,7 +349,8 @@ impl<'de> de::Deserialize<'de> for Checked<Type> {
}

fn visit_str<E>(self, value: &str) -> Result<Self::Value, E>
where E: de::Error
where
E: de::Error,
{
use self::Type::*;
use crate::validation::Checked::*;
Expand All @@ -380,7 +373,7 @@ impl<'de> de::Deserialize<'de> for Checked<Type> {
impl ser::Serialize for Type {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: ser::Serializer
S: ser::Serializer,
{
serializer.serialize_str(match *self {
Type::Scalar => "SCALAR",
Expand Down Expand Up @@ -421,7 +414,7 @@ impl ComponentType {
impl ser::Serialize for ComponentType {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: ser::Serializer
S: ser::Serializer,
{
serializer.serialize_u32(self.as_gl_enum())
}
Expand Down
Loading

0 comments on commit 7fe2af0

Please sign in to comment.