use trait upcasting and remove as_any for ResourceData

- bumped msrv to 1.86
This commit is contained in:
Dmitry Stepanov
2025-04-06 18:56:17 +03:00
parent 6d2874b8d5
commit 10a4dc048b
23 changed files with 32 additions and 35 deletions
+1 -1
View File
@@ -4,7 +4,7 @@ version = "0.36.2"
license = "MIT"
authors = ["Dmitry Stepanov <[email protected]>"]
edition = "2021"
rust-version = "1.80"
rust-version = "1.86"
description = "A standalone scene editor for Fyrox game engine"
homepage = "https://github.com/FyroxEngine/Fyrox"
keywords = ["fyrox", "editor", "rust"]
+1 -1
View File
@@ -4,7 +4,7 @@ license = "MIT"
version = "0.36.2"
authors = ["Dmitry Stepanov <[email protected]>"]
edition = "2021"
rust-version = "1.80"
rust-version = "1.86"
description = "A scene editor for Fyrox game engine"
homepage = "https://github.com/FyroxEngine/Fyrox"
keywords = ["fyrox", "editor", "rust"]
+1 -1
View File
@@ -12,7 +12,7 @@ homepage = "https://fyrox.rs"
documentation = "https://docs.rs/fyrox-animation"
repository = "https://github.com/FyroxEngine/Fyrox"
readme = "README.md"
rust-version = "1.80"
rust-version = "1.86"
[dependencies]
fyrox-core = { version = "0.36.2", path = "../fyrox-core" }
+1 -1
View File
@@ -4,7 +4,7 @@ license = "MIT"
version = "0.36.0"
authors = ["Dmitry Stepanov <[email protected]>", "Brendan Guild <[email protected]>"]
edition = "2021"
rust-version = "1.80"
rust-version = "1.86"
description = "An autotiler for Fyrox game engine"
homepage = "https://github.com/FyroxEngine/Fyrox"
keywords = ["tilemap", "autotile", "wave function collapse"]
+1 -1
View File
@@ -10,7 +10,7 @@ include = ["/src/**/*", "/Cargo.toml", "/LICENSE", "/README.md"]
homepage = "https://fyrox.rs"
documentation = "https://docs.rs/fyrox-build-tools"
repository = "https://github.com/FyroxEngine/Fyrox"
rust-version = "1.80"
rust-version = "1.86"
[dependencies]
fyrox-core = { path = "../fyrox-core", version = "0.36.2" }
+1 -1
View File
@@ -8,7 +8,7 @@ description = "Proc-macro for the Visit trait"
repository = "https://github.com/FyroxEngine/Fyrox"
include = ["/src/**/*", "/Cargo.toml", "/README.md"]
readme = "README.md"
rust-version = "1.80"
rust-version = "1.86"
[lib]
proc-macro = true
+1 -1
View File
@@ -12,7 +12,7 @@ homepage = "https://fyrox.rs"
documentation = "https://docs.rs/fyrox-core"
repository = "https://github.com/FyroxEngine/Fyrox"
readme = "README.md"
rust-version = "1.80"
rust-version = "1.86"
[dependencies]
fyrox-core-derive = { path = "../fyrox-core-derive", version = "0.36.2" }
+1 -1
View File
@@ -12,7 +12,7 @@ homepage = "https://fyrox.rs"
documentation = "https://docs.rs/fyrox-dylib"
repository = "https://github.com/FyroxEngine/Fyrox"
readme = "README.md"
rust-version = "1.80"
rust-version = "1.86"
[lib]
crate-type = ["dylib"]
+1 -1
View File
@@ -11,7 +11,7 @@ include = ["/src/**/*", "/Cargo.toml", "/LICENSE"]
homepage = "https://fyrox.rs"
documentation = "https://docs.rs/fyrox-graph"
repository = "https://github.com/FyroxEngine/Fyrox"
rust-version = "1.80"
rust-version = "1.86"
[dependencies]
fyrox-core = { path = "../fyrox-core", version = "0.36.2" }
+1 -1
View File
@@ -10,7 +10,7 @@ include = ["/src/**/*", "/Cargo.toml", "/LICENSE", "/README.md"]
homepage = "https://fyrox.rs"
documentation = "https://docs.rs/fyrox-ui"
repository = "https://github.com/FyroxEngine/Fyrox"
rust-version = "1.80"
rust-version = "1.86"
[dependencies]
fyrox-core = { path = "../fyrox-core", version = "0.36.2", features = ["serde"] }
+1 -1
View File
@@ -12,7 +12,7 @@ homepage = "https://fyrox.rs"
documentation = "https://docs.rs/fyrox"
repository = "https://github.com/FyroxEngine/Fyrox"
readme = "README.md"
rust-version = "1.80"
rust-version = "1.86"
[dependencies]
fyrox-core-derive = { path = "../fyrox-core-derive", version = "0.36.2" }
+2 -2
View File
@@ -47,8 +47,8 @@ use crate::{
resource::texture::TextureResource,
};
use fxhash::FxHashMap;
use fyrox_resource::ResourceDataAsAny;
use lazy_static::lazy_static;
use std::any::Any;
use std::{
error::Error,
fmt::{Display, Formatter},
@@ -1241,7 +1241,7 @@ impl MaterialResourceExtension for MaterialResource {
ResourceState::Ok { ref data, .. } => MaterialResource::new_ok(
Uuid::new_v4(),
kind,
ResourceDataAsAny::as_any(&**data)
(&**data as &dyn Any)
.downcast_ref::<Material>()
.unwrap()
.clone(),
+1 -1
View File
@@ -11,7 +11,7 @@ include = ["/src/**/*", "/Cargo.toml", "/LICENSE"]
homepage = "https://fyrox.rs"
documentation = "https://docs.rs/fyrox-math"
repository = "https://github.com/FyroxEngine/Fyrox"
rust-version = "1.80"
rust-version = "1.86"
[dependencies]
rectutils = "0.3.0"
+1 -1
View File
@@ -11,7 +11,7 @@ include = ["/src/**/*", "/Cargo.toml", "/LICENSE"]
homepage = "https://fyrox.rs"
documentation = "https://docs.rs/fyrox-resource"
repository = "https://github.com/FyroxEngine/Fyrox"
rust-version = "1.80"
rust-version = "1.86"
[dependencies]
fyrox-core = { path = "../fyrox-core", version = "0.36.2", features = ["serde"] }
+9 -12
View File
@@ -38,7 +38,8 @@ use crate::{
};
use fxhash::FxHashSet;
pub use fyrox_core as core;
use fyrox_core::{combine_uuids, define_as_any_trait, log::Log};
use fyrox_core::{combine_uuids, log::Log};
use std::any::Any;
use std::path::PathBuf;
use std::{
error::Error,
@@ -76,10 +77,8 @@ pub const SHADER_RESOURCE_UUID: Uuid = uuid!("f1346417-b726-492a-b80f-c02096c6c0
/// Type UUID of curve resource. It is defined here to load old versions of resources.
pub const CURVE_RESOURCE_UUID: Uuid = uuid!("f28b949f-28a2-4b68-9089-59c234f58b6b");
define_as_any_trait!(ResourceDataAsAny => ResourceData);
/// A trait for resource data.
pub trait ResourceData: ResourceDataAsAny + Debug + Visit + Send + Reflect {
pub trait ResourceData: Debug + Visit + Send + Reflect {
/// Returns unique data type id.
fn type_uuid(&self) -> Uuid;
@@ -129,7 +128,7 @@ where
pub fn data(&mut self) -> Option<&mut T> {
if let ResourceState::Ok { ref mut data, .. } = self.guard.state {
ResourceDataAsAny::as_any_mut(&mut **data).downcast_mut::<T>()
(&mut **data as &mut dyn Any).downcast_mut::<T>()
} else {
None
}
@@ -137,7 +136,7 @@ where
pub fn data_ref(&self) -> Option<&T> {
if let ResourceState::Ok { ref data, .. } = self.guard.state {
ResourceDataAsAny::as_any(&**data).downcast_ref::<T>()
(&**data as &dyn Any).downcast_ref::<T>()
} else {
None
}
@@ -468,7 +467,7 @@ where
#[inline]
pub fn as_loaded_ref(&self) -> Option<&T> {
match self.guard.state {
ResourceState::Ok { ref data, .. } => ResourceDataAsAny::as_any(&**data).downcast_ref(),
ResourceState::Ok { ref data, .. } => (&**data as &dyn Any).downcast_ref(),
_ => None,
}
}
@@ -476,9 +475,7 @@ where
#[inline]
pub fn as_loaded_mut(&mut self) -> Option<&mut T> {
match self.guard.state {
ResourceState::Ok { ref mut data, .. } => {
ResourceDataAsAny::as_any_mut(&mut **data).downcast_mut()
}
ResourceState::Ok { ref mut data, .. } => (&mut **data as &mut dyn Any).downcast_mut(),
_ => None,
}
}
@@ -529,7 +526,7 @@ where
self.guard.kind
)
}
ResourceState::Ok { ref data, .. } => ResourceDataAsAny::as_any(&**data)
ResourceState::Ok { ref data, .. } => (&**data as &dyn Any)
.downcast_ref()
.expect("Type mismatch!"),
}
@@ -555,7 +552,7 @@ where
header.kind
)
}
ResourceState::Ok { ref mut data, .. } => ResourceDataAsAny::as_any_mut(&mut **data)
ResourceState::Ok { ref mut data, .. } => (&mut **data as &mut dyn Any)
.downcast_mut()
.expect("Type mismatch!"),
}
+1 -1
View File
@@ -11,7 +11,7 @@ include = ["/src/**/*", "/Cargo.toml", "/LICENSE"]
homepage = "https://fyrox.rs"
documentation = "https://docs.rs/fyrox-scripts"
repository = "https://github.com/FyroxEngine/Fyrox"
rust-version = "1.80"
rust-version = "1.86"
[dependencies]
fyrox = { version = "0.36.2", path = "../fyrox" }
+1 -1
View File
@@ -12,7 +12,7 @@ homepage = "https://fyrox.rs"
documentation = "https://docs.rs/fyrox-sound"
repository = "https://github.com/FyroxEngine/Fyrox"
readme = "README.md"
rust-version = "1.80"
rust-version = "1.86"
[dependencies]
fyrox-core = { path = "../fyrox-core", version = "0.36.2" }
+1 -1
View File
@@ -10,7 +10,7 @@ include = ["/src/**/*", "/Cargo.toml", "/LICENSE", "/README.md"]
homepage = "https://fyrox.rs"
documentation = "https://docs.rs/fyrox-texture"
repository = "https://github.com/FyroxEngine/Fyrox"
rust-version = "1.80"
rust-version = "1.86"
[dependencies]
fyrox-core = { path = "../fyrox-core", version = "0.36.2" }
+1 -1
View File
@@ -12,7 +12,7 @@ homepage = "https://fyrox.rs"
documentation = "https://docs.rs/fyrox-ui"
repository = "https://github.com/FyroxEngine/Fyrox"
readme = "README.md"
rust-version = "1.80"
rust-version = "1.86"
[dependencies]
fyrox-core = { path = "../fyrox-core", version = "0.36.2", features = ["serde"] }
+1 -1
View File
@@ -12,7 +12,7 @@ homepage = "https://fyrox.rs"
documentation = "https://docs.rs/fyrox"
repository = "https://github.com/FyroxEngine/Fyrox"
readme = "README.md"
rust-version = "1.80"
rust-version = "1.86"
[features]
default = ["fyrox-impl"]
+1 -1
View File
@@ -10,7 +10,7 @@ categories = ["game-development"]
include = ["/src/**/*", "/Cargo.toml", "/LICENSE", "/README.md", "/resources/**/*"]
homepage = "https://fyrox.rs"
repository = "https://github.com/FyroxEngine/Fyrox"
rust-version = "1.80"
rust-version = "1.86"
[dependencies]
fyrox = { version = "0.36.2", path = "../fyrox" }
+1 -1
View File
@@ -11,7 +11,7 @@ include = ["/src/**/*", "/Cargo.toml", "/LICENSE", "/README.md", "engine.version
homepage = "https://fyrox.rs"
repository = "https://github.com/FyroxEngine/Fyrox"
readme = "README.md"
rust-version = "1.80"
rust-version = "1.86"
[dependencies]
uuid = { version = "1", features = ["v4"] }
+1 -1
View File
@@ -11,7 +11,7 @@ include = ["/src/**/*", "/Cargo.toml", "/LICENSE", "/README.md"]
homepage = "https://fyrox.rs"
repository = "https://github.com/FyroxEngine/Fyrox"
readme = "README.md"
rust-version = "1.80"
rust-version = "1.86"
[dependencies]
fyrox-template-core = { version = "0.36.2", path = "../template-core" }