commit | 5fe8da383f392974e1f279913a1bf4c97c867e1e | [log] [tgz] |
---|---|---|
author | Inna Palant <ipalant@google.com> | Wed Dec 13 12:19:20 2023 +0000 |
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | Wed Dec 13 12:19:20 2023 +0000 |
tree | ff176214b85e9271e57b726f443643ddc3042b27 | |
parent | 21be4635b1b8eabdf7a3abed6367ada2e24be5c6 [diff] | |
parent | a2909347ec722e2b3d4dbe20a7c6ca3086981b3d [diff] |
Merge remote-tracking branch 'origin/upstream' am: a2909347ec Original change: undetermined Change-Id: I9d6e81096507a5ee4a42fecdd101872757ea1ee1 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
A trait (& utilities) for downcasting trait objects back to their original types.
Add to your Cargo.toml:
[dependencies] downcast = "0.12"
Add to your crate root:
#[macro_use] extern crate downcast;
Arc
-pointers.Downcast::downcast()
).Any::type_name()
).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!