[][src]Struct growable::Growable

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]

Returns a new instance of Growable but does not allocate any memory on the heap yet.

Examples

  let _ = Growable::new();

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

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

Returns true if no memory has been allocated yet.

Returns the amount of memory allocated by this Growable.

Returns the alignment.

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 Sync for Growable
[src]

impl Send for Growable
[src]

impl Default for Growable
[src]

impl Clone for Growable
[src]

Performs copy-assignment from source. Read more

impl Drop for Growable
[src]

impl Debug for Growable
[src]

impl Pointer for Growable
[src]

Blanket Implementations

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

impl<T> From for T
[src]

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

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

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

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

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

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

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

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