removed ReflectBase trait + use trait upcasting instead

This commit is contained in:
Dmitry Stepanov
2026-05-05 00:29:44 +03:00
parent 225e8f9c47
commit aae761a27e
2 changed files with 6 additions and 26 deletions
+1 -19
View File
@@ -226,24 +226,6 @@ impl PartialEq<Self> for FieldMut<'_, '_> {
}
}
pub trait ReflectBase: Any + Debug {
fn as_any_raw(&self) -> &dyn Any;
fn as_any_raw_mut(&mut self) -> &mut dyn Any;
}
impl<T> ReflectBase for T
where
T: Reflect,
{
fn as_any_raw(&self) -> &dyn Any {
self
}
fn as_any_raw_mut(&mut self) -> &mut dyn Any {
self
}
}
/// A trait for runtime reflection.
///
/// ## Code Generation
@@ -299,7 +281,7 @@ where
/// to string. `Display` isn't used here, because it can't be derived and it is very tedious to implement it
/// for every type that should support `Reflect` trait. It is a good compromise between development speed
/// and the quality of the string output.
pub trait Reflect: ReflectBase {
pub trait Reflect: Any + Debug {
fn source_path() -> &'static str
where
Self: Sized;
+5 -7
View File
@@ -555,7 +555,7 @@ where
) -> Result<Option<Box<dyn Reflect>>, InheritError> {
let mut result: Result<Option<Box<dyn Reflect>>, InheritError> = Ok(None);
match parent.inner_value_ref().as_any_raw().downcast_ref::<T>() {
match (parent.inner_value_ref() as &dyn Any).downcast_ref::<T>() {
Some(parent_value) => {
if !self.is_modified() {
let mut parent_value_clone = parent_value.clone();
@@ -807,14 +807,14 @@ pub fn mark_inheritable_properties_modified(object: &mut dyn Reflect, ignored_ty
#[cfg(test)]
mod test {
use std::cell::RefCell;
use std::{cell::Cell, ops::DerefMut};
use crate::{
reflect::{prelude::*, ReflectInheritableVariable},
variable::{try_inherit_properties, InheritableVariable, VariableFlags},
visitor::{Visit, Visitor},
};
use std::any::Any;
use std::cell::RefCell;
use std::{cell::Cell, ops::DerefMut};
#[derive(Reflect, Clone, Debug, PartialEq)]
struct Foo {
@@ -1216,9 +1216,7 @@ mod test {
fn inheritable_variable_ref_cell() {
let v = InheritableVariable::new_modified(RefCell::new(123u32));
assert_eq!(
v.inner_value_ref()
.as_any_raw()
.downcast_ref::<RefCell<u32>>(),
(v.inner_value_ref() as &dyn Any).downcast_ref::<RefCell<u32>>(),
Some(&RefCell::new(123u32))
);
}