Display
for Vecs and slicesslicedisplay
is a tiny no-std
crate which supplies the SliceDisplay
trait.
This trait extends &[T]
and Vec<T>
with the display
method, which allows formatting without heap allocations.
```rust use slicedisplay::SliceDisplay;
let empty: Vec
let single = Vec::from([1]); asserteq!(single.display().tostring(), "[1]");
let numbers = Vec::from([1, 2, 3, 4, 5]); asserteq!(numbers.display().tostring(), "[1, 2, 3, 4, 5]"); ```
It's also possible to slightly customize the display.
```rust use slicedisplay::SliceDisplay;
let hello: Vec<_> = "Hello".chars().collect(); asserteq!( hello.display().delimiter(';').tostring(), "[H; e; l; l; o]" ); asserteq!( hello.display().terminator('{', '}').tostring(), "{H, e, l, l, o}" ); asserteq!( hello .display() .terminator('(', ')') .delimiter(';') .tostring(), "(H; e; l; l; o)" ); ```