File tree Expand file tree Collapse file tree 1 file changed +4
-4
lines changed Expand file tree Collapse file tree 1 file changed +4
-4
lines changed Original file line number Diff line number Diff line change 1717//! # Smart pointers and `dyn Any`
1818//!
1919//! One piece of behavior to keep in mind when using `Any` as a trait object,
20- //! especially with types like `Box<dyn Any>` or `Arc<dyn Any>` is that simply
20+ //! especially with types like `Box<dyn Any>` or `Arc<dyn Any>`, is that simply
2121//! calling `.type_id()` on the value will produce the `TypeId` of the
22- //! container, and not the underlying trait object. This can be avoided
22+ //! * container*, not the underlying trait object. This can be avoided by
2323//! converting the smart pointer into a `&dyn Any` instead, which will return
24- //! the object's type id. For example:
24+ //! the object's `TypeId`. For example:
25+ //!
2526//! ```
2627//! use std::any::{Any, TypeId};
2728//!
3233//! // ... than this:
3334//! let boxed_id = boxed.type_id();
3435//!
35- //! // Both of these assertions pass
3636//! assert_eq!(actual_id, TypeId::of::<i32>());
3737//! assert_eq!(boxed_id, TypeId::of::<Box<dyn Any>>());
3838//! ```
You can’t perform that action at this time.
0 commit comments