Smallbytes
SmallBytes = SmallVec + impl BufMut (from the bytes crate)
use SmallBytes;
use BufMut;
// initialize a buffer with inline capacity of 6 bytes
let mut buf = new;
// the first word fits inline (stack)
buf.put;
// the rest does not, so the contents are moved to the heap
buf.put;
buf.put_u16;
assert_eq!;
The size of a SmallBytes object is at least 24 bytes (pointer, length, capacity) similar to a Vec. This means you can always store 16 bytes on the stack for free.
use size_of;
use SmallBytes;
assert_eq!; // zero bytes on the stack, don't do this
assert_eq!; // 8 bytes on the stack
assert_eq!; // 16 bytes on the stack (ideal minimum)
assert_eq!; // 24 bytes on the stack (stack size increases)