pub struct PoolBox<A> { /* private fields */ }Expand description
A unique pointer to a pool allocated value of A.
Implementations§
Source§impl<A> PoolBox<A>
impl<A> PoolBox<A>
Sourcepub fn default(pool: &Pool<A>) -> Selfwhere
A: PoolDefault,
pub fn default(pool: &Pool<A>) -> Selfwhere
A: PoolDefault,
Construct a PoolBox with a newly initialised value of A.
This uses PoolDefault::default_uninit() to initialise a
default value, which may be faster than constructing a PoolBox from an
existing value using PoolBox::new(), depending on the data
type.
§Examples
let pool: Pool<usize> = Pool::new(256);
let zero = PoolBox::default(&pool);
assert_eq!(0, *zero);Sourcepub fn new(pool: &Pool<A>, value: A) -> Self
pub fn new(pool: &Pool<A>, value: A) -> Self
Wrap a value in a PoolBox.
This will copy the entire value into the memory handled by the
PoolBox, which may be slower than using
PoolBox::default(), so it’s not recommended to use this to
construct the default value.
§Examples
let pool: Pool<usize> = Pool::new(256);
let number = PoolBox::new(&pool, 1337);
assert_eq!(1337, *number);Sourcepub fn clone_from(pool: &Pool<A>, value: &A) -> Selfwhere
A: PoolClone,
pub fn clone_from(pool: &Pool<A>, value: &A) -> Selfwhere
A: PoolClone,
Clone a value and return a new PoolBox to it.
This will use PoolClone::clone_uninit() to perform the
clone, which may be more efficient than using
PoolBox::new(value.clone()).
§Examples
let pool: Pool<Vec<usize>> = Pool::new(1);
let vec = vec![1, 2, 3];
let ref1 = PoolBox::clone_from(&pool, &vec);
assert_eq!(vec, *ref1);Sourcepub fn pin_default(pool: &Pool<A>) -> Pin<Self>where
A: PoolDefault,
pub fn pin_default(pool: &Pool<A>) -> Pin<Self>where
A: PoolDefault,
Sourcepub fn ptr_eq(left: &Self, right: &Self) -> bool
pub fn ptr_eq(left: &Self, right: &Self) -> bool
Test two PoolBoxes for pointer equality.
§Examples
let pool: Pool<usize> = Pool::new(1);
let ref1 = PoolBox::default(&pool);
assert!(PoolBox::ptr_eq(&ref1, &ref1));Sourcepub fn into_raw_non_null(b: PoolBox<A>) -> NonNull<A>
pub fn into_raw_non_null(b: PoolBox<A>) -> NonNull<A>
Consume the PoolBox and return a pointer to the contents.
Please note that the only proper way to drop the value pointed to
is by using PoolBox::from_raw to turn it back into a PoolBox, because
the value is followed by PoolBox metadata which also needs to
be dropped.
Sourcepub fn into_raw(b: PoolBox<A>) -> *mut A
pub fn into_raw(b: PoolBox<A>) -> *mut A
Consume the PoolBox and return a pointer to the contents.
The pointer is guaranteed to be non-null.
Please note that the only proper way to drop the value pointed to
is by using PoolBox::from_raw to turn it back into a PoolBox, because
the value is followed by PoolBox metadata which also needs to
be dropped.
Sourcepub unsafe fn from_raw(ptr: *mut A) -> Self
pub unsafe fn from_raw(ptr: *mut A) -> Self
Turn a raw pointer back into a PoolBox.
The pointer must be non-null and obtained from a previous call to
PoolBox::into_raw or PoolBox::into_raw_non_null.
§Safety
This must only be called on pointers obtained through PoolBox::into_raw.
It’s not OK to call it on a pointer to a value of A you’ve allocated
yourself.
§Examples
let pool: Pool<usize> = Pool::new(1);
let ref1 = PoolBox::new(&pool, 31337);
// Turn the PoolBox into a raw pointer and see if it still works.
let ptr = PoolBox::into_raw(ref1);
assert_eq!(31337, unsafe { *ptr });
// Turn it back into a PoolBox and see, again, if it still works.
let ref2 = unsafe { PoolBox::from_raw(ptr) };
assert_eq!(31337, *ref2);Trait Implementations§
Source§impl<A> BorrowMut<A> for PoolBox<A>
impl<A> BorrowMut<A> for PoolBox<A>
Source§fn borrow_mut(&mut self) -> &mut A
fn borrow_mut(&mut self) -> &mut A
Source§impl<A> Clone for PoolBox<A>where
A: PoolClone,
impl<A> Clone for PoolBox<A>where
A: PoolClone,
Source§fn clone(&self) -> Self
fn clone(&self) -> Self
Clone a PoolBox and its contents.
This will use PoolClone::clone_uninit() to perform the
clone, which may be more efficient than using
PoolBox::new(value.clone()).
§Examples
let pool: Pool<Vec<usize>> = Pool::new(1);
let vec1 = PoolBox::new(&pool, vec![1, 2, 3]);
let vec2 = vec1.clone();
assert_eq!(vec1, vec2);1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more