Skip to content

Commit

Permalink
Merge pull request #322 from IcanDivideBy0/clippy
Browse files Browse the repository at this point in the history
Fix clippy warnings
  • Loading branch information
IcanDivideBy0 committed Jan 29, 2022
2 parents 7fe2af0 + d3d1589 commit 3437ee5
Show file tree
Hide file tree
Showing 34 changed files with 151 additions and 213 deletions.
1 change: 1 addition & 0 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ before_test:
test_script:
- cargo test --all --all-features --release
- cargo fmt --all -- --check
- cargo clippy --all-features
2 changes: 1 addition & 1 deletion examples/export/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ fn export(output: Output) {
align_to_multiple_of_four(&mut json_offset);
let glb = gltf::binary::Glb {
header: gltf::binary::Header {
magic: b"glTF".clone(),
magic: *b"glTF",
version: 2,
length: json_offset + buffer_length,
},
Expand Down
6 changes: 3 additions & 3 deletions gltf-json/src/accessor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub const UNSIGNED_INT: u32 = 5125;
pub const FLOAT: u32 = 5126;

/// All valid generic vertex attribute component types.
pub const VALID_COMPONENT_TYPES: &'static [u32] = &[
pub const VALID_COMPONENT_TYPES: &[u32] = &[
BYTE,
UNSIGNED_BYTE,
SHORT,
Expand All @@ -71,10 +71,10 @@ 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: &[u32] = &[UNSIGNED_BYTE, UNSIGNED_SHORT, UNSIGNED_INT];

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

/// Contains data structures for sparse storage.
Expand Down
5 changes: 2 additions & 3 deletions gltf-json/src/animation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ use serde_derive::{Deserialize, Serialize};
use std::fmt;

/// All valid animation interpolation algorithms.
pub const VALID_INTERPOLATIONS: &'static [&'static str] = &["LINEAR", "STEP", "CUBICSPLINE"];
pub const VALID_INTERPOLATIONS: &[&str] = &["LINEAR", "STEP", "CUBICSPLINE"];

/// All valid animation property names.
pub const VALID_PROPERTIES: &'static [&'static str] =
&["translation", "rotation", "scale", "weights"];
pub const VALID_PROPERTIES: &[&str] = &["translation", "rotation", "scale", "weights"];

/// Specifies an interpolation algorithm.
#[derive(Clone, Copy, Debug, Eq, PartialEq, Deserialize)]
Expand Down
2 changes: 1 addition & 1 deletion gltf-json/src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub const MIN_BYTE_STRIDE: u32 = 4;
pub const MAX_BYTE_STRIDE: u32 = 252;

/// All valid GPU buffer targets.
pub const VALID_TARGETS: &'static [u32] = &[ARRAY_BUFFER, ELEMENT_ARRAY_BUFFER];
pub const VALID_TARGETS: &[u32] = &[ARRAY_BUFFER, ELEMENT_ARRAY_BUFFER];

/// Specifies the target a GPU buffer should be bound to.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
Expand Down
2 changes: 1 addition & 1 deletion gltf-json/src/camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use serde_derive::{Deserialize, Serialize};
use std::fmt;

/// All valid camera types.
pub const VALID_CAMERA_TYPES: &'static [&'static str] = &["perspective", "orthographic"];
pub const VALID_CAMERA_TYPES: &[&str] = &["perspective", "orthographic"];

/// Specifies the camera type.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
Expand Down
4 changes: 2 additions & 2 deletions gltf-json/src/extensions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub mod texture;
pub use self::root::Root;

/// Names of glTF 2.0 extensions enabled by the user.
pub const ENABLED_EXTENSIONS: &'static [&'static str] = &[
pub const ENABLED_EXTENSIONS: &[&str] = &[
#[cfg(feature = "KHR_lights_punctual")]
"KHR_lights_punctual",
#[cfg(feature = "KHR_materials_pbrSpecularGlossiness")]
Expand All @@ -53,7 +53,7 @@ pub const ENABLED_EXTENSIONS: &'static [&'static str] = &[
];

/// Names of glTF 2.0 extensions supported by the library.
pub const SUPPORTED_EXTENSIONS: &'static [&'static str] = &[
pub const SUPPORTED_EXTENSIONS: &[&str] = &[
"KHR_lights_punctual",
"KHR_materials_pbrSpecularGlossiness",
"KHR_materials_unlit",
Expand Down
11 changes: 4 additions & 7 deletions gltf-json/src/extensions/scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub mod khr_lights_punctual {
use std::fmt;

/// All valid light types.
pub const VALID_TYPES: &'static [&'static str] = &["directional", "point", "spot"];
pub const VALID_TYPES: &[&str] = &["directional", "point", "spot"];

#[derive(Clone, Debug, Deserialize, Serialize, Validate)]
pub struct KhrLightsPunctual {
Expand Down Expand Up @@ -151,7 +151,7 @@ pub mod khr_lights_punctual {
}

fn outer_cone_angle_default() -> f32 {
0.7853981633974483
std::f32::consts::FRAC_PI_4
}

impl<'de> de::Deserialize<'de> for Checked<Type> {
Expand Down Expand Up @@ -201,12 +201,9 @@ pub mod khr_lights_punctual {

#[cfg(feature = "KHR_materials_variants")]
pub mod khr_materials_variants {
use crate::validation::{Checked, Error, Validate};
use crate::{Extras, Index, Path, Root};
use gltf_derive::Validate;
use serde::{de, ser};
use crate::validation::{Error, Validate};
use crate::{Path, Root};
use serde_derive::{Deserialize, Serialize};
use std::fmt;

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Variant {
Expand Down
2 changes: 1 addition & 1 deletion gltf-json/src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use gltf_derive::Validate;
use serde_derive::{Deserialize, Serialize};

/// All valid MIME types.
pub const VALID_MIME_TYPES: &'static [&'static str] = &["image/jpeg", "image/png"];
pub const VALID_MIME_TYPES: &[&str] = &["image/jpeg", "image/png"];

/// Image data used to create a texture.
#[derive(Clone, Debug, Deserialize, Serialize, Validate)]
Expand Down
2 changes: 1 addition & 1 deletion gltf-json/src/material.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use serde_derive::{Deserialize, Serialize};
use std::fmt;

/// All valid alpha modes.
pub const VALID_ALPHA_MODES: &'static [&'static str] = &["OPAQUE", "MASK", "BLEND"];
pub const VALID_ALPHA_MODES: &[&str] = &["OPAQUE", "MASK", "BLEND"];

/// The alpha rendering mode of a material.
#[derive(Clone, Copy, Eq, PartialEq, Debug)]
Expand Down
6 changes: 3 additions & 3 deletions gltf-json/src/mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub const TRIANGLE_STRIP: u32 = 5;
pub const TRIANGLE_FAN: u32 = 6;

/// All valid primitive rendering modes.
pub const VALID_MODES: &'static [u32] = &[
pub const VALID_MODES: &[u32] = &[
POINTS,
LINES,
LINE_LOOP,
Expand All @@ -40,7 +40,7 @@ pub const VALID_MODES: &'static [u32] = &[
];

/// All valid semantic names for Morph targets.
pub const VALID_MORPH_TARGETS: &'static [&'static str] = &["POSITION", "NORMAL", "TANGENT"];
pub const VALID_MORPH_TARGETS: &[&str] = &["POSITION", "NORMAL", "TANGENT"];

/// The type of primitives to render.
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq)]
Expand Down Expand Up @@ -308,7 +308,7 @@ impl Semantic {
"POSITION" => Valid(Positions),
"TANGENT" => Valid(Tangents),
#[cfg(feature = "extras")]
_ if s.starts_with("_") => Valid(Extras(s[1..].to_string())),
_ if s.starts_with('_') => Valid(Extras(s[1..].to_string())),
_ if s.starts_with("COLOR_") => match s["COLOR_".len()..].parse() {
Ok(set) => Valid(Colors(set)),
Err(_) => Invalid,
Expand Down
1 change: 1 addition & 0 deletions gltf-json/src/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ impl Root {
}

/// Deserialize from a JSON string slice.
#[allow(clippy::should_implement_trait)]
pub fn from_str(str_: &str) -> Result<Self, Error> {
serde_json::from_str(str_)
}
Expand Down
6 changes: 3 additions & 3 deletions gltf-json/src/texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ pub const MIRRORED_REPEAT: u32 = 33_648;
pub const REPEAT: u32 = 10_497;

/// All valid magnification filters.
pub const VALID_MAG_FILTERS: &'static [u32] = &[NEAREST, LINEAR];
pub const VALID_MAG_FILTERS: &[u32] = &[NEAREST, LINEAR];

/// All valid minification filters.
pub const VALID_MIN_FILTERS: &'static [u32] = &[
pub const VALID_MIN_FILTERS: &[u32] = &[
NEAREST,
LINEAR,
NEAREST_MIPMAP_NEAREST,
Expand All @@ -46,7 +46,7 @@ pub const VALID_MIN_FILTERS: &'static [u32] = &[
];

/// All valid wrapping modes.
pub const VALID_WRAPPING_MODES: &'static [u32] = &[CLAMP_TO_EDGE, MIRRORED_REPEAT, REPEAT];
pub const VALID_WRAPPING_MODES: &[u32] = &[CLAMP_TO_EDGE, MIRRORED_REPEAT, REPEAT];

/// Magnification filter.
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq)]
Expand Down
2 changes: 1 addition & 1 deletion src/accessor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ impl<'a> Accessor<'a> {
#[cfg(feature = "names")]
#[cfg_attr(docsrs, doc(cfg(feature = "names")))]
pub fn name(&self) -> Option<&'a str> {
self.json.name.as_ref().map(String::as_str)
self.json.name.as_deref()
}

/// Specifies whether integer data values should be normalized.
Expand Down
15 changes: 3 additions & 12 deletions src/accessor/sparse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ pub struct Indices<'a> {
impl<'a> Indices<'a> {
/// Constructs `sparse::Indices`.
pub(crate) fn new(document: &'a Document, json: &'a json::accessor::sparse::Indices) -> Self {
Self {
document: document,
json: json,
}
Self { document, json }
}

/// Returns the buffer view containing the sparse indices.
Expand Down Expand Up @@ -72,10 +69,7 @@ pub struct Sparse<'a> {
impl<'a> Sparse<'a> {
/// Constructs `Sparse`.
pub(crate) fn new(document: &'a Document, json: &'a json::accessor::sparse::Sparse) -> Self {
Self {
document: document,
json: json,
}
Self { document, json }
}

/// Returns the number of attributes encoded in this sparse accessor.
Expand Down Expand Up @@ -114,10 +108,7 @@ pub struct Values<'a> {
impl<'a> Values<'a> {
/// Constructs `sparse::Values`.
pub(crate) fn new(document: &'a Document, json: &'a json::accessor::sparse::Values) -> Self {
Self {
document: document,
json: json,
}
Self { document, json }
}

/// Returns the buffer view containing the sparse values.
Expand Down
30 changes: 13 additions & 17 deletions src/accessor/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ impl<'a, T: Item> Iterator for Iter<'a, T> {

fn next(&mut self) -> Option<Self::Item> {
match self {
&mut Iter::Standard(ref mut iter) => iter.next(),
&mut Iter::Sparse(ref mut iter) => iter.next(),
Iter::Standard(ref mut iter) => iter.next(),
Iter::Sparse(ref mut iter) => iter.next(),
}
}

fn nth(&mut self, nth: usize) -> Option<Self::Item> {
match self {
&mut Iter::Standard(ref mut iter) => iter.nth(nth),
&mut Iter::Sparse(ref mut iter) => iter.nth(nth),
Iter::Standard(ref mut iter) => iter.nth(nth),
Iter::Sparse(ref mut iter) => iter.nth(nth),
}
}

Expand All @@ -56,8 +56,8 @@ impl<'a, T: Item> Iterator for Iter<'a, T> {

fn size_hint(&self) -> (usize, Option<usize>) {
match self {
&Iter::Standard(ref iter) => iter.size_hint(),
&Iter::Sparse(ref iter) => iter.size_hint(),
Iter::Standard(ref iter) => iter.size_hint(),
Iter::Sparse(ref iter) => iter.size_hint(),
}
}
}
Expand Down Expand Up @@ -116,7 +116,7 @@ impl<'a, T: Item> SparseIter<'a, T> {
SparseIter {
base,
indices: indices.peekable(),
values: values,
values,
counter: 0,
}
}
Expand All @@ -125,17 +125,13 @@ impl<'a, T: Item> SparseIter<'a, T> {
impl<'a, T: Item> Iterator for SparseIter<'a, T> {
type Item = T;
fn next(&mut self) -> Option<Self::Item> {
let next_base_value = self
let mut next_value = self
.base
.as_mut()
.map(|iter| iter.next())
.unwrap_or(Some(T::zero()));
if next_base_value.is_none() {
return None;
}
.unwrap_or_else(|| Some(T::zero()))?;

let mut next_value = next_base_value.unwrap();
let next_sparse_index = self.indices.peek().clone();
let next_sparse_index = self.indices.peek();
if let Some(index) = next_sparse_index {
if *index == self.counter {
self.indices.next(); // advance
Expand Down Expand Up @@ -248,7 +244,7 @@ impl<T: Item + Copy> Item for [T; 3] {
assert!(slice.len() >= 3 * mem::size_of::<T>());
[
T::from_slice(slice),
T::from_slice(&slice[1 * mem::size_of::<T>()..]),
T::from_slice(&slice[mem::size_of::<T>()..]),
T::from_slice(&slice[2 * mem::size_of::<T>()..]),
]
}
Expand All @@ -262,7 +258,7 @@ impl<T: Item + Copy> Item for [T; 4] {
assert!(slice.len() >= 4 * mem::size_of::<T>());
[
T::from_slice(slice),
T::from_slice(&slice[1 * mem::size_of::<T>()..]),
T::from_slice(&slice[mem::size_of::<T>()..]),
T::from_slice(&slice[2 * mem::size_of::<T>()..]),
T::from_slice(&slice[3 * mem::size_of::<T>()..]),
]
Expand All @@ -277,7 +273,7 @@ impl<'a, T: Item> ItemIter<'a, T> {
pub fn new(slice: &'a [u8], stride: usize) -> Self {
ItemIter {
data: slice,
stride: stride,
stride,
_phantom: PhantomData,
}
}
Expand Down
23 changes: 7 additions & 16 deletions src/animation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ impl<'a> Animation<'a> {
json: &'a json::animation::Animation,
) -> Self {
Self {
document: document,
index: index,
json: json,
document,
index,
json,
}
}

Expand All @@ -97,7 +97,7 @@ impl<'a> Animation<'a> {
/// Optional user-defined name for this object.
#[cfg(feature = "names")]
pub fn name(&self) -> Option<&'a str> {
self.json.name.as_ref().map(String::as_str)
self.json.name.as_deref()
}

/// Returns an `Iterator` over the animation samplers.
Expand All @@ -115,10 +115,7 @@ impl<'a> Animation<'a> {
impl<'a> Channel<'a> {
/// Constructs a `Channel`.
pub(crate) fn new(anim: Animation<'a>, json: &'a json::animation::Channel) -> Self {
Self {
anim: anim,
json: json,
}
Self { anim, json }
}

/// Returns the parent `Animation` struct.
Expand Down Expand Up @@ -159,10 +156,7 @@ impl<'a> Channel<'a> {
impl<'a> Target<'a> {
/// Constructs a `Target`.
pub(crate) fn new(anim: Animation<'a>, json: &'a json::animation::Target) -> Self {
Self {
anim: anim,
json: json,
}
Self { anim, json }
}

/// Returns the parent `Animation` struct.
Expand Down Expand Up @@ -194,10 +188,7 @@ impl<'a> Target<'a> {
impl<'a> Sampler<'a> {
/// Constructs a `Sampler`.
pub(crate) fn new(anim: Animation<'a>, json: &'a json::animation::Sampler) -> Self {
Self {
anim: anim,
json: json,
}
Self { anim, json }
}

/// Returns the parent `Animation` struct.
Expand Down
Loading

0 comments on commit 3437ee5

Please sign in to comment.