commit | 8f15941fddf8fdbb80eb29743207880673911df4 | [log] [tgz] |
---|---|---|
author | Xin Li <[email protected]> | Tue Jun 18 11:43:34 2024 -0700 |
committer | Xin Li <[email protected]> | Tue Jun 18 11:43:34 2024 -0700 |
tree | 2ed307f637804d94ea18b6a3a96038c19f43f839 | |
parent | fb9fcc10964b99e960bf1a3a004f968665a89a58 [diff] | |
parent | 70259aaf25cdfa3eb845d01e41589a22f4035eb9 [diff] |
Mark ab/11976889 as merged in aosp-main-future Bug: 347831320 Merged-In: Icf55148f9eaf8e9dd89ab13248dace62c9cc3a1c Change-Id: Id13fe8e0d0a12ca937233e9365f9849b5517ec39
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!