Lines Matching defs:MaybeUninit

472 /// `MaybeUninit` is identical to the [standard library
473 /// `MaybeUninit`][core-maybe-uninit] type except that it supports unsized
478 /// The same layout guarantees and caveats apply to `MaybeUninit<T>` as apply to
479 /// the [standard library `MaybeUninit`][core-maybe-uninit] with one exception:
483 /// `MaybeUninit<T>` and vice versa
484 /// - Given `t: *const T` and `m: *const MaybeUninit<T>` with identical fat
488 /// [core-maybe-uninit]: core::mem::MaybeUninit
492 pub struct MaybeUninit<T: ?Sized + KnownLayout>(
493 // SAFETY: `MaybeUninit<T>` has the same size as `T`, because (by invariant
494 // on `T::MaybeUninit`) `T::MaybeUninit` has `T::LAYOUT` identical to `T`,
496 // accurately reflects the layout of `T`. By invariant on `T::MaybeUninit`,
497 // it admits uninitialized bytes in all positions. Because `MaybeUninit` is
500 T::MaybeUninit,
504 impl<T: ?Sized + KnownLayout> MaybeUninit<T> {
505 /// Constructs a `MaybeUninit<T>` initialized with the given value.
512 // SAFETY: It is valid to transmute `val` to `MaybeUninit<T>` because it
513 // is both valid to transmute `val` to `T::MaybeUninit`, and it is valid
514 // to transmute from `T::MaybeUninit` to `MaybeUninit<T>`.
516 // First, it is valid to transmute `val` to `T::MaybeUninit` because, by
517 // invariant on `T::MaybeUninit`:
518 // - For `T: Sized`, `T` and `T::MaybeUninit` have the same size.
520 // `T::MaybeUninit`.
522 // Second, it is additionally valid to transmute from `T::MaybeUninit`
523 // to `MaybeUninit<T>`, because `MaybeUninit<T>` is a
524 // `repr(transparent)` wrapper around `T::MaybeUninit`.
527 // `T::MaybeUninit: Sized` bound to this function's `where` clause.
531 /// Constructs an uninitialized `MaybeUninit<T>`.
541 // `MaybeUninit<T>` since they both admit uninitialized bytes in all
544 // `MaybeUninit<T>` has the same size as `T`, because (by invariant on
545 // `T::MaybeUninit`) `T::MaybeUninit` has `T::LAYOUT` identical to `T`,
552 // [1] Per https://doc.rust-lang.org/1.81.0/std/mem/union.MaybeUninit.html#layout-1:
554 // `MaybeUninit<T>` is guaranteed to have the same size, alignment,
559 /// Creates a `Box<MaybeUninit<T>>`.
574 // `Self`, because `Self` is `MaybeUninit` and thus admits arbitrary
579 /// Extracts the value from the `MaybeUninit<T>` container.
596 impl<T: ?Sized + KnownLayout> fmt::Debug for MaybeUninit<T> {
1175 let uninit = MaybeUninit::new(input);
1184 let uninit = MaybeUninit::new(&input);
1194 let uninit = MaybeUninit::new(&input[..]);
1203 let _uninit = MaybeUninit::<u8>::uninit();
1210 let _boxed = MaybeUninit::<u8>::new_boxed_uninit(()).unwrap();
1215 let uninit = MaybeUninit::<u8>::uninit();
1216 assert!(format!("{:?}", uninit).contains("MaybeUninit"));