From 380e3fb72a616addcfa77bbd0e833b299f9ac9d3 Mon Sep 17 00:00:00 2001 From: Frostie314159 Date: Sat, 17 Aug 2024 11:47:33 +0200 Subject: [PATCH] Removed pool initialization. --- examples/{initialised.rs => uninit.rs} | 6 +++--- src/lib.rs | 21 +++------------------ 2 files changed, 6 insertions(+), 21 deletions(-) rename examples/{initialised.rs => uninit.rs} (75%) diff --git a/examples/initialised.rs b/examples/uninit.rs similarity index 75% rename from examples/initialised.rs rename to examples/uninit.rs index 6d477cf..9075fd4 100644 --- a/examples/initialised.rs +++ b/examples/uninit.rs @@ -1,11 +1,11 @@ use atomic_pool::{pool, Box}; use std::mem; -pool!(TestPool: [u32; 3], [0u32; 3]); +pool!(TestPool: [u32; 3]); fn main() { let mut buffer = unsafe { Box::::new_uninit() }.unwrap(); - println!("Allocated new buffer, with contents: {:#x}", *buffer); + println!("Allocated new buffer."); *buffer = 0xf00dbabeu32; @@ -17,7 +17,7 @@ fn main() { let reallocated_buffer = unsafe { Box::::new_uninit() }.unwrap(); println!( - "Reallocated buffer, with contents: 0x{:#x}", + "Reallocated buffer, with contents: {:#x}", *reallocated_buffer ); } diff --git a/src/lib.rs b/src/lib.rs index 78ffb29..a2d2ffa 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -105,8 +105,8 @@ impl Box

{ } /// Turn this box into a raw pointer. - /// - /// Once you turn a box into a raw pointer, it becomes your responsibility to free it properly again. + /// + /// Once you turn a box into a raw pointer, it becomes your responsibility to free it properly again. /// This can be done, by creating a box from that raw pointer again, using [Self::from_raw]. pub fn into_raw(b: Self) -> NonNull { let res = b.ptr; @@ -115,7 +115,7 @@ impl Box

{ } /// Create a box from a raw pointer. - /// + /// /// # Safety /// You must ensure, that the pointer points to valid memory, which was allocated from the pool in the generic parameter. /// If you fail to do so, this will trigger a panic, once this box is dropped. @@ -269,21 +269,6 @@ macro_rules! pool { } } }; - ($vis:vis $name:ident: [$ty:ty; $n:expr], $initial_value:expr) => { - $vis struct $name { _uninhabited: ::core::convert::Infallible } - impl $crate::Pool for $name { - type Item = $ty; - type Storage = $crate::PoolStorageImpl<$ty, {$n}, {($n+31)/32}>; - fn get() -> &'static Self::Storage { - static POOL: $crate::PoolStorageImpl<$ty, {$n}, {($n+31)/32}> = { - let mut pool_storage_impl = $crate::PoolStorageImpl::new(); - pool_storage_impl.data = unsafe { ::core::mem::transmute($initial_value) }; - pool_storage_impl - }; - &POOL - } - } - }; } #[cfg(test)] mod test {