pub fn spare_capacity<'a, T>(v: &'a mut Vec<T>) -> SpareCapacity<'a, T>Expand description
Construct an SpareCapacity, which implements Buffer.
This wraps a Vec and uses the spare capacity of the Vec as the buffer
to receive data in, automatically calling set_len on the Vec to set the
length to include the received elements.
This uses the existing capacity, and never allocates, so the Vec should
have some non-empty spare capacity!
ยงExamples
use rustix::buffer::spare_capacity;
use rustix::io::{read, Errno};
let mut buf = Vec::with_capacity(1024);
match read(input, spare_capacity(&mut buf)) {
Ok(0) => { /* end of stream */ }
Ok(n) => { /* `buf` is now `n` bytes longer */ }
Err(Errno::INTR) => { /* `buf` is unmodified */ }
Err(e) => {
return Err(e);
}
}