Skip to main content

buf

Macro buf 

Source
macro_rules! buf {
    ($cap:expr; $($element:expr),*) => { ... };
    ($($element:expr),*) => { ... };
}
Expand description

Creates a Buffer containing the given arguments.

buf! allows shorthand initialization of a buffer. It supports two syntax variants:

  1. Specifying the capacity explicitly as a macro argument.
  2. Allowing the capacity to be inferred by the compiler.

§Examples

Creating a buffer with an explicit fixed capacity via the macro argument:

let b = buf![10; 1, 2];

Creating a buffer where the capacity and type are inferred from the context:

let b: Buffer<i32, 5> = buf![1, 2, 3];
assert_eq!(b.len(), 3);

§Panics

This macro will panic at runtime if the number of passed elements exceeds the allocated capacity.