From e0165ab294a03469271a7d1ca35a88ee941ebee6 Mon Sep 17 00:00:00 2001 From: Intege-rs Date: Fri, 11 Apr 2025 13:39:23 -0400 Subject: [PATCH] Mut::array --- sub/core/src/pod.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/sub/core/src/pod.rs b/sub/core/src/pod.rs index 1e3ef33..92e0baa 100644 --- a/sub/core/src/pod.rs +++ b/sub/core/src/pod.rs @@ -31,7 +31,7 @@ unsafe impl Sync for Mut {} unsafe impl Send for Mut {} impl Mut { - #[inline(always)]#[inline(always)] + #[inline(always)] pub const fn new(value: T) -> Self { Self(core::cell::UnsafeCell::new(value)) } @@ -41,6 +41,25 @@ impl Mut { } } +impl Mut { + + #[inline(always)] + pub const fn array(value: T) -> [Self;S] { + unsafe { + let mut a = MaybeUninit::<[Mut;S]>::uninit(); + let mut i = 0usize; + while i < S { + a.as_mut_ptr() + .cast::>() + .add(i) + .write(Mut::new(value)); + i+= 1; + } + a.assume_init() + } + } +} + impl Mut { #[inline(always)] pub unsafe fn set(&self, value: T) { unsafe { core::ptr::write(self.as_ptr(), value) } } #[inline(always)] pub fn get(&self) -> T { unsafe { core::ptr::read(self.as_ptr()) } }