[−][src]Struct smallbox::SmallBox
An optimized box that store value on stack or on heap depending on its size
Methods
impl<T: ?Sized, Space> SmallBox<T, Space>
[src]
pub fn new(val: T) -> SmallBox<T, Space> where
T: Sized,
[src]
T: Sized,
Box value on stack or on heap depending on its size.
Example
use smallbox::SmallBox; use smallbox::space::*; let small: SmallBox<_, S4> = SmallBox::new([0usize; 2]); let large: SmallBox<_, S4> = SmallBox::new([1usize; 8]); assert_eq!(small.len(), 2); assert_eq!(large[7], 1); assert!(large.is_heap() == true);
pub fn resize<ToSpace>(self) -> SmallBox<T, ToSpace>
[src]
Change the capacity of SmallBox
.
This method may move stack-allocated data from stack to heap when inline space is not sufficient. And once the data is moved to heap, it'll never be moved again.
Example
use smallbox::SmallBox; use smallbox::space::{S2, S4}; let s: SmallBox::<_, S4> = SmallBox::new([0usize; 4]); let m: SmallBox::<_, S2> = s.resize();
pub fn is_heap(&self) -> bool
[src]
Returns true if data is allocated on heap.
Example
use smallbox::SmallBox; use smallbox::space::S1; let stacked: SmallBox::<usize, S1> = SmallBox::new(0usize); assert!(!stacked.is_heap()); let heaped: SmallBox::<(usize, usize), S1> = SmallBox::new((0usize, 1usize)); assert!(heaped.is_heap());
pub fn into_inner(self) -> T where
T: Sized,
[src]
T: Sized,
Consumes the SmallBox and returns ownership of the boxed value
Examples
use smallbox::SmallBox; use smallbox::space::S1; let stacked : SmallBox<_, S1> = SmallBox::new([21usize]); let val = stacked.into_inner(); assert_eq!(val[0], 21); let boxed : SmallBox<_, S1> = SmallBox::new(vec![21, 56, 420]); let val = boxed.into_inner(); assert_eq!(val[1], 56);
impl<Space> SmallBox<dyn Any, Space>
[src]
pub fn downcast<T: Any>(self) -> Result<SmallBox<T, Space>, Self>
[src]
Attempt to downcast the box to a concrete type.
Examples
#[macro_use] extern crate smallbox; use std::any::Any; use smallbox::SmallBox; use smallbox::space::*; fn print_if_string(value: SmallBox<dyn Any, S1>) { if let Ok(string) = value.downcast::<String>() { println!("String ({}): {}", string.len(), string); } } fn main() { let my_string = "Hello World".to_string(); print_if_string(smallbox!(my_string)); print_if_string(smallbox!(0i8)); }
impl<Space> SmallBox<dyn Any + Send, Space>
[src]
pub fn downcast<T: Any>(self) -> Result<SmallBox<T, Space>, Self>
[src]
Attempt to downcast the box to a concrete type.
Examples
#[macro_use] extern crate smallbox; use std::any::Any; use smallbox::SmallBox; use smallbox::space::*; fn print_if_string(value: SmallBox<dyn Any, S1>) { if let Ok(string) = value.downcast::<String>() { println!("String ({}): {}", string.len(), string); } } fn main() { let my_string = "Hello World".to_string(); print_if_string(smallbox!(my_string)); print_if_string(smallbox!(0i8)); }
Trait Implementations
impl<T: ?Sized + Send, Space> Send for SmallBox<T, Space>
[src]
impl<T: ?Sized + Sync, Space> Sync for SmallBox<T, Space>
[src]
impl<T: ?Sized, Space> Drop for SmallBox<T, Space>
[src]
impl<T: Clone, Space> Clone for SmallBox<T, Space> where
T: Sized,
[src]
T: Sized,
fn clone(&self) -> Self
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<T: ?Sized + Eq, Space> Eq for SmallBox<T, Space>
[src]
impl<T: ?Sized + Ord, Space> Ord for SmallBox<T, Space>
[src]
fn cmp(&self, other: &SmallBox<T, Space>) -> Ordering
[src]
fn max(self, other: Self) -> Self
1.21.0[src]
fn min(self, other: Self) -> Self
1.21.0[src]
fn clamp(self, min: Self, max: Self) -> Self
[src]
impl<T: ?Sized + PartialEq, Space> PartialEq<SmallBox<T, Space>> for SmallBox<T, Space>
[src]
fn eq(&self, other: &SmallBox<T, Space>) -> bool
[src]
fn ne(&self, other: &SmallBox<T, Space>) -> bool
[src]
impl<T: ?Sized + PartialOrd, Space> PartialOrd<SmallBox<T, Space>> for SmallBox<T, Space>
[src]
fn partial_cmp(&self, other: &SmallBox<T, Space>) -> Option<Ordering>
[src]
fn lt(&self, other: &SmallBox<T, Space>) -> bool
[src]
fn le(&self, other: &SmallBox<T, Space>) -> bool
[src]
fn ge(&self, other: &SmallBox<T, Space>) -> bool
[src]
fn gt(&self, other: &SmallBox<T, Space>) -> bool
[src]
impl<T: ?Sized + Display, Space> Display for SmallBox<T, Space>
[src]
impl<T: ?Sized + Debug, Space> Debug for SmallBox<T, Space>
[src]
impl<T: ?Sized, Space> Deref for SmallBox<T, Space>
[src]
impl<T: ?Sized, Space> DerefMut for SmallBox<T, Space>
[src]
impl<T: ?Sized + Hash, Space> Hash for SmallBox<T, Space>
[src]
fn hash<H: Hasher>(&self, state: &mut H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<T: ?Sized, Space> Pointer for SmallBox<T, Space>
[src]
Auto Trait Implementations
impl<T: ?Sized, Space> Unpin for SmallBox<T, Space> where
Space: Unpin,
T: Unpin,
Space: Unpin,
T: Unpin,
impl<T: ?Sized, Space> UnwindSafe for SmallBox<T, Space> where
Space: UnwindSafe,
T: RefUnwindSafe + UnwindSafe,
Space: UnwindSafe,
T: RefUnwindSafe + UnwindSafe,
impl<T: ?Sized, Space> RefUnwindSafe for SmallBox<T, Space> where
Space: RefUnwindSafe,
T: RefUnwindSafe,
Space: RefUnwindSafe,
T: RefUnwindSafe,
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,