Is giving Iter<_,u8> to a function more efficient than &[u8]?

⚓ Rust    📅 2026-01-05    👤 surdeus    👁️ 4      

surdeus

Hi everyone,
I'm working on a crate to extract informations from midi file ( which is an hex file). I made a first version of the crate where I give an &[u8] (representing data in midi file) to different functions, one extracting header, another tracks.

Every time I call a different function I shift the starting point of the slice:

pub fn open(path: &str) -> std::io::Result<()> {
    let data = fs::read(path)?;

    let _header = Header::extract(&data);
    let _track = Track::extract(&data[14..]); //Header length is always 14 bytes

    drop(data);

    Ok(())
}

I was wondering if giving Iter< _, u8> to function would be more efficient than giving &[u8], as data are only read once.

4 posts - 4 participants

Read full topic

🏷️ Rust_feed