Skip to content

Instantly share code, notes, and snippets.

@kubkon
Last active Jul 27, 2020
Embed
What would you like to do?
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