Macro smallvec::smallvec_inline

source ยท
macro_rules! smallvec_inline {
    (@one $x:expr) => { ... };
    ($elem:expr; $n:expr) => { ... };
    ($($x:expr),+ $(,)?) => { ... };
}
Expand description

Creates an inline SmallVec containing the arguments. This macro is enabled by the feature const_new.

smallvec_inline! allows SmallVecs to be defined with the same syntax as array expressions in const contexts. The inline storage A will always be an array of the size specified by the arguments. There are two forms of this macro:

  • Create a SmallVec containing a given list of elements:
const V: SmallVec<[i32; 3]> = smallvec_inline![1, 2, 3];
assert_eq!(V[0], 1);
assert_eq!(V[1], 2);
assert_eq!(V[2], 3);
  • Create a SmallVec from a given element and size:
const V: SmallVec<[i32; 3]> = smallvec_inline![1; 3];
assert_eq!(V, SmallVec::from_buf([1, 1, 1]));

Note that the behavior mimics that of array expressions, in contrast to smallvec.