Enum smallbox::SmallBox [] [src]

pub enum SmallBox<T: ?Sized, Space = S4> {
    Stack(StackBox<T, Space>),
    Box(Box<T>),
}

Stack allocation with heap fallback

Examples

use smallbox::SmallBox;

let val: SmallBox<PartialEq<usize>> = SmallBox::new(5usize);

assert!(*val == 5)

Variants

Methods

impl<T: ?Sized, Space> SmallBox<T, Space>
[src]

Box val on stack or heap depending on its size

Example

use smallbox::SmallBox;
use smallbox::space::*;

let tiny: SmallBox<[u64], S4> = SmallBox::new([0; 2]);
let big: SmallBox<[u64], S4> = SmallBox::new([1; 8]);

assert_eq!(tiny.len(), 2);
assert_eq!(big[7], 1);

match tiny {
    SmallBox::Stack(val) => assert_eq!(*val, [0; 2]),
    _ => unreachable!()
}

match big {
    SmallBox::Box(val) => assert_eq!(*val, [1; 8]),
    _ => unreachable!()
}

Try to transforms to the SmallBox<T> of bigger capacity, and return Err when target capacity is smaller. Note that this method will always success when the allocation is on heap.

Example

use smallbox::SmallBox;
use smallbox::space::*;

let s = SmallBox::<[usize], S8>::new([0usize; 4]);
assert!(s.resize::<S16>().is_ok());

let s = SmallBox::<[usize], S8>::new([0usize; 4]);
assert!(s.resize::<S4>().is_err());

Trait Implementations

impl<T: ?Sized, Space> Deref for SmallBox<T, Space>
[src]

The resulting type after dereferencing

The method called to dereference a value

impl<T: ?Sized, Space> DerefMut for SmallBox<T, Space>
[src]

The method called to mutably dereference a value

impl<T: Display + ?Sized, Space> Display for SmallBox<T, Space>
[src]

Formats the value using the given formatter. Read more

impl<T: Debug + ?Sized, Space> Debug for SmallBox<T, Space>
[src]

Formats the value using the given formatter.

impl<T: ?Sized, Space> Pointer for SmallBox<T, Space>
[src]

Formats the value using the given formatter.

impl<T: ?Sized + PartialEq, Space> PartialEq for SmallBox<T, Space>
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<T: ?Sized + PartialOrd, Space> PartialOrd for SmallBox<T, Space>
[src]

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

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

impl<T: ?Sized + Ord, Space> Ord for SmallBox<T, Space>
[src]

This method returns an Ordering between self and other. Read more

impl<T: ?Sized + Eq, Space> Eq for SmallBox<T, Space>
[src]

impl<T: ?Sized + Hash, Space> Hash for SmallBox<T, Space>
[src]

Feeds this value into the given [Hasher]. Read more

Feeds a slice of this type into the given [Hasher]. Read more