We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 46224d5 commit b16ea15Copy full SHA for b16ea15
library/core/src/any.rs
@@ -915,3 +915,21 @@ pub const fn downcast_trait<
915
None => None,
916
}
917
918
+#[allow(missing_docs)]
919
+#[must_use]
920
+#[unstable(feature = "downcast_trait", issue = "69420")]
921
+pub const fn downcast_trait_mut<
922
+ T: Any + 'static,
923
+ U: ptr::Pointee<Metadata = ptr::DynMetadata<U>> + ?Sized + 'static,
924
+>(
925
+ t: &mut T,
926
+) -> Option<&mut U> {
927
+ let vtable: Option<ptr::DynMetadata<U>> = const { intrinsics::vtable_for::<T, U>() };
928
+ match vtable {
929
+ Some(dyn_metadata) => {
930
+ let pointer = ptr::from_raw_parts_mut(t, dyn_metadata);
931
+ Some(unsafe { &mut *pointer })
932
+ }
933
+ None => None,
934
935
+}
0 commit comments