Struct PoolBox

Source
pub struct PoolBox<A> { /* private fields */ }
Expand description

A unique pointer to a pool allocated value of A.

Implementations§

Source§

impl<A> PoolBox<A>

Source

pub fn default(pool: &Pool<A>) -> Self
where 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);
Source

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);
Source

pub fn clone_from(pool: &Pool<A>, value: &A) -> Self
where 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);
Source

pub fn pin_default(pool: &Pool<A>) -> Pin<Self>
where A: PoolDefault,

Construct a Pinned PoolBox with a default value.

§Examples
let pool: Pool<usize> = Pool::new(256);
let zero = PoolBox::pin_default(&pool);
assert_eq!(0, *zero);
Source

pub fn pin(pool: &Pool<A>, value: A) -> Pin<Self>

Construct a Pinned PoolBox with the given value.

§Examples
let pool: Pool<usize> = Pool::new(256);
let number = PoolBox::pin(&pool, 1337);
assert_eq!(1337, *number);
Source

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));
Source

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.

Source

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.

Source

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> AsMut<A> for PoolBox<A>

Source§

fn as_mut(&mut self) -> &mut A

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl<A> AsRef<A> for PoolBox<A>

Source§

fn as_ref(&self) -> &A

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<A> Borrow<A> for PoolBox<A>

Source§

fn borrow(&self) -> &A

Immutably borrows from an owned value. Read more
Source§

impl<A> BorrowMut<A> for PoolBox<A>

Source§

fn borrow_mut(&mut self) -> &mut A

Mutably borrows from an owned value. Read more
Source§

impl<A> Clone for PoolBox<A>
where A: PoolClone,

Source§

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)

Performs copy-assignment from source. Read more
Source§

impl<A> Debug for PoolBox<A>
where A: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<A> Deref for PoolBox<A>

Source§

type Target = A

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<A> DerefMut for PoolBox<A>

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl<A> Display for PoolBox<A>
where A: Display,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<A> Drop for PoolBox<A>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<A> Hash for PoolBox<A>
where A: Hash,

Source§

fn hash<H: Hasher>(&self, hasher: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<A> Ord for PoolBox<A>
where A: Ord,

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<A> PartialEq for PoolBox<A>
where A: PartialEq,

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<A> PartialOrd for PoolBox<A>
where A: PartialOrd,

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<A> Pointer for PoolBox<A>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<A> Eq for PoolBox<A>
where A: Eq,

Auto Trait Implementations§

§

impl<A> Freeze for PoolBox<A>

§

impl<A> RefUnwindSafe for PoolBox<A>
where A: RefUnwindSafe,

§

impl<A> !Send for PoolBox<A>

§

impl<A> !Sync for PoolBox<A>

§

impl<A> Unpin for PoolBox<A>

§

impl<A> UnwindSafe for PoolBox<A>
where A: RefUnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.