aienux
Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.
Brought by drakestapleton
aienux / vendor / uefi / src / polyfill.rs
| 1 | // SPDX-License-Identifier: MIT OR Apache-2.0 |
| 2 | |
| 3 | //! Polyfills for functions in the standard library that are currently gated |
| 4 | //! behind unstable features. |
| 5 | |
| 6 | use core::mem::MaybeUninit; |
| 7 | use core::ptr; |
| 8 | #[cfg(feature = "alloc")] |
| 9 | use {alloc::vec::Vec, core::mem::ManuallyDrop}; |
| 10 | |
| 11 | /// Polyfill for the unstable `MaybeUninit::slice_assume_init_ref` function. |
| 12 | /// |
| 13 | /// See <https://github.com/rust-lang/rust/issues/63569>. |
| 14 | pub const unsafe fn maybe_uninit_slice_assume_init_ref<T>(s: &[MaybeUninit<T>]) -> &[T] { |
| 15 | // SAFETY: The source layout matches the target view. |
| 16 | unsafe { &*(ptr::from_ref(s) as *const [T]) } |
| 17 | } |
| 18 | |
| 19 | /// Polyfill for the unstable `MaybeUninit::slice_as_mut_ptr` function. |
| 20 | /// |
| 21 | /// See <https://github.com/rust-lang/rust/issues/63569>. |
| 22 | pub const fn maybe_uninit_slice_as_mut_ptr<T>(s: &mut [MaybeUninit<T>]) -> *mut T { |
| 23 | s.as_mut_ptr().cast::<T>() |
| 24 | } |
| 25 | |
| 26 | /// Polyfill for the unstable `Vec::into_raw_parts` function. |
| 27 | /// |
| 28 | /// See <https://github.com/rust-lang/rust/issues/65816>. |
| 29 | #[cfg(feature = "alloc")] |
| 30 | pub fn vec_into_raw_parts<T>(v: Vec<T>) -> (*mut T, usize, usize) { |
| 31 | let mut v = ManuallyDrop::new(v); |
| 32 | (v.as_mut_ptr(), v.len(), v.capacity()) |
| 33 | } |