removed lots of redundant as_any + as_any_mut impls

- replaced them with `Downcast` trait
This commit is contained in:
Dmitry Stepanov
2025-01-12 23:00:18 +03:00
parent 9c01455545
commit 1993a758d1
32 changed files with 95 additions and 415 deletions
+3 -30
View File
@@ -24,7 +24,7 @@ use crate::{
algebra::{Vector2, Vector3},
pool::Handle,
uuid::Uuid,
TypeUuidProvider,
Downcast, TypeUuidProvider,
},
gui::{
border::BorderBuilder,
@@ -33,6 +33,7 @@ use crate::{
image::ImageBuilder,
key::HotKey,
message::{KeyCode, UiMessage},
style::{resource::StyleResourceExt, Style},
utils::make_simple_tooltip,
widget::WidgetBuilder,
BuildContext, Thickness, UiNode,
@@ -45,9 +46,6 @@ use crate::{
settings::Settings,
Engine, Message,
};
use fyrox::gui::style::resource::StyleResourceExt;
use fyrox::gui::style::Style;
use std::any::Any;
pub mod gizmo;
pub mod move_mode;
@@ -58,32 +56,7 @@ pub mod scale_mode;
pub mod select_mode;
pub mod terrain;
pub trait BaseInteractionMode: 'static {
fn as_any(&self) -> &dyn Any;
fn as_any_mut(&mut self) -> &mut dyn Any;
fn into_any(self: Box<Self>) -> Box<dyn Any>;
}
impl<T> BaseInteractionMode for T
where
T: 'static,
{
fn as_any(&self) -> &dyn Any {
self
}
fn as_any_mut(&mut self) -> &mut dyn Any {
self
}
fn into_any(self: Box<Self>) -> Box<dyn Any> {
self
}
}
pub trait InteractionMode: BaseInteractionMode {
pub trait InteractionMode: Downcast {
fn on_left_mouse_button_down(
&mut self,
editor_selection: &Selection,
+5 -18
View File
@@ -18,23 +18,10 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
use crate::fyrox::gui::message::UiMessage;
use crate::{Editor, Message};
use std::any::Any;
pub trait BaseEditorPlugin: Any {
fn as_any(&self) -> &dyn Any;
fn as_any_mut(&mut self) -> &mut dyn Any;
}
impl<T: EditorPlugin> BaseEditorPlugin for T {
fn as_any(&self) -> &dyn Any {
self
}
fn as_any_mut(&mut self) -> &mut dyn Any {
self
}
}
use crate::{
fyrox::{core::Downcast, gui::message::UiMessage},
Editor, Message,
};
/// Editor plugin allows you to extend editor functionality with custom tools. It provides a standard way of interaction
/// between your plugin and built-in editor's functionality.
@@ -55,7 +42,7 @@ impl<T: EditorPlugin> BaseEditorPlugin for T {
/// The editor usually operates on scenes (there could be multiple opened scenes, but only one active) and any modification of
/// their content **must** be done via _commands_. [Command](https://en.wikipedia.org/wiki/Command_pattern) is a standard
/// pattern that encapsulates an action. Command pattern is used for undo/redo functionality.
pub trait EditorPlugin: BaseEditorPlugin {
pub trait EditorPlugin: Downcast {
/// This method is called right after the editor was fully initialized. It is guaranteed to be called only once.
fn on_start(&mut self, #[allow(unused_variables)] editor: &mut Editor) {}
+14 -18
View File
@@ -18,30 +18,26 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
use crate::command::{Command, CommandStack};
use crate::fyrox::{
core::{algebra::Vector2, math::Rect, pool::Handle, reflect::Reflect},
engine::Engine,
gui::{
inspector::PropertyChanged,
message::{KeyCode, MouseButton},
UiNode,
},
resource::texture::TextureResource,
scene::SceneContainer,
};
use crate::{
command::{Command, CommandStack},
fyrox::{
core::{algebra::Vector2, math::Rect, pool::Handle, reflect::Reflect, Downcast},
engine::Engine,
gui::{
inspector::PropertyChanged,
message::{KeyCode, MouseButton},
UiNode,
},
resource::texture::TextureResource,
scene::SceneContainer,
},
scene::Selection,
settings::{keys::KeyBindings, Settings},
Message,
};
use std::{any::Any, path::Path};
pub trait SceneController: 'static {
fn as_any(&self) -> &dyn Any;
fn as_any_mut(&mut self) -> &mut dyn Any;
use std::path::Path;
pub trait SceneController: Downcast {
fn on_key_up(&mut self, key: KeyCode, engine: &mut Engine, key_bindings: &KeyBindings) -> bool;
fn on_key_down(
+2 -20
View File
@@ -99,9 +99,9 @@ use crate::{
Message, Settings,
};
use fyrox::asset::untyped::ResourceKind;
use fyrox::core::Downcast;
use fyrox::graph::SceneGraphNode;
use std::{
any::Any,
cell::RefCell,
fmt::Debug,
fs::File,
@@ -479,14 +479,6 @@ impl GameScene {
}
impl SceneController for GameScene {
fn as_any(&self) -> &dyn Any {
self
}
fn as_any_mut(&mut self) -> &mut dyn Any {
self
}
#[must_use]
fn on_key_up(
&mut self,
@@ -1297,10 +1289,8 @@ impl SceneController for GameScene {
}
}
pub trait BaseSelectionContainer: Debug + 'static {
pub trait BaseSelectionContainer: Downcast + Debug {
fn clone_boxed(&self) -> Box<dyn SelectionContainer>;
fn as_any(&self) -> &dyn Any;
fn as_any_mut(&mut self) -> &mut dyn Any;
fn eq_ref(&self, other: &dyn SelectionContainer) -> bool;
}
@@ -1312,14 +1302,6 @@ where
Box::new(self.clone())
}
fn as_any(&self) -> &dyn Any {
self
}
fn as_any_mut(&mut self) -> &mut dyn Any {
self
}
fn eq_ref(&self, other: &dyn SelectionContainer) -> bool {
if let Some(other) = other.downcast_ref::<T>() {
self == other
+33 -40
View File
@@ -25,41 +25,42 @@ pub mod menu;
pub mod selection;
pub mod utils;
use crate::fyrox::{
core::{
algebra::{Vector2, Vector3},
color::Color,
futures::executor::block_on,
log::Log,
make_relative_path,
math::Rect,
pool::{ErasedHandle, Handle},
reflect::Reflect,
},
engine::Engine,
fxhash::FxHashSet,
graph::SceneGraph,
graph::{BaseSceneGraph, SceneGraphNode},
gui::{
absm::AnimationBlendingStateMachine,
animation::AnimationPlayer,
brush::Brush,
draw::{CommandTexture, Draw},
inspector::PropertyChanged,
message::{KeyCode, MessageDirection, MouseButton},
UiNode, UiUpdateSwitches, UserInterface, UserInterfaceResourceExtension,
},
renderer::framework::gpu_texture::PixelKind,
resource::texture::{TextureKind, TextureResource, TextureResourceExtension},
scene::SceneContainer,
};
use crate::plugins::absm::{command::fetch_machine, selection::SelectedEntity};
use crate::plugins::animation::{self, command::fetch_animations_container};
use crate::plugins::inspector::editors::handle::HandlePropertyEditorMessage;
use crate::{
asset::item::AssetItem,
command::{make_command, Command, CommandGroup, CommandStack},
fyrox::{
core::{
algebra::{Vector2, Vector3},
color::Color,
futures::executor::block_on,
log::Log,
make_relative_path,
math::Rect,
pool::{ErasedHandle, Handle},
reflect::Reflect,
},
engine::Engine,
fxhash::FxHashSet,
graph::{BaseSceneGraph, SceneGraph, SceneGraphNode},
gui::{
absm::AnimationBlendingStateMachine,
animation::AnimationPlayer,
brush::Brush,
draw::{CommandTexture, Draw},
inspector::PropertyChanged,
message::{KeyCode, MessageDirection, MouseButton},
UiNode, UiUpdateSwitches, UserInterface, UserInterfaceResourceExtension,
},
renderer::framework::gpu_texture::PixelKind,
resource::texture::{TextureKind, TextureResource, TextureResourceExtension},
scene::SceneContainer,
},
message::MessageSender,
plugins::{
absm::{command::fetch_machine, selection::SelectedEntity},
animation::{self, command::fetch_animations_container},
inspector::editors::handle::HandlePropertyEditorMessage,
},
scene::{
commands::ChangeSelectionCommand, controller::SceneController, selector::HierarchyNode,
Selection,
@@ -74,7 +75,7 @@ use crate::{
},
Message,
};
use std::{any::Any, fs::File, io::Write, path::Path};
use std::{fs::File, io::Write, path::Path};
pub struct PreviewInstance {
pub instance: Handle<UiNode>,
@@ -116,14 +117,6 @@ impl UiScene {
}
impl SceneController for UiScene {
fn as_any(&self) -> &dyn Any {
self
}
fn as_any_mut(&mut self) -> &mut dyn Any {
self
}
fn on_key_up(
&mut self,
_key: KeyCode,
-9
View File
@@ -40,7 +40,6 @@ use crate::{
use fxhash::FxHashMap;
use fyrox_resource::{Resource, ResourceData};
use std::{
any::Any,
collections::VecDeque,
error::Error,
fmt::Debug,
@@ -124,14 +123,6 @@ impl Visit for AnimationTracksData {
}
impl ResourceData for AnimationTracksData {
fn as_any(&self) -> &dyn Any {
self
}
fn as_any_mut(&mut self) -> &mut dyn Any {
self
}
fn type_uuid(&self) -> Uuid {
<AnimationTracksData as TypeUuidProvider>::type_uuid()
}
+6
View File
@@ -504,6 +504,8 @@ pub trait Downcast: Any {
/// Converts self reference as a reference to [`Any`]. Could be used to downcast a trait object
/// to a particular type.
fn as_any_mut(&mut self) -> &mut dyn Any;
fn into_any(self: Box<Self>) -> Box<dyn Any>;
}
impl<T: Any> Downcast for T {
@@ -514,6 +516,10 @@ impl<T: Any> Downcast for T {
fn as_any_mut(&mut self) -> &mut dyn Any {
self
}
fn into_any(self: Box<Self>) -> Box<dyn Any> {
self
}
}
#[cfg(test)]
-9
View File
@@ -1403,7 +1403,6 @@ mod test {
};
use fyrox_resource::{Resource, ResourceData};
use std::{
any::Any,
error::Error,
ops::{Deref, DerefMut, Index, IndexMut},
path::Path,
@@ -1499,14 +1498,6 @@ mod test {
}
impl ResourceData for Graph {
fn as_any(&self) -> &dyn Any {
self
}
fn as_any_mut(&mut self) -> &mut dyn Any {
self
}
fn type_uuid(&self) -> Uuid {
<Graph as TypeUuidProvider>::type_uuid()
}
+2 -10
View File
@@ -47,9 +47,9 @@ use crate::{
resource::texture::TextureResource,
};
use fxhash::FxHashMap;
use fyrox_core::Downcast;
use lazy_static::lazy_static;
use std::{
any::Any,
error::Error,
fmt::{Display, Formatter},
path::Path,
@@ -636,14 +636,6 @@ impl TypeUuidProvider for Material {
}
impl ResourceData for Material {
fn as_any(&self) -> &dyn Any {
self
}
fn as_any_mut(&mut self) -> &mut dyn Any {
self
}
fn type_uuid(&self) -> Uuid {
<Self as TypeUuidProvider>::type_uuid()
}
@@ -1121,7 +1113,7 @@ impl MaterialResourceExtension for MaterialResource {
}
ResourceState::Ok(ref material) => MaterialResource::new_ok(
kind,
ResourceData::as_any(&**material)
Downcast::as_any(&**material)
.downcast_ref::<Material>()
.unwrap()
.clone(),
-9
View File
@@ -458,7 +458,6 @@ pub use fyrox_graphics::gpu_program::{
use ron::ser::PrettyConfig;
use serde::{Deserialize, Serialize};
use std::{
any::Any,
error::Error,
fmt::{Display, Formatter},
fs::File,
@@ -736,14 +735,6 @@ impl Shader {
}
impl ResourceData for Shader {
fn as_any(&self) -> &dyn Any {
self
}
fn as_any_mut(&mut self) -> &mut dyn Any {
self
}
fn type_uuid(&self) -> Uuid {
<Self as TypeUuidProvider>::type_uuid()
}
+4 -26
View File
@@ -30,6 +30,7 @@ use crate::{
pool::Handle,
reflect::Reflect,
visitor::{Visit, VisitError},
Downcast,
},
engine::{
task::TaskPoolHandler, AsyncSceneLoader, GraphicsContext, PerformanceStatistics,
@@ -43,7 +44,6 @@ use crate::{
scene::{Scene, SceneContainer},
};
use std::{
any::Any,
ops::{Deref, DerefMut},
path::Path,
sync::Arc,
@@ -187,37 +187,15 @@ pub struct PluginContext<'a, 'b> {
pub task_pool: &'a mut TaskPoolHandler,
}
/// Base plugin automatically implements type casting for plugins.
pub trait BasePlugin: Any + 'static {
/// Returns a reference to Any trait. It is used for type casting.
fn as_any(&self) -> &dyn Any;
/// Returns a reference to Any trait. It is used for type casting.
fn as_any_mut(&mut self) -> &mut dyn Any;
}
impl<T> BasePlugin for T
where
T: Any + Plugin + 'static,
{
fn as_any(&self) -> &dyn Any {
self
}
fn as_any_mut(&mut self) -> &mut dyn Any {
self
}
}
impl dyn Plugin {
/// Performs downcasting to a particular type.
pub fn cast<T: Plugin>(&self) -> Option<&T> {
BasePlugin::as_any(self).downcast_ref::<T>()
Downcast::as_any(self).downcast_ref::<T>()
}
/// Performs downcasting to a particular type.
pub fn cast_mut<T: Plugin>(&mut self) -> Option<&mut T> {
BasePlugin::as_any_mut(self).downcast_mut::<T>()
Downcast::as_any_mut(self).downcast_mut::<T>()
}
}
@@ -267,7 +245,7 @@ impl dyn Plugin {
/// }
/// }
/// ```
pub trait Plugin: BasePlugin + Visit + Reflect {
pub trait Plugin: Downcast + Visit + Reflect {
/// The method is called when the plugin constructor was just registered in the engine. The main
/// use of this method is to register scripts and custom scene graph nodes in [`SerializationContext`].
fn register(&self, #[allow(unused_variables)] context: PluginRegistrationContext) {}
-9
View File
@@ -29,7 +29,6 @@ use crate::{
};
use std::error::Error;
use std::{
any::Any,
fmt::{Display, Formatter},
path::Path,
};
@@ -82,14 +81,6 @@ pub struct CurveResourceState {
}
impl ResourceData for CurveResourceState {
fn as_any(&self) -> &dyn Any {
self
}
fn as_any_mut(&mut self) -> &mut dyn Any {
self
}
fn type_uuid(&self) -> Uuid {
<Self as TypeUuidProvider>::type_uuid()
}
-9
View File
@@ -69,7 +69,6 @@ use fyrox_core::math;
use fyrox_ui::{UiNode, UserInterface};
use serde::{Deserialize, Serialize};
use std::{
any::Any,
error::Error,
fmt::{Display, Formatter},
path::{Path, PathBuf},
@@ -598,14 +597,6 @@ impl ModelResourceExtension for ModelResource {
}
impl ResourceData for Model {
fn as_any(&self) -> &dyn Any {
self
}
fn as_any_mut(&mut self) -> &mut dyn Any {
self
}
fn type_uuid(&self) -> Uuid {
<Self as TypeUuidProvider>::type_uuid()
}
-9
View File
@@ -63,7 +63,6 @@ use fyrox_resource::manager::BuiltInResource;
use half::f16;
use lazy_static::lazy_static;
use std::{
any::Any,
error::Error,
hash::Hasher,
path::{Path, PathBuf},
@@ -238,14 +237,6 @@ pub struct SurfaceData {
}
impl ResourceData for SurfaceData {
fn as_any(&self) -> &dyn Any {
self
}
fn as_any_mut(&mut self) -> &mut dyn Any {
self
}
fn type_uuid(&self) -> Uuid {
<SurfaceData as fyrox_core::TypeUuidProvider>::type_uuid()
}
-9
View File
@@ -46,7 +46,6 @@ use crate::{
scene::debug::SceneDrawingContext,
};
use std::{
any::Any,
error::Error,
fmt::{Display, Formatter},
path::{Path, PathBuf},
@@ -401,14 +400,6 @@ impl TileMapBrush {
}
impl ResourceData for TileMapBrush {
fn as_any(&self) -> &dyn Any {
self
}
fn as_any_mut(&mut self) -> &mut dyn Any {
self
}
fn type_uuid(&self) -> Uuid {
<Self as TypeUuidProvider>::type_uuid()
}
@@ -34,7 +34,6 @@ use crate::{
},
};
use std::{
any::Any,
error::Error,
fmt::{Debug, Display, Formatter},
num::{ParseFloatError, ParseIntError},
@@ -179,14 +178,6 @@ pub struct CustomTileCollider {
}
impl ResourceData for CustomTileCollider {
fn as_any(&self) -> &dyn Any {
self
}
fn as_any_mut(&mut self) -> &mut dyn Any {
self
}
fn type_uuid(&self) -> Uuid {
<Self as TypeUuidProvider>::type_uuid()
}
-9
View File
@@ -45,7 +45,6 @@ use crate::{
resource::texture::TextureResource,
};
use std::{
any::Any,
collections::hash_map::{Entry, Keys},
error::Error,
fmt::{Display, Formatter},
@@ -1925,14 +1924,6 @@ impl TileSet {
}
impl ResourceData for TileSet {
fn as_any(&self) -> &dyn Any {
self
}
fn as_any_mut(&mut self) -> &mut dyn Any {
self
}
fn type_uuid(&self) -> Uuid {
<Self as TypeUuidProvider>::type_uuid()
}
-8
View File
@@ -116,14 +116,6 @@ mod test {
struct Stub {}
impl ResourceData for Stub {
fn as_any(&self) -> &dyn std::any::Any {
self
}
fn as_any_mut(&mut self) -> &mut dyn std::any::Any {
self
}
fn type_uuid(&self) -> Uuid {
Uuid::default()
}
+8 -15
View File
@@ -38,7 +38,6 @@ use crate::{
};
use fxhash::FxHashSet;
use std::{
any::Any,
error::Error,
fmt::{Debug, Formatter},
future::Future,
@@ -53,8 +52,8 @@ use std::{
use crate::state::LoadError;
use crate::untyped::{ResourceHeader, ResourceKind};
pub use fyrox_core as core;
use fyrox_core::combine_uuids;
use fyrox_core::log::Log;
use fyrox_core::{combine_uuids, Downcast};
pub mod constructor;
pub mod entry;
@@ -79,13 +78,7 @@ pub const SHADER_RESOURCE_UUID: Uuid = uuid!("f1346417-b726-492a-b80f-c02096c6c0
pub const CURVE_RESOURCE_UUID: Uuid = uuid!("f28b949f-28a2-4b68-9089-59c234f58b6b");
/// A trait for resource data.
pub trait ResourceData: 'static + Debug + Visit + Send + Reflect {
/// Returns `self` as `&dyn Any`. It is useful to implement downcasting to a particular type.
fn as_any(&self) -> &dyn Any;
/// Returns `self` as `&mut dyn Any`. It is useful to implement downcasting to a particular type.
fn as_any_mut(&mut self) -> &mut dyn Any;
pub trait ResourceData: Downcast + Debug + Visit + Send + Reflect {
/// Returns unique data type id.
fn type_uuid(&self) -> Uuid;
@@ -135,7 +128,7 @@ where
pub fn data(&mut self) -> Option<&mut T> {
if let ResourceState::Ok(ref mut data) = self.guard.state {
ResourceData::as_any_mut(&mut **data).downcast_mut::<T>()
Downcast::as_any_mut(&mut **data).downcast_mut::<T>()
} else {
None
}
@@ -143,7 +136,7 @@ where
pub fn data_ref(&self) -> Option<&T> {
if let ResourceState::Ok(ref data) = self.guard.state {
ResourceData::as_any(&**data).downcast_ref::<T>()
Downcast::as_any(&**data).downcast_ref::<T>()
} else {
None
}
@@ -457,7 +450,7 @@ where
#[inline]
pub fn as_loaded_ref(&self) -> Option<&T> {
match self.guard.state {
ResourceState::Ok(ref data) => ResourceData::as_any(&**data).downcast_ref(),
ResourceState::Ok(ref data) => Downcast::as_any(&**data).downcast_ref(),
_ => None,
}
}
@@ -465,7 +458,7 @@ where
#[inline]
pub fn as_loaded_mut(&mut self) -> Option<&mut T> {
match self.guard.state {
ResourceState::Ok(ref mut data) => ResourceData::as_any_mut(&mut **data).downcast_mut(),
ResourceState::Ok(ref mut data) => Downcast::as_any_mut(&mut **data).downcast_mut(),
_ => None,
}
}
@@ -516,7 +509,7 @@ where
self.guard.kind
)
}
ResourceState::Ok(ref data) => ResourceData::as_any(&**data)
ResourceState::Ok(ref data) => Downcast::as_any(&**data)
.downcast_ref()
.expect("Type mismatch!"),
}
@@ -542,7 +535,7 @@ where
header.kind
)
}
ResourceState::Ok(ref mut data) => ResourceData::as_any_mut(&mut **data)
ResourceState::Ok(ref mut data) => Downcast::as_any_mut(&mut **data)
.downcast_mut()
.expect("Type mismatch!"),
}
+5 -33
View File
@@ -23,49 +23,21 @@
use crate::{
core::uuid::Uuid, io::ResourceIo, options::BaseImportOptions, state::LoadError, ResourceData,
};
use std::{any::Any, future::Future, path::PathBuf, pin::Pin, sync::Arc};
use fyrox_core::Downcast;
use std::{future::Future, path::PathBuf, pin::Pin, sync::Arc};
#[cfg(target_arch = "wasm32")]
#[doc(hidden)]
pub trait BaseResourceLoader: 'static {}
pub trait BaseResourceLoader: Downcast {}
#[cfg(not(target_arch = "wasm32"))]
#[doc(hidden)]
pub trait BaseResourceLoader: Send + 'static {}
pub trait BaseResourceLoader: Send + Downcast {}
impl<T> BaseResourceLoader for T where T: ResourceLoader {}
/// A simple type-casting trait that has auto-impl.
pub trait ResourceLoaderTypeTrait: BaseResourceLoader {
/// Converts `self` into boxed `Any`.
fn into_any(self: Box<Self>) -> Box<dyn Any>;
/// Returns `self` as `&dyn Any`. It is useful for downcasting to a particular type.
fn as_any(&self) -> &dyn Any;
/// Returns `self` as `&mut dyn Any`. It is useful for downcasting to a particular type.
fn as_any_mut(&mut self) -> &mut dyn Any;
}
impl<T> ResourceLoaderTypeTrait for T
where
T: ResourceLoader,
{
fn into_any(self: Box<Self>) -> Box<dyn Any> {
self
}
fn as_any(&self) -> &dyn Any {
self
}
fn as_any_mut(&mut self) -> &mut dyn Any {
self
}
}
/// Trait for resource loading.
pub trait ResourceLoader: ResourceLoaderTypeTrait {
pub trait ResourceLoader: BaseResourceLoader {
/// Returns a list of file extensions supported by the loader. Resource manager will use this list
/// to pick the correct resource loader when the user requests a resource.
fn extensions(&self) -> &[&str];
-8
View File
@@ -884,14 +884,6 @@ mod test {
}
impl ResourceData for Stub {
fn as_any(&self) -> &dyn std::any::Any {
unimplemented!()
}
fn as_any_mut(&mut self) -> &mut dyn std::any::Any {
unimplemented!()
}
fn type_uuid(&self) -> Uuid {
<Self as TypeUuidProvider>::type_uuid()
}
+3 -14
View File
@@ -24,20 +24,17 @@ use crate::{
core::{append_extension, log::Log, reflect::Reflect},
io::ResourceIo,
};
use fyrox_core::Downcast;
use ron::ser::PrettyConfig;
use serde::{de::DeserializeOwned, Serialize};
use std::{any::Any, fs::File, path::Path};
use std::{fs::File, path::Path};
/// Extension of import options file.
pub const OPTIONS_EXTENSION: &str = "options";
/// Base type-agnostic trait for resource import options. This trait has automatic implementation
/// for everything that implements [`ImportOptions`] trait.
pub trait BaseImportOptions: Reflect {
/// Returns self as any and used for downcasting to a particular type.
fn as_any(&self) -> &dyn Any;
/// Returns self as any and used for downcasting to a particular type.
fn as_any_mut(&mut self) -> &mut dyn Any;
pub trait BaseImportOptions: Downcast + Reflect {
/// Saves the options to a file at the given path.
fn save(&self, path: &Path) -> bool;
}
@@ -61,14 +58,6 @@ impl<T> BaseImportOptions for T
where
T: ImportOptions,
{
fn as_any(&self) -> &dyn Any {
self
}
fn as_any_mut(&mut self) -> &mut dyn Any {
self
}
fn save(&self, path: &Path) -> bool {
self.save_internal(path)
}
-8
View File
@@ -220,14 +220,6 @@ mod test {
struct Stub {}
impl ResourceData for Stub {
fn as_any(&self) -> &dyn std::any::Any {
self
}
fn as_any_mut(&mut self) -> &mut dyn std::any::Any {
self
}
fn type_uuid(&self) -> Uuid {
Uuid::default()
}
-8
View File
@@ -528,14 +528,6 @@ mod test {
struct Stub {}
impl ResourceData for Stub {
fn as_any(&self) -> &dyn std::any::Any {
self
}
fn as_any_mut(&mut self) -> &mut dyn std::any::Any {
self
}
fn type_uuid(&self) -> Uuid {
Uuid::default()
}
-9
View File
@@ -41,7 +41,6 @@ use fyrox_resource::{
};
use std::error::Error;
use std::{
any::Any,
fmt::Debug,
io::{Cursor, Read, Seek, SeekFrom},
ops::{Deref, DerefMut},
@@ -286,14 +285,6 @@ impl DerefMut for SoundBuffer {
}
impl ResourceData for SoundBuffer {
fn as_any(&self) -> &dyn Any {
self
}
fn as_any_mut(&mut self) -> &mut dyn Any {
self
}
fn type_uuid(&self) -> Uuid {
SOUND_BUFFER_RESOURCE_UUID
}
+1 -9
View File
@@ -95,7 +95,7 @@ use fyrox_resource::{
use hrtf::HrirSphere;
use std::error::Error;
use std::path::Path;
use std::{any::Any, fmt::Debug, fmt::Formatter, path::PathBuf, sync::Arc};
use std::{fmt::Debug, fmt::Formatter, path::PathBuf, sync::Arc};
/// See module docs.
#[derive(Clone, Debug, Default, Reflect)]
@@ -222,14 +222,6 @@ impl TypeUuidProvider for HrirSphereResourceData {
}
impl ResourceData for HrirSphereResourceData {
fn as_any(&self) -> &dyn Any {
self
}
fn as_any_mut(&mut self) -> &mut dyn Any {
self
}
fn type_uuid(&self) -> Uuid {
<Self as TypeUuidProvider>::type_uuid()
}
-9
View File
@@ -64,7 +64,6 @@ use image::{ColorType, DynamicImage, ImageError, ImageFormat, Pixel};
use lazy_static::lazy_static;
use serde::{Deserialize, Serialize};
use std::{
any::Any,
fmt::{Debug, Display, Formatter},
hash::{Hash, Hasher},
io::Cursor,
@@ -294,14 +293,6 @@ impl TypeUuidProvider for Texture {
}
impl ResourceData for Texture {
fn as_any(&self) -> &dyn Any {
self
}
fn as_any_mut(&mut self) -> &mut dyn Any {
self
}
fn type_uuid(&self) -> Uuid {
<Self as TypeUuidProvider>::type_uuid()
}
+2 -16
View File
@@ -20,12 +20,12 @@
use crate::{
core::{algebra::Vector2, pool::Handle, reflect::Reflect, uuid::Uuid, visitor::Visit},
core::{ComponentProvider, Downcast, TypeUuidProvider},
draw::DrawingContext,
message::{OsEvent, UiMessage},
widget::Widget,
UiNode, UserInterface,
};
use fyrox_core::{ComponentProvider, TypeUuidProvider};
use std::{
any::Any,
ops::{Deref, DerefMut},
@@ -35,13 +35,7 @@ use std::{
/// Base trait for all UI widgets. It has auto-impl and you don't need to implement it manually. Your widget
/// must implement [`Clone`] and [`Control`] traits for impl to be generated for you, also your widget must
/// not contain any references (due to `'static` lifetime requirement).
pub trait BaseControl: Send + 'static {
/// Returns `self` as `&dyn Any`.
fn as_any(&self) -> &dyn Any;
/// Returns `self` as `&mut dyn Any`.
fn as_any_mut(&mut self) -> &mut dyn Any;
pub trait BaseControl: Send + Downcast {
/// Returns the exact copy of the widget in "type-erased" form.
fn clone_boxed(&self) -> Box<dyn Control>;
@@ -59,14 +53,6 @@ impl<T> BaseControl for T
where
T: Any + Clone + 'static + Control + TypeUuidProvider,
{
fn as_any(&self) -> &dyn Any {
self
}
fn as_any_mut(&mut self) -> &mut dyn Any {
self
}
fn clone_boxed(&self) -> Box<dyn Control> {
Box::new(self.clone())
}
-9
View File
@@ -32,7 +32,6 @@ use fyrox_resource::{
};
use lazy_static::lazy_static;
use std::{
any::Any,
error::Error,
fmt::{Debug, Formatter},
hash::{Hash, Hasher},
@@ -220,14 +219,6 @@ pub struct Font {
uuid_provider!(Font = "692fec79-103a-483c-bb0b-9fc3a349cb48");
impl ResourceData for Font {
fn as_any(&self) -> &dyn Any {
self
}
fn as_any_mut(&mut self) -> &mut dyn Any {
self
}
fn type_uuid(&self) -> Uuid {
<Self as TypeUuidProvider>::type_uuid()
}
+2 -12
View File
@@ -300,15 +300,13 @@ use fyrox_resource::{
ResourceData,
};
use serde::{Deserialize, Serialize};
use std::any::TypeId;
use std::ops::{Deref, Index, IndexMut};
use std::{
any::Any,
any::TypeId,
cell::{Ref, RefCell, RefMut},
collections::{btree_set::BTreeSet, hash_map::Entry, VecDeque},
error::Error,
fmt::{Debug, Formatter},
ops::DerefMut,
ops::{Deref, DerefMut, Index, IndexMut},
path::Path,
sync::{
mpsc::{self, Receiver, Sender, TryRecvError},
@@ -3457,14 +3455,6 @@ fn transform_size(transform_space_bounds: Vector2<f32>, matrix: &Matrix3<f32>) -
uuid_provider!(UserInterface = "0d065c93-ef9c-4dd2-9fe7-e2b33c1a21b6");
impl ResourceData for UserInterface {
fn as_any(&self) -> &dyn Any {
self
}
fn as_any_mut(&mut self) -> &mut dyn Any {
self
}
fn type_uuid(&self) -> Uuid {
<Self as TypeUuidProvider>::type_uuid()
}
+5 -5
View File
@@ -23,10 +23,10 @@
use crate::{
core::{
pool::Handle, reflect::prelude::*, uuid_provider, variable, visitor::prelude::*,
ComponentProvider, NameProvider,
ComponentProvider, Downcast, NameProvider,
},
widget::Widget,
BaseControl, Control, UserInterface,
Control, UserInterface,
};
use fyrox_graph::SceneGraphNode;
use fyrox_resource::{untyped::UntypedResource, Resource};
@@ -209,7 +209,7 @@ impl UiNode {
where
T: Control,
{
BaseControl::as_any(&*self.0).downcast_ref::<T>()
Downcast::as_any(&*self.0).downcast_ref::<T>()
}
/// Tries to perform **direct** downcasting to a particular widget type. It is just a simple wrapper
@@ -218,7 +218,7 @@ impl UiNode {
where
T: Control,
{
BaseControl::as_any_mut(&mut *self.0).downcast_mut::<T>()
Downcast::as_any_mut(&mut *self.0).downcast_mut::<T>()
}
/// Tries to fetch a component of the given type `T`. At very basis it mimics [`Self::cast`] behaviour, but
@@ -302,7 +302,7 @@ impl Reflect for UiNode {
}
fn into_any(self: Box<Self>) -> Box<dyn Any> {
self.0.into_any()
Reflect::into_any(self.0)
}
fn as_any(&self, func: &mut dyn FnMut(&dyn Any)) {
-9
View File
@@ -35,7 +35,6 @@ use fyrox_resource::{
Resource, ResourceData,
};
use std::{
any::Any,
error::Error,
fmt::{Display, Formatter},
path::{Path, PathBuf},
@@ -81,14 +80,6 @@ impl From<VisitError> for StyleResourceError {
}
impl ResourceData for Style {
fn as_any(&self) -> &dyn Any {
self
}
fn as_any_mut(&mut self) -> &mut dyn Any {
self
}
fn type_uuid(&self) -> Uuid {
<Self as TypeUuidProvider>::type_uuid()
}