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 relaxing the constraint T: Sized
.
In order to do that, this macro will check the coersion rules from type T
to
the target type. This macro will invoke a complie-time error on any invalid type coersion.
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::space::*;
use smallbox::SmallBox;
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);