pub struct Chain<R1: Read, R2: Read> { /* private fields */ }Expand description
Adapter to chain two readers together.
It might seem the exact same as std::io::Chain but it
is not. The difference is that when it reaches the end of
the first reader, it fills the rest of the buffer with
the first bytes from the second reader, what std::io::Chain
doesn’t do.
Implementations§
Trait Implementations§
Source§impl<R1: Read, R2: Read> Read for Chain<R1, R2>
impl<R1: Read, R2: Read> Read for Chain<R1, R2>
Source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
Pull some bytes from this source into the specified buffer, returning how many bytes were read.
Example:
use std::io::Read;
use fencryption_lib::io::Chain;
let text = "Never gonna give you up ! Never gonna let you down !";
let mut source = Chain::new([255u8; 41].as_ref(), text.as_bytes());
let mut buf = vec![0u8; 16];
loop {
let read_len = source.read(&mut buf).unwrap();
println!("{:x?} {}", &buf[..read_len], read_len);
if read_len != buf.len() {
break;
}
}Output:
[ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff] 16
[ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff] 16
[ff, ff, ff, ff, ff, ff, ff, ff, ff, 4e, 65, 76, 65, 72, 20, 67] 16
[6f, 6e, 6e, 61, 20, 67, 69, 76, 65, 20, 79, 6f, 75, 20, 75, 70] 16
[20, 21, 20, 4e, 65, 76, 65, 72, 20, 67, 6f, 6e, 6e, 61, 20, 6c] 16
[65, 74, 20, 79, 6f, 75, 20, 64, 6f, 77, 6e, 20, 21] 131.36.0 · Source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
Like
read, except that it reads into a slice of buffers. Read moreSource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
🔬This is a nightly-only experimental API. (
can_vector)1.0.0 · Source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
Reads all bytes until EOF in this source, placing them into
buf. Read more1.0.0 · Source§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
Reads all bytes until EOF in this source, appending them to
buf. Read more1.6.0 · Source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
Reads the exact number of bytes required to fill
buf. Read moreSource§fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
🔬This is a nightly-only experimental API. (
read_buf)Pull some bytes from this source into the specified buffer. Read more
Source§fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
🔬This is a nightly-only experimental API. (
read_buf)Reads the exact number of bytes required to fill
cursor. Read more1.0.0 · Source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Creates a “by reference” adapter for this instance of
Read. Read more1.0.0 · Source§fn chain<R>(self, next: R) -> Chain<Self, R>
fn chain<R>(self, next: R) -> Chain<Self, R>
Creates an adapter which will chain this stream with another. Read more
Auto Trait Implementations§
impl<R1, R2> Freeze for Chain<R1, R2>
impl<R1, R2> RefUnwindSafe for Chain<R1, R2>where
R2: RefUnwindSafe,
R1: RefUnwindSafe,
impl<R1, R2> Send for Chain<R1, R2>
impl<R1, R2> Sync for Chain<R1, R2>
impl<R1, R2> Unpin for Chain<R1, R2>
impl<R1, R2> UnsafeUnpin for Chain<R1, R2>where
R2: UnsafeUnpin,
R1: UnsafeUnpin,
impl<R1, R2> UnwindSafe for Chain<R1, R2>where
R2: UnwindSafe,
R1: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more