read_vectored in libstd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(()) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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