Skip to content

Instantly share code, notes, and snippets.

@Shatur
Last active April 9, 2023 11:12
Show Gist options
  • Select an option

  • Save Shatur/cfe4ac9f4125f5704720006ad433c404 to your computer and use it in GitHub Desktop.

Select an option

Save Shatur/cfe4ac9f4125f5704720006ad433c404 to your computer and use it in GitHub Desktop.
use std::any::Any;
use anyhow::Result;
use bevy::{
prelude::*,
reflect::{ReflectMut, ReflectOwned, ReflectRef, TypeInfo},
};
struct BoxedReflect(Box<dyn Reflect>);
impl Reflect for BoxedReflect {
fn type_name(&self) -> &str {
self.0.type_name()
}
fn get_type_info(&self) -> &'static TypeInfo {
self.0.get_type_info()
}
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
}
fn into_reflect(self: Box<Self>) -> Box<dyn Reflect> {
self.0
}
fn as_reflect(&self) -> &dyn Reflect {
&*self.0
}
fn as_reflect_mut(&mut self) -> &mut dyn Reflect {
&mut *self.0
}
fn apply(&mut self, value: &dyn Reflect) {
self.0.apply(value)
}
fn set(&mut self, value: Box<dyn Reflect>) -> Result<(), Box<dyn Reflect>> {
self.0.set(value)
}
fn reflect_ref(&self) -> ReflectRef {
self.0.reflect_ref()
}
fn reflect_mut(&mut self) -> ReflectMut {
self.0.reflect_mut()
}
fn reflect_owned(self: Box<Self>) -> ReflectOwned {
self.0.reflect_owned()
}
fn clone_value(&self) -> Box<dyn Reflect> {
self.0.clone_value()
}
}
impl FromReflect for BoxedReflect {
fn from_reflect(reflect: &dyn Reflect) -> Option<Self> {
Some(Self(reflect.clone_value()))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment