pub trait ReadBuffer: ReadBufferRef {
// Provided method
fn read_buffer<'d, B: Buffer<'d>>(&mut self, buf: B) -> Result<&'d [u8]> { ... }
}Expand description
Trait to read to T: Buffer.
This trait should be imported to read into buffers.
Provided Methods§
Sourcefn read_buffer<'d, B: Buffer<'d>>(&mut self, buf: B) -> Result<&'d [u8]>
fn read_buffer<'d, B: Buffer<'d>>(&mut self, buf: B) -> Result<&'d [u8]>
Reads (equivalently to Read::read) into the buffer and returns the
newly read bytes.
Examples found in repository?
examples/example.rs (line 18)
8fn main() {
9 let filename = env::temp_dir().join("rust_buffer_test.txt");
10 {
11 let mut f = File::create(&filename).unwrap();
12 f.write(&[1; 256]).unwrap();
13 }
14 {
15 let mut contents = Vec::with_capacity(1);
16 let mut f = File::open(&filename).unwrap();
17 loop {
18 let len = f.read_buffer(&mut contents).unwrap().len();
19 println!("{:3} {:3}/{:3}", len, contents.len(), contents.capacity());
20 if len == 0 {
21 break;
22 }
23 if contents.len() == contents.capacity() {
24 let len = contents.len();
25 contents.reserve(len);
26 }
27 }
28 }
29}Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.