File tree 1 file changed +4
-4
lines changed
1 file changed +4
-4
lines changed Original file line number Diff line number Diff line change 17
17
//! # Smart pointers and `dyn Any`
18
18
//!
19
19
//! 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
21
21
//! 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
23
23
//! 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
+ //!
25
26
//! ```
26
27
//! use std::any::{Any, TypeId};
27
28
//!
32
33
//! // ... than this:
33
34
//! let boxed_id = boxed.type_id();
34
35
//!
35
- //! // Both of these assertions pass
36
36
//! assert_eq!(actual_id, TypeId::of::<i32>());
37
37
//! assert_eq!(boxed_id, TypeId::of::<Box<dyn Any>>());
38
38
//! ```
You can’t perform that action at this time.
0 commit comments