pub trait Any: 'static { fn type_id(&self) -> TypeId; }
A type 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.
impl dyn Any + 'static
[src]
pub fn is<T>(&self) -> bool where
T: Any,
[src]
Returns true
if the boxed type is the same as T
.
pub fn downcast_ref<T>(&self) -> Option<&T> where
T: Any,
[src]
Returns some reference to the boxed value if it is of type T
, or None
if it isn't.
pub fn downcast_mut<T>(&mut self) -> Option<&mut T> where
T: Any,
[src]
Returns some mutable reference to the boxed value if it is of type T
, or None
if it isn't.
impl dyn Any + 'static + Send
[src]
pub fn is<T>(&self) -> bool where
T: Any,
[src]
Forwards to the method defined on the type Any
.
pub fn downcast_ref<T>(&self) -> Option<&T> where
T: Any,
[src]
Forwards to the method defined on the type Any
.
pub fn downcast_mut<T>(&mut self) -> Option<&mut T> where
T: Any,
[src]
Forwards to the method defined on the type Any
.
impl dyn Any + 'static + Send + Sync
[src]
pub fn is<T>(&self) -> bool where
T: Any,
[src]1.28.0
Forwards to the method defined on the type Any
.
pub fn downcast_ref<T>(&self) -> Option<&T> where
T: Any,
[src]1.28.0
Forwards to the method defined on the type Any
.
use std::any::Any; fn print_if_string(s: &(dyn Any + Send + Sync)) { if let Some(string) = s.downcast_ref::<String>() { println!("It's a string({}): '{}'", string.len(), string); } else { println!("Not a string..."); } } fn main() { print_if_string(&0); print_if_string(&"cookie monster".to_string()); }
pub fn downcast_mut<T>(&mut self) -> Option<&mut T> where
T: Any,
[src]1.28.0
Forwards to the method defined on the type Any
.
impl Debug for dyn Any + 'static + Send
[src]
impl Debug for dyn Any + 'static + Send + Sync
[src]1.28.0
impl Debug for dyn Any + 'static
[src]
© 2010 The Rust Project Developers
Licensed under the Apache License, Version 2.0 or the MIT license, at your option.
https://doc.rust-lang.org/std/any/trait.Any.html