Crates.io | anymore |
lib.rs | anymore |
version | 1.0.0 |
created_at | 2025-08-04 15:53:14.138969+00 |
updated_at | 2025-08-04 15:53:14.138969+00 |
description | AnyDebug: Dynamically typed values which can be inspected |
homepage | |
repository | https://github.com/linebender/anymore |
max_upload_size | |
id | 1780854 |
size | 33,924 |
The Anymore crate provides the AnyDebug
trait, for dynamically typed values which
can be inspected in Rust.
These can be used in any program domain, but have been developed with graphical
user interface libraries as the target consumer.
The AnyDebug
trait also has the type_name
method, which
can be used to access the type name of the contained value.
The traits in this crate can be used in the same way that you would use
Any
, with the additional capability that the Debug implementation is meaningful.
See the module-level documentation of Any
for more details of how it
can be used.
dyn AnyDebug
When you have dyn AnyDebug
contained in a smart pointer, such as Box
or
Arc
,
the type_name
method will give the type name of the smart
pointer, rather than the type name of the contained value. This can be avoided by
converting the smart pointer into a &dyn AnyDebug
instead, which will return the
object’s type name. This is the same caveat
seen with thetype_id
method on Any
.
In user interface contexts, there is often a need for passing dynamically typed values.
In Xilem, for example, one of the key concepts is
dispatching arbitrary messages to the correct component (called View
in Xilem
).
Each View
expects messages of a specific type or types, and knows how to handle these.
However, sometimes, due to bugs elsewhere in the app, a view will receive a message of a
type it didn't expect. If it were using the standard library, Any
type, there would be no
feasible way for the author of that View
implementation to learn what the underlying type was.
This can make understanding this failure quite challenging.
Because of this, Xilem uses the AnyDebug
trait for these messages, so they can be inspected.
A similar need arises in Masonry, which is the widget toolkit co-developed with Xilem.
The following crate feature flags are available:
alloc
(enabled by default): Implement downcasting from Box
es.
If this feature is not enabled, Anymore can be used in contexts without an allocator enabled.type_name
(enabled by default): Provide the type_name
function on AnyDebug
, which gives the type's name.
Most users should leave this enabled, as the costs of this method existing are expected to be negligible.This version of Anymore has been verified to compile with Rust 1.86 and later.
Future versions of Anymore might increase the Rust version requirement. It will not be treated as a breaking change and as such can even happen with small patch releases.
Discussion of Anymore development happens in the Linebender Zulip, specifically #rust ui > Anymore. All public content can be read without logging in.
Licensed under either of
at your option.
Contributions are welcome by pull request. The Rust code of conduct applies. Please feel free to add your name to the AUTHORS file in any substantive pull request.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be licensed as above, without any additional terms or conditions.