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']);

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]

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

impl RefUnwindSafe for Growable

impl Unpin for Growable

impl UnwindSafe for Growable

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.