Struct growable::Growable [−][src]
A chunk of the heap memory that can be assigned with an arbitrary type.
Examples
First, let’s spawn a new Growable
. In this case no allocation will be performed.
let growable = Growable::new();
Now we can assign some data to it.
let arr: Reusable<[char; 3]> = growable.consume(['f', 'o', 'o']); assert_eq!(&*arr, &['f', 'o', 'o']);
No longer wanted data can be then freed on demand, fetching Growable back. Then it might be assigned with some data again and so on.
let growable = Reusable::free(arr); let arr: Reusable<[char; 6]> = growable.consume(['f', 'o', 'o', 'b', 'a', 'r']); assert_eq!(&*arr, &['f', 'o', 'o', 'b', 'a', 'r']);
Implementations
impl Growable
[src]
pub fn new() -> Self
[src]
Returns a new instance of Growable
but does not allocate any memory on the heap yet.
Examples
let _ = Growable::new();
pub fn with_capacity_for_type<T>() -> Self
[src]
Returns a new instance of Growable
with memory already allocated on the heap suitable to
store an instance of a given type T.
Examples
struct Foo { a: u8, b: usize, c: (), } let _ = Growable::with_capacity_for_type::<Foo>();
pub fn with_capacity(len: usize, ptr_alignment: usize) -> Self
[src]
Returns a new instance of Growable
with memory already allocated on the heap.
Panics
ptr_alignment
is not a power of two.len
overflows after being rounded up to the nearest multiple of the alignment.
Notes
Might trigger alloc_error
handler.
Examples
let _ = Growable::with_capacity(256, 16);
pub fn is_empty(&self) -> bool
[src]
Returns true if no memory has been allocated yet.
pub fn len(&self) -> usize
[src]
Returns the amount of memory allocated by this Growable
.
pub fn alignment(&self) -> usize
[src]
Returns the alignment.
pub fn consume<T>(self, t: T) -> Reusable<T>
[src]
Places an instance of T
on the heap, an actual (re)allocation will be performed
only if there is not enough space or the pointer alignment is invalid.
Notes
Might trigger alloc_error
handler.
Examples
let growable = Growable::with_capacity(128, 8); let num = growable.consume(0usize); assert_eq!(*num, 0usize);
Trait Implementations
impl Clone for Growable
[src]
fn clone(&self) -> Self
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Debug for Growable
[src]
impl Default for Growable
[src]
impl Drop for Growable
[src]
impl Pointer for Growable
[src]
impl Send for Growable
[src]
impl Sync for Growable
[src]
Auto Trait Implementations
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,