diff --git a/fyrox-animation/src/container.rs b/fyrox-animation/src/container.rs index 477ad55b7..6638b0fb3 100644 --- a/fyrox-animation/src/container.rs +++ b/fyrox-animation/src/container.rs @@ -36,6 +36,7 @@ use fyrox_core::algebra::{Quaternion, UnitQuaternion}; /// The kind of track output value, the animation system works only with numeric properties and the number /// of variants is small. #[derive(Clone, Copy, Debug, Visit, Reflect, PartialEq, Eq)] +#[derive(Default)] pub enum TrackValueKind { /// A real number. Requires only 1 parametric curve. Real, @@ -44,6 +45,7 @@ pub enum TrackValueKind { Vector2, /// A 3-dimensional vector of real values. Requires 3 parametric curves, where `X = 0`, `Y = 1`, `Z = 2`. + #[default] Vector3, /// A 4-dimensional vector of real values. Requires 4 parametric curves, where `X = 0`, `Y = 1`, `Z = 2`, `W = 3`. @@ -77,11 +79,6 @@ impl TrackValueKind { } } -impl Default for TrackValueKind { - fn default() -> Self { - Self::Vector3 - } -} /// Interpolation mode for track data. #[derive(Visit, Reflect, Debug, Clone, Default, PartialEq)] diff --git a/fyrox-animation/src/spritesheet/mod.rs b/fyrox-animation/src/spritesheet/mod.rs index 06544828a..82ace71ea 100644 --- a/fyrox-animation/src/spritesheet/mod.rs +++ b/fyrox-animation/src/spritesheet/mod.rs @@ -47,12 +47,14 @@ impl SpriteSheetTexture for T {} /// Animation playback status. #[derive(Visit, Reflect, Copy, Clone, Eq, PartialEq, Debug, AsRefStr, EnumString, VariantNames)] +#[derive(Default)] pub enum Status { /// Animation is playing. Playing, /// Animation is stopped. Stopped animation is guaranteed to be either at beginning or at end frames (depending on speed). /// When an animation is stopped manually via ([`SpriteSheetAnimation::stop()`], the animation will be rewound to beginning. + #[default] Stopped, /// Animation is paused. Playback can be resumed by [`SpriteSheetAnimation::play()`]. @@ -61,11 +63,6 @@ pub enum Status { uuid_provider!(Status = "74a31122-a7a8-476c-ab87-77e53cf0523c"); -impl Default for Status { - fn default() -> Self { - Self::Stopped - } -} /// Some animation event. #[derive(Visit, Reflect, Clone, Debug, Eq, PartialEq)] diff --git a/fyrox-animation/src/value.rs b/fyrox-animation/src/value.rs index 9f075a8a6..d9f8a17f0 100644 --- a/fyrox-animation/src/value.rs +++ b/fyrox-animation/src/value.rs @@ -39,10 +39,12 @@ use std::{ /// An actual type of a property value. #[derive(Visit, Reflect, Clone, Copy, Debug, PartialEq, Eq, Hash)] +#[derive(Default)] pub enum ValueType { /// `bool` Bool, /// `f32` + #[default] F32, /// `f64` F64, @@ -192,11 +194,6 @@ impl ValueType { } } -impl Default for ValueType { - fn default() -> Self { - Self::F32 - } -} /// A real value that can be produced by an animation track. Animations always operate on real numbers (`f32`) for any kind /// of machine numeric types (including `bool`). This is needed to be able to blend values; final blending result is then diff --git a/fyrox-autotile/src/auto.rs b/fyrox-autotile/src/auto.rs index 01c628b0d..2c1c1af2c 100644 --- a/fyrox-autotile/src/auto.rs +++ b/fyrox-autotile/src/auto.rs @@ -249,10 +249,12 @@ impl Deref for HashConstraintMap { /// The ways in which a cell's choice of tile can be constrained. #[derive(Debug, Clone)] +#[derive(Default)] pub enum TileConstraint { /// No constraint. This means that the cell is outside of the area of consideration /// for the autotiler, such as beyond the edge of the world. Cells with this constraint /// put no limits on what may be adjacent in any direction. + #[default] None, /// A terrain is a set of possible patterns. Any pattern within the terrain may be chosen /// to be the pattern for this cell. @@ -262,11 +264,6 @@ pub enum TileConstraint { Pattern(P), } -impl Default for TileConstraint { - fn default() -> Self { - Self::None - } -} impl Default for &TileConstraint { fn default() -> Self { diff --git a/fyrox-core-derive/tests/it/visit/basic.rs b/fyrox-core-derive/tests/it/visit/basic.rs index 15617bd2b..44ef6a412 100644 --- a/fyrox-core-derive/tests/it/visit/basic.rs +++ b/fyrox-core-derive/tests/it/visit/basic.rs @@ -50,20 +50,14 @@ struct Generics { } // NOTE: This enum doesn't implement copy, but `#[derive(Visit)]` still works -#[derive(Debug, Clone, PartialEq, Eq, Hash, Visit)] +#[derive(Debug, Clone, PartialEq, Eq, Hash, Visit, Default)] enum PlainEnum { + #[default] A, B, C, } -// NOTE: implementing default for `PlainEnum` is REQUIRED to derive `Visit` for `OnefTheTypes` -impl Default for PlainEnum { - fn default() -> Self { - Self::A - } -} - #[derive(Debug, Clone, PartialEq, Visit)] enum OneOfTheTypes { NamedFields(NamedFields), diff --git a/fyrox-core/src/visitor/mod.rs b/fyrox-core/src/visitor/mod.rs index e5f567519..2681c817d 100644 --- a/fyrox-core/src/visitor/mod.rs +++ b/fyrox-core/src/visitor/mod.rs @@ -872,19 +872,14 @@ mod test { } #[allow(dead_code)] - #[derive(Visit, PartialEq, Debug)] + #[derive(Visit, PartialEq, Debug, Default)] pub enum ResourceKind { + #[default] Unknown, Model(Model), Texture(Texture), } - impl Default for ResourceKind { - fn default() -> Self { - Self::Unknown - } - } - #[derive(Visit, PartialEq, Debug)] struct Resource { kind: ResourceKind, diff --git a/fyrox-impl/src/resource/model/mod.rs b/fyrox-impl/src/resource/model/mod.rs index 1d8c1e79b..5cddbef81 100644 --- a/fyrox-impl/src/resource/model/mod.rs +++ b/fyrox-impl/src/resource/model/mod.rs @@ -669,6 +669,7 @@ impl Default for Model { EnumString, VariantNames, )] +#[derive(Default)] pub enum MaterialSearchOptions { /// Search in specified materials directory. It is suitable for cases when /// your model resource use shared textures. @@ -684,6 +685,7 @@ pub enum MaterialSearchOptions { /// # Platform specific /// /// Works on every platform. + #[default] RecursiveUp, /// Global search starting from working directory. Slowest option with a lot of ambiguities - @@ -707,11 +709,6 @@ pub enum MaterialSearchOptions { uuid_provider!(MaterialSearchOptions = "11634aa0-cf8f-4532-a8cd-c0fa6ef804f1"); -impl Default for MaterialSearchOptions { - fn default() -> Self { - Self::RecursiveUp - } -} impl MaterialSearchOptions { /// A helper to create MaterialsDirectory variant. diff --git a/fyrox-impl/src/scene/mesh/buffer.rs b/fyrox-impl/src/scene/mesh/buffer.rs index 7322a3720..0ac4167b6 100644 --- a/fyrox-impl/src/scene/mesh/buffer.rs +++ b/fyrox-impl/src/scene/mesh/buffer.rs @@ -57,8 +57,10 @@ pub trait VertexTrait: Copy + 'static { /// Data type for a vertex attribute component. #[derive(Reflect, Copy, Clone, PartialOrd, PartialEq, Eq, Ord, Hash, Visit, Debug)] #[repr(u8)] +#[derive(Default)] pub enum VertexAttributeDataType { /// 32-bit floating-point. + #[default] F32, /// 32-bit unsigned integer. U32, @@ -68,11 +70,6 @@ pub enum VertexAttributeDataType { U8, } -impl Default for VertexAttributeDataType { - fn default() -> Self { - Self::F32 - } -} impl VertexAttributeDataType { /// Returns size of data in bytes. @@ -89,8 +86,10 @@ impl VertexAttributeDataType { /// room for any custom data - it may be fit into `TexCoordN` attributes. #[derive(Reflect, Copy, Clone, PartialOrd, PartialEq, Eq, Ord, Hash, Visit, Debug)] #[repr(u32)] +#[derive(Default)] pub enum VertexAttributeUsage { /// Vertex position. Usually `Vector2` or `Vector3`. + #[default] Position = 0, /// Vertex normal. Usually `Vector3`, more rare `Vector3` (F16). Normal = 1, @@ -139,11 +138,6 @@ pub enum VertexAttributeUsage { Count, } -impl Default for VertexAttributeUsage { - fn default() -> Self { - Self::Position - } -} /// Input vertex attribute descriptor used to construct layouts and feed vertex buffer. #[derive(Debug, Hash)] diff --git a/fyrox-impl/src/scene/rigidbody.rs b/fyrox-impl/src/scene/rigidbody.rs index dd1a11c76..6d7fd9448 100644 --- a/fyrox-impl/src/scene/rigidbody.rs +++ b/fyrox-impl/src/scene/rigidbody.rs @@ -67,8 +67,10 @@ use strum_macros::{AsRefStr, EnumString, VariantNames}; Copy, Clone, Debug, Reflect, Visit, PartialEq, Eq, Hash, AsRefStr, EnumString, VariantNames, )] #[repr(u32)] +#[derive(Default)] pub enum RigidBodyType { /// Dynamic rigid bodies can be affected by external forces. + #[default] Dynamic = 0, /// Static rigid bodies cannot be affected by external forces. Static = 1, @@ -82,11 +84,6 @@ pub enum RigidBodyType { uuid_provider!(RigidBodyType = "562d2907-1b41-483a-8ca2-12eebaff7f5d"); -impl Default for RigidBodyType { - fn default() -> Self { - Self::Dynamic - } -} impl From for RigidBodyType { fn from(s: dynamics::RigidBodyType) -> Self { diff --git a/fyrox-impl/src/utils/behavior/composite.rs b/fyrox-impl/src/utils/behavior/composite.rs index 2d488925a..035fcdf34 100644 --- a/fyrox-impl/src/utils/behavior/composite.rs +++ b/fyrox-impl/src/utils/behavior/composite.rs @@ -32,10 +32,12 @@ use crate::{ /// Defines exact behavior of the composite node. #[derive(Debug, PartialEq, Visit, Eq, Clone)] +#[derive(Default)] pub enum CompositeNodeKind { /// `Sequence` node will execute children nodes consecutively /// until `Status::Failure` is returned from any descendant node. In other words `Sequence` /// implement AND logical function. + #[default] Sequence, /// `Selector` node will execute children until `Status::Success` /// is returned from any descendant node. In other worlds `Selector` implement OR logical @@ -43,11 +45,6 @@ pub enum CompositeNodeKind { Selector, } -impl Default for CompositeNodeKind { - fn default() -> Self { - Self::Sequence - } -} /// See module docs. #[derive(Debug, PartialEq, Visit, Eq, Clone)] diff --git a/fyrox-impl/src/utils/behavior/mod.rs b/fyrox-impl/src/utils/behavior/mod.rs index a1af2365f..a4cfd8796 100644 --- a/fyrox-impl/src/utils/behavior/mod.rs +++ b/fyrox-impl/src/utils/behavior/mod.rs @@ -95,12 +95,13 @@ where } /// Possible variations of behavior nodes. -#[derive(Debug, PartialEq, Visit, Eq, Clone)] +#[derive(Debug, PartialEq, Visit, Eq, Clone, Default)] pub enum BehaviorNode where B: Clone, { #[doc(hidden)] + #[default] Unknown, /// Root node of the tree. Root(RootNode), @@ -113,15 +114,6 @@ where Inverter(Inverter), } -impl Default for BehaviorNode -where - B: Clone, -{ - fn default() -> Self { - Self::Unknown - } -} - /// See module docs. #[derive(Debug, PartialEq, Visit, Clone)] pub struct BehaviorTree @@ -388,8 +380,9 @@ mod test { } } - #[derive(Debug, PartialEq, Visit, Clone)] + #[derive(Debug, PartialEq, Visit, Clone, Default)] enum BotBehavior { + #[default] None, Walk(WalkAction), OpenDoor(OpenDoorAction), @@ -397,12 +390,6 @@ mod test { CloseDoor(CloseDoorAction), } - impl Default for BotBehavior { - fn default() -> Self { - Self::None - } - } - #[derive(Default, Visit)] struct Environment { // > 0 - door in front of diff --git a/fyrox-sound/src/buffer/streaming.rs b/fyrox-sound/src/buffer/streaming.rs index c55adf8b5..64ce0d6e3 100644 --- a/fyrox-sound/src/buffer/streaming.rs +++ b/fyrox-sound/src/buffer/streaming.rs @@ -75,17 +75,14 @@ pub struct StreamingBuffer { } #[derive(Debug)] +#[derive(Default)] enum StreamingSource { + #[default] Null, Decoder(Decoder), Raw(Box), } -impl Default for StreamingSource { - fn default() -> Self { - Self::Null - } -} impl StreamingSource { #[inline] diff --git a/fyrox-sound/src/context.rs b/fyrox-sound/src/context.rs index 34e40f290..965bc6b86 100644 --- a/fyrox-sound/src/context.rs +++ b/fyrox-sound/src/context.rs @@ -57,6 +57,7 @@ pub const SAMPLE_RATE: u32 = 44100; /// Distance model defines how volume of sound will decay when distance to listener changes. #[derive(Copy, Clone, Debug, Eq, PartialEq, Reflect, Visit, AsRefStr, EnumString, VariantNames)] #[repr(u32)] +#[derive(Default)] pub enum DistanceModel { /// No distance attenuation at all. None = 0, @@ -73,6 +74,7 @@ pub enum DistanceModel { /// # Notes /// /// This is default distance model of context. + #[default] InverseDistance = 1, /// Distance will decay using following formula: @@ -101,11 +103,6 @@ pub enum DistanceModel { uuid_provider!(DistanceModel = "957f3b00-3f89-438c-b1b7-e841e8d75ba9"); -impl Default for DistanceModel { - fn default() -> Self { - Self::InverseDistance - } -} /// See module docs. #[derive(Clone, Default, Debug, Visit)] diff --git a/fyrox-sound/src/renderer/mod.rs b/fyrox-sound/src/renderer/mod.rs index 4d1f85d24..aed7b644e 100644 --- a/fyrox-sound/src/renderer/mod.rs +++ b/fyrox-sound/src/renderer/mod.rs @@ -46,8 +46,10 @@ pub mod hrtf; // can be only one at a time on context. #[allow(clippy::large_enum_variant)] #[derive(Debug, Clone, AsRefStr, EnumString, VariantNames, Visit, Reflect)] +#[derive(Default)] pub enum Renderer { /// Stateless default renderer. + #[default] Default, /// Can be used *only* with mono sounds, stereo sounds will be rendered through @@ -57,11 +59,6 @@ pub enum Renderer { uuid_provider!(Renderer = "13bf8432-987a-4216-b6aa-f5c0e8914a31"); -impl Default for Renderer { - fn default() -> Self { - Self::Default - } -} fn render_with_params( source: &mut SoundSource, diff --git a/fyrox-texture/src/lib.rs b/fyrox-texture/src/lib.rs index ad3826845..4bc4a7dac 100644 --- a/fyrox-texture/src/lib.rs +++ b/fyrox-texture/src/lib.rs @@ -875,6 +875,7 @@ impl TextureResourceExtension for TextureResource { Eq, )] #[repr(u32)] +#[derive(Default)] pub enum TextureMagnificationFilter { /// Returns the value of the texture element that is nearest to the center of the pixel /// being textured. @@ -882,16 +883,12 @@ pub enum TextureMagnificationFilter { /// Returns the weighted average of the four texture elements that are closest to the /// center of the pixel being textured. + #[default] Linear = 1, } uuid_provider!(TextureMagnificationFilter = "824f5b6c-8957-42db-9ebc-ef2a5dece5ab"); -impl Default for TextureMagnificationFilter { - fn default() -> Self { - Self::Linear - } -} /// The texture minifying function is used whenever the pixel being textured maps to an area /// greater than one texture element. @@ -912,6 +909,7 @@ impl Default for TextureMagnificationFilter { Eq, )] #[repr(u32)] +#[derive(Default)] pub enum TextureMinificationFilter { /// Returns the value of the texture element that is nearest to the center of the pixel /// being textured. @@ -941,6 +939,7 @@ pub enum TextureMinificationFilter { /// and uses the Linear criterion (a weighted average of the four texture elements that /// are closest to the center of the pixel) to produce a texture value from each mipmap. /// The final texture value is a weighted average of those two values. + #[default] LinearMipMapLinear = 5, } @@ -959,11 +958,6 @@ impl TextureMinificationFilter { } } -impl Default for TextureMinificationFilter { - fn default() -> Self { - Self::LinearMipMapLinear - } -} /// Defines a law of texture coordinate modification. #[derive( @@ -983,9 +977,11 @@ impl Default for TextureMinificationFilter { Eq, )] #[repr(u32)] +#[derive(Default)] pub enum TextureWrapMode { /// Causes the integer part of a coordinate to be ignored; GPU uses only the fractional part, /// thereby creating a repeating pattern. + #[default] Repeat = 0, /// Causes a coordinates to be clamped to the range range, where N is the size of the texture @@ -1009,11 +1005,6 @@ pub enum TextureWrapMode { uuid_provider!(TextureWrapMode = "e360d139-4374-4323-a66d-d192809d9d87"); -impl Default for TextureWrapMode { - fn default() -> Self { - Self::Repeat - } -} /// Texture kind defines pixel format of texture. #[derive(Copy, Clone, PartialEq, Eq, Debug, Reflect)] @@ -1264,8 +1255,10 @@ fn ceil_div_4(x: u32) -> u32 { AsRefStr, )] #[repr(u32)] +#[derive(Default)] pub enum CompressionOptions { /// An image will be stored without compression if it is not already compressed. + #[default] NoCompression = 0, /// An image will be encoded via DXT1 (BC1) compression with low quality if is not @@ -1285,11 +1278,6 @@ pub enum CompressionOptions { uuid_provider!(CompressionOptions = "fbdcc081-d0b8-4b62-9925-2de6c013fbf5"); -impl Default for CompressionOptions { - fn default() -> Self { - Self::NoCompression - } -} fn transmute_slice(bytes: &[u8]) -> &'_ [T] { // SAFETY: This is absolutely safe because `image` crate's Rgb8/Rgba8/etc. and `tbc`s Rgb8/Rgba8/etc. diff --git a/fyrox-ui/src/file_browser/mod.rs b/fyrox-ui/src/file_browser/mod.rs index 1ff233545..88640255a 100644 --- a/fyrox-ui/src/file_browser/mod.rs +++ b/fyrox-ui/src/file_browser/mod.rs @@ -654,7 +654,7 @@ fn make_fs_watcher_event_path_relative_to_tree_root( ) -> PathBuf { match root { Some(ref root) => { - let remove_prefix = if *root == PathBuf::from(".") { + let remove_prefix = if root == Path::new(".") { std::env::current_dir().unwrap() } else { root.clone()