Struct growable::Growable [−][src]
pub struct Growable { /* fields omitted */ }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']);
Methods
impl Growable[src]
impl Growablepub fn new() -> Self[src]
pub fn new() -> SelfReturns 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]
pub fn with_capacity_for_type<T>() -> SelfReturns 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]
pub fn with_capacity(len: usize, ptr_alignment: usize) -> SelfReturns a new instance of Growable with memory already allocated on the heap.
Panics
ptr_alignmentis not a power of two.lenoverflows after being rounded up to the nearest multiple of the alignment.
Examples
let _ = Growable::with_capacity(256, 16);
pub fn is_empty(&self) -> bool[src]
pub fn is_empty(&self) -> boolReturns true if no memory has been allocated yet.
pub fn len(&self) -> usize[src]
pub fn len(&self) -> usizeReturns the amount of memory allocated by this Growable.
pub fn alignment(&self) -> usize[src]
pub fn alignment(&self) -> usizeReturns the alignment.
pub fn consume<T>(self, t: T) -> Reusable<T>[src]
pub fn consume<T>(self, t: T) -> Reusable<T>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 oom() handler.
Examples
let growable = Growable::with_capacity(128, 8); let num = growable.consume(0usize); assert_eq!(*num, 0usize);
Trait Implementations
impl Send for Growable[src]
impl Send for Growableimpl Sync for Growable[src]
impl Sync for Growableimpl Clone for Growable[src]
impl Clone for Growablefn clone(&self) -> Self[src]
fn clone(&self) -> SelfReturns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)1.0.0[src]
fn clone_from(&mut self, source: &Self)Performs copy-assignment from source. Read more
impl Pointer for Growable[src]
impl Pointer for Growableimpl Debug for Growable[src]
impl Debug for Growablefn fmt(&self, formatter: &mut Formatter) -> Result[src]
fn fmt(&self, formatter: &mut Formatter) -> ResultFormats the value using the given formatter. Read more
impl Default for Growable[src]
impl Default for Growableimpl Drop for Growable[src]
impl Drop for GrowableBlanket Implementations
impl<T> From for T[src]
impl<T> From for Timpl<T, U> Into for T where
U: From<T>, [src]
impl<T, U> Into for T where
U: From<T>, impl<T> ToOwned for T where
T: Clone, [src]
impl<T> ToOwned for T where
T: Clone, type Owned = T
fn to_owned(&self) -> T[src]
fn to_owned(&self) -> TCreates owned data from borrowed data, usually by cloning. Read more
fn clone_into(&self, target: &mut T)[src]
fn clone_into(&self, target: &mut T)🔬 This is a nightly-only experimental API. (toowned_clone_into)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more
impl<T, U> TryFrom for T where
T: From<U>, [src]
impl<T, U> TryFrom for T where
T: From<U>, type Error = !
try_from)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>try_from)Performs the conversion.
impl<T> Borrow for T where
T: ?Sized, [src]
impl<T> Borrow for T where
T: ?Sized, impl<T> BorrowMut for T where
T: ?Sized, [src]
impl<T> BorrowMut for T where
T: ?Sized, fn borrow_mut(&mut self) -> &mut T[src]
fn borrow_mut(&mut self) -> &mut TMutably borrows from an owned value. Read more
impl<T, U> TryInto for T where
U: TryFrom<T>, [src]
impl<T, U> TryInto for T where
U: TryFrom<T>, type Error = <U as TryFrom<T>>::Error
try_from)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>try_from)Performs the conversion.
impl<T> Any for T where
T: 'static + ?Sized, [src]
impl<T> Any for T where
T: 'static + ?Sized, fn get_type_id(&self) -> TypeId[src]
fn get_type_id(&self) -> TypeId🔬 This is a nightly-only experimental API. (get_type_id)
this method will likely be replaced by an associated static
Gets the TypeId of self. Read more