How to log long array?


I am loading 500Kb Vec into memory and would like to print!() let’s say first 100 bytes. I’ve tried

print!("buf: ", buf.as_slice().take(100))

but it turns out that it would create Take struct with derived Debug, which will print the the original source plus limit. Any idea how to do it?

println!("buf: {:?}", &buf[..100]);

Ahh, I forgot about reference operator. Without ref, error message is not helpful:
the trait bound[u8]: std::marker::Sizedis not satisfied

Well, that works for most cases, but if array happen to be smaller, then:
thread 'tests::iterator' panicked at 'index 100 out of range for slice of length 10'

Ok, fixed it with:

println!("Read page[{}]: {:?}", buff.len(), &buff[..100.min(buff.len())]);