Bug: 310600230

Clone this repo:
  1. 3d82bb2 Merge remote-tracking branch 'origin/upstream' am: a2909347ec am: 5fe8da383f am: c4b16643db by Inna Palant · 5 months ago android14-qpr2-release android14-qpr2-s1-release android14-qpr2-s2-release android14-qpr2-s3-release main android-14.0.0_r28 android-14.0.0_r29 android-14.0.0_r30 android-14.0.0_r31 android-14.0.0_r32 android-14.0.0_r33
  2. c4b1664 Merge remote-tracking branch 'origin/upstream' am: a2909347ec am: 5fe8da383f by Inna Palant · 5 months ago
  3. 5fe8da3 Merge remote-tracking branch 'origin/upstream' am: a2909347ec by Inna Palant · 5 months ago
  4. a290934 Merge remote-tracking branch 'origin/upstream' Import b/310600230 by Inna Palant · 5 months ago simpleperf-release platform-tools-34.0.5
  5. 4669719 Import 'downcast' crate by Martin Geisler · 6 months ago upstream

downcast   Latest Version

A trait (& utilities) for downcasting trait objects back to their original types.

link to API documentation

example usage

Add to your Cargo.toml:

[dependencies]
downcast = "0.12"

Add to your crate root:

#[macro_use]
extern crate downcast;
  • simple showcases the most simple usage of this library.
  • with_params showcases how to deal with traits who have type parameters.
  • sync_service showcases how to downcast Arc-pointers.

build features

  • std (default) enables all functionality requiring the standard library (Downcast::downcast()).
  • nightly enables all functionality requiring rust nightly (Any::type_name()).

faq

Q: I'm getting the size for values of type XXX cannot be known at compile time errors, what am i doing wrong?

A: Make sure you use the corresponding Any bound along with the Downcast traits. So, Any for Downcast and AnySync for DowncastSync.

Q: Can i cast trait objects to trait objects?

A: No, that is currently no possible in safe rust - and unsafe solutions are very tricky, as well. If you found a solution, feel free to share it!

Q: What is the difference between this and the downcast-rs crate on crates.io?

A: At the moment, there isn't one, really. There was an unfortunate naming clash. You may consider using the other crate, as it is more actively maintained. This one is considered feature-complete and frozen in functionality. Hopefully, one day, the Rust language will make downcasting easier and we will need neither of these crates anymore!