tag | 78cc0e6465de40d6ff5d3875ac83d4a40a64d331 | |
---|---|---|
tagger | The Android Open Source Project <initial-contribution@android.com> | Tue Apr 23 15:27:26 2024 -0700 |
object | 6d82755414322b660674f90133a92c194bc0bd39 |
Platform Tools Release 35.0.1 (11580240)
commit | 6d82755414322b660674f90133a92c194bc0bd39 | [log] [tgz] |
---|---|---|
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | Thu Mar 07 02:14:35 2024 +0000 |
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | Thu Mar 07 02:14:35 2024 +0000 |
tree | ff176214b85e9271e57b726f443643ddc3042b27 | |
parent | a2909347ec722e2b3d4dbe20a7c6ca3086981b3d [diff] | |
parent | 3d82bb20933db1fa78735402d76eaca0c9aae523 [diff] |
Snap for 11541002 from 3d82bb20933db1fa78735402d76eaca0c9aae523 to sdk-release Change-Id: I0f928d253019e5ef2f4d2a117d5db6ec9791f205
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!