liveBook · Manning

Any

Any is a Rust trait that supports runtime type identification and checked conversion of suitable values to concrete types.

How 2 Manning books explain it

Learn Rust in a Month of Lunches

Any is a Rust standard-library trait for values that can support runtime type inspection and downcasting when they satisfy the required lifetime conditions.

How it is used
Supports checking a panic payload’s type inside a custom panic hook.
How deep it goes
Shows dyn Any + Send and a downcast_ref::<&str>() check, but does not explain trait implementation or lifetime requirements.
Examples
Shows a panic hook that prints a borrowed-string payload or “No payload!” when the downcast fails.
What you can do after
Apply it via std::panic::set_hook to attempt downcast_ref::<&str>() on a panic payload.

Read how Learn Rust in a Month of Lunches explains any →

Idiomatic Rust

The Rust Any trait enables runtime type identification and checked conversion to a concrete type for suitable values.

How it is used
Enables checked recovery of concrete types from trait objects.
How deep it goes
Demonstrates `as_any` and `downcast_ref` without further implementation detail.
Examples
Checks trait objects for `MyStruct1` or `MyStruct2` and calls their concrete methods.
What you can do after
Apply checked downcasting with `as_any` and `downcast_ref`.

Read how Idiomatic Rust explains any →

Related concepts

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.