arrayvec-util 0.1.0

Additional utilities for working with ArrayVec and ArrayString that make it more similar to the standard library
Documentation
use core::{fmt::Display, hint::black_box};

use arrayvec_util::ToArrayString;
use criterion::{Criterion, criterion_group, criterion_main};

pub fn criterion_benchmark(c: &mut Criterion) {
    struct EndWithExclamationMark(&'static str);

    impl Display for EndWithExclamationMark {
        fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
            write!(f, "{}!", self.0)
        }
    }

    let sentence = EndWithExclamationMark("The quick brown fox jumps over the lazy dog");

    c.bench_function("ToArrayString trait", |b| {
        b.iter(|| {
            black_box(sentence.to_array_string::<44>());
        })
    });

    c.bench_function("ToString trait", |b| {
        b.iter(|| {
            black_box(sentence.to_string());
        })
    });
}

criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);