smallbox

Macro smallbox 

Source
macro_rules! smallbox {
    ( $e: expr ) => { ... };
}
Expand description

Box value on stack or on heap depending on its size

This macro is similar to SmallBox::new, which is used to create a new SmallBox instance, but relaxes the constraint T: Sized. In order to do that, this macro will check the coercion rules from type T to the target type. This macro will invoke a compile-time error on any invalid type coercion.

You can think that it has the signature of smallbox!<U: Sized, T: ?Sized>(val: U) -> SmallBox<T, Space>

ยงExample

#[macro_use]
extern crate smallbox;

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

let small: SmallBox<[usize], S4> = smallbox!([0usize; 2]);
let large: SmallBox<[usize], S4> = smallbox!([1usize; 8]);

assert_eq!(small.len(), 2);
assert_eq!(large[7], 1);

assert!(large.is_heap() == true);