Skip to content

Instantly share code, notes, and snippets.

@kubkon
Last active July 27, 2020 12:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kubkon/29861a275b9ac6a762d1d6eed1c10984 to your computer and use it in GitHub Desktop.
Save kubkon/29861a275b9ac6a762d1d6eed1c10984 to your computer and use it in GitHub Desktop.
read_vectored in libstd
use std::fs;
use std::io::{self, IoSliceMut, Read, Write, Seek, SeekFrom};
fn main() -> io::Result<()> {
let mut f = fs::OpenOptions::new()
.read(true)
.write(true)
.create(true)
.truncate(true)
.open("test.txt")?;
f.write_all(b"Hello!")?;
f.seek(SeekFrom::Start(0))?;
let buffer = &mut [0u8; 6];
let (mut first, mut second) = buffer.split_at_mut(3);
let iovecs = &mut [IoSliceMut::new(&mut first), IoSliceMut::new(&mut second)];
f.read_vectored(iovecs)?;
assert_eq!(b"Hello!", buffer, "buffers should be equal");
Ok(())
}
thread 'main' panicked at 'assertion failed: `(left == right)`
left: `[72, 101, 108, 108, 111, 33]`,
right: `[72, 101, 108, 0, 0, 0]`: buffers should be equal', src\main.rs:19:5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment