Trait Any Copy item path 1.6.0 · Source pub trait Any: 'static {
// Required method
fn type_id (&self) -> TypeId ;
}Expand description A trait to emulate dynamic typing.
Most types implement Any. However, any type which contains a non-'static reference does not.
See the module-level documentation for more details.
Gets the TypeId of self.
If called on a dyn Any trait object
(or a trait object of a subtrait of Any),
this returns the TypeId of the underlying
concrete type, not that of dyn Any itself.
§ Examples
use std::any::{Any, TypeId};
fn is_string(s: & dyn Any) -> bool {
TypeId::of::<String>() == s.type_id()
}
assert_eq! (is_string(& 0 ), false );
assert_eq! (is_string(& "cookie monster" .to_string()), true );