Use std::any::type_name

This commit is contained in:
timfish
2019-09-30 18:57:21 +01:00
parent 20d30d93c3
commit 53bb0a38f0
3 changed files with 38 additions and 37 deletions

View File

@@ -1,9 +1,11 @@
use std::any::{Any as StdAny, TypeId};
use std::any::{type_name, Any as StdAny, TypeId};
use std::fmt;
pub trait Any: StdAny {
fn type_id(&self) -> TypeId;
fn type_name(&self) -> String;
fn box_clone(&self) -> Box<dyn Any>;
/// This type may only be implemented by `rhai`.
@@ -20,6 +22,10 @@ where
TypeId::of::<T>()
}
fn type_name(&self) -> String {
type_name::<T>().to_string()
}
#[inline]
fn box_clone(&self) -> Box<dyn Any> {
Box::new(self.clone())