Enum smallbox::SmallBox
[−]
[src]
pub enum SmallBox<T: ?Sized, Space = S2> { 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
Stack(StackBox<T, Space>)Box(Box<T>)Methods
impl<T: ?Sized, Space> SmallBox<T, Space>[src]
fn new<U>(val: U) -> SmallBox<T, Space> where
U: Unsize<T>,
U: Unsize<T>,
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!() }
fn resize<ToSpace>(self) -> Result<SmallBox<T, ToSpace>, Self>
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]
type Target = T
The resulting type after dereferencing
fn deref(&self) -> &T
The method called to dereference a value
impl<T: ?Sized, Space> DerefMut for SmallBox<T, Space>[src]
fn deref_mut(&mut self) -> &mut T
The method called to mutably dereference a value
impl<T: Display + ?Sized, Space> Display for SmallBox<T, Space>[src]
impl<T: Debug + ?Sized, Space> Debug for SmallBox<T, Space>[src]
impl<T: ?Sized, Space> Pointer for SmallBox<T, Space>[src]
impl<T: ?Sized + PartialEq, Space> PartialEq for SmallBox<T, Space>[src]
fn eq(&self, other: &SmallBox<T, Space>) -> bool
This method tests for self and other values to be equal, and is used by ==. Read more
fn ne(&self, other: &SmallBox<T, Space>) -> bool
This method tests for !=.
impl<T: ?Sized + PartialOrd, Space> PartialOrd for SmallBox<T, Space>[src]
fn partial_cmp(&self, other: &SmallBox<T, Space>) -> Option<Ordering>
This method returns an ordering between self and other values if one exists. Read more
fn lt(&self, other: &SmallBox<T, Space>) -> bool
This method tests less than (for self and other) and is used by the < operator. Read more
fn le(&self, other: &SmallBox<T, Space>) -> bool
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
fn ge(&self, other: &SmallBox<T, Space>) -> bool
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
fn gt(&self, other: &SmallBox<T, Space>) -> bool
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]
fn cmp(&self, other: &SmallBox<T, Space>) -> Ordering
This method returns an Ordering between self and other. Read more