pub struct PrefixedReadIo<I, P> { /* private fields */ }
Expand description
PrefixedReadIO facilitates the addition of a prefix to an IO stream, enabling stream rewinding and peeking capabilities. Subsequent reads will preserve access to the original stream contents.
async fn demo<T>(mut stream: T)
where
T: AsyncReadRent + AsyncWriteRent,
{
// let stream = b"hello world";
let buf = vec![0 as u8; 6];
let (_, buf) = stream.read_exact(buf).await;
assert_eq!(buf, b"hello ");
let prefix_buf = std::io::Cursor::new(buf);
let mut pio = PrefixedReadIo::new(stream, prefix_buf);
let buf = vec![0 as u8; 11];
let (_, buf) = pio.read_exact(buf).await;
assert_eq!(buf, b"hello world");
}
Implementations§
Source§impl<I, P> PrefixedReadIo<I, P>
impl<I, P> PrefixedReadIo<I, P>
Sourcepub const fn prefix_finished(&self) -> bool
pub const fn prefix_finished(&self) -> bool
If the prefix has read to eof
Sourcepub fn into_inner(self) -> I
pub fn into_inner(self) -> I
Into inner
Trait Implementations§
Source§impl<I: AsyncReadRent, P: Read> AsyncReadRent for PrefixedReadIo<I, P>
impl<I: AsyncReadRent, P: Read> AsyncReadRent for PrefixedReadIo<I, P>
Source§impl<I: AsyncWriteRent, P> AsyncWriteRent for PrefixedReadIo<I, P>
impl<I: AsyncWriteRent, P> AsyncWriteRent for PrefixedReadIo<I, P>
Source§fn write<T: IoBuf>(
&mut self,
buf: T,
) -> impl Future<Output = BufResult<usize, T>>
fn write<T: IoBuf>( &mut self, buf: T, ) -> impl Future<Output = BufResult<usize, T>>
Writes the contents of a buffer into this writer, returning the number of bytes written. Read more
Source§fn writev<T: IoVecBuf>(
&mut self,
buf_vec: T,
) -> impl Future<Output = BufResult<usize, T>>
fn writev<T: IoVecBuf>( &mut self, buf_vec: T, ) -> impl Future<Output = BufResult<usize, T>>
This function attempts to write the entire contents of
buf_vec
, but the write may not
fully succeed, and it might also result in an error. The bytes will be written starting at
the specified offset. Read moreSource§impl<I: CancelableAsyncReadRent, P: Read> CancelableAsyncReadRent for PrefixedReadIo<I, P>
impl<I: CancelableAsyncReadRent, P: Read> CancelableAsyncReadRent for PrefixedReadIo<I, P>
Source§async fn cancelable_read<T: IoBufMut>(
&mut self,
buf: T,
c: CancelHandle,
) -> BufResult<usize, T>
async fn cancelable_read<T: IoBufMut>( &mut self, buf: T, c: CancelHandle, ) -> BufResult<usize, T>
Same as read(2)
Source§async fn cancelable_readv<T: IoVecBufMut>(
&mut self,
buf: T,
c: CancelHandle,
) -> BufResult<usize, T>
async fn cancelable_readv<T: IoVecBufMut>( &mut self, buf: T, c: CancelHandle, ) -> BufResult<usize, T>
Same as readv(2)
Source§impl<I: CancelableAsyncWriteRent, P> CancelableAsyncWriteRent for PrefixedReadIo<I, P>
impl<I: CancelableAsyncWriteRent, P> CancelableAsyncWriteRent for PrefixedReadIo<I, P>
Source§fn cancelable_write<T: IoBuf>(
&mut self,
buf: T,
c: CancelHandle,
) -> impl Future<Output = BufResult<usize, T>>
fn cancelable_write<T: IoBuf>( &mut self, buf: T, c: CancelHandle, ) -> impl Future<Output = BufResult<usize, T>>
Same as write(2)
Source§fn cancelable_writev<T: IoVecBuf>(
&mut self,
buf_vec: T,
c: CancelHandle,
) -> impl Future<Output = BufResult<usize, T>>
fn cancelable_writev<T: IoVecBuf>( &mut self, buf_vec: T, c: CancelHandle, ) -> impl Future<Output = BufResult<usize, T>>
Same as writev(2)
Source§fn cancelable_flush(
&mut self,
c: CancelHandle,
) -> impl Future<Output = Result<()>>
fn cancelable_flush( &mut self, c: CancelHandle, ) -> impl Future<Output = Result<()>>
Flush buffered data if needed
Source§fn cancelable_shutdown(
&mut self,
c: CancelHandle,
) -> impl Future<Output = Result<()>>
fn cancelable_shutdown( &mut self, c: CancelHandle, ) -> impl Future<Output = Result<()>>
Same as shutdown
impl<I, P> Split for PrefixedReadIo<I, P>where
I: Split,
implement unsafe Split for PrefixedReadIo, it’s safe
because read/write are independent, we can safely split them into two I/O parts.
Auto Trait Implementations§
impl<I, P> Freeze for PrefixedReadIo<I, P>
impl<I, P> RefUnwindSafe for PrefixedReadIo<I, P>where
I: RefUnwindSafe,
P: RefUnwindSafe,
impl<I, P> Send for PrefixedReadIo<I, P>
impl<I, P> Sync for PrefixedReadIo<I, P>
impl<I, P> Unpin for PrefixedReadIo<I, P>
impl<I, P> UnwindSafe for PrefixedReadIo<I, P>where
I: UnwindSafe,
P: UnwindSafe,
Blanket Implementations§
Source§impl<A> AsyncReadRentExt for Awhere
A: AsyncReadRent + ?Sized,
impl<A> AsyncReadRentExt for Awhere
A: AsyncReadRent + ?Sized,
Source§async fn read_exact<T>(&mut self, buf: T) -> (Result<usize, Error>, T)where
T: IoBufMut + 'static,
async fn read_exact<T>(&mut self, buf: T) -> (Result<usize, Error>, T)where
T: IoBufMut + 'static,
Read until buf capacity is fulfilled
Source§async fn read_vectored_exact<T>(&mut self, buf: T) -> (Result<usize, Error>, T)where
T: IoVecBufMut + 'static,
async fn read_vectored_exact<T>(&mut self, buf: T) -> (Result<usize, Error>, T)where
T: IoVecBufMut + 'static,
Readv until buf capacity is fulfilled
Source§impl<A> AsyncWriteRentExt for Awhere
A: AsyncWriteRent + ?Sized,
impl<A> AsyncWriteRentExt for Awhere
A: AsyncWriteRent + ?Sized,
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
Source§impl<A> CancelableAsyncReadRentExt for Awhere
A: CancelableAsyncReadRent + ?Sized,
impl<A> CancelableAsyncReadRentExt for Awhere
A: CancelableAsyncReadRent + ?Sized,
Source§async fn cancelable_read_exact<T>(
&mut self,
buf: T,
c: CancelHandle,
) -> (Result<usize, Error>, T)where
T: IoBufMut + 'static,
async fn cancelable_read_exact<T>(
&mut self,
buf: T,
c: CancelHandle,
) -> (Result<usize, Error>, T)where
T: IoBufMut + 'static,
Read until buf capacity is fulfilled
Source§async fn cancelable_read_vectored_exact<T>(
&mut self,
buf: T,
c: CancelHandle,
) -> (Result<usize, Error>, T)where
T: IoVecBufMut + 'static,
async fn cancelable_read_vectored_exact<T>(
&mut self,
buf: T,
c: CancelHandle,
) -> (Result<usize, Error>, T)where
T: IoVecBufMut + 'static,
Readv until buf capacity is fulfilled
Source§async fn cancelable_read_u8(&mut self, c: CancelHandle) -> Result<u8, Error>
async fn cancelable_read_u8(&mut self, c: CancelHandle) -> Result<u8, Error>
Read number in async way
Source§async fn cancelable_read_u16(&mut self, c: CancelHandle) -> Result<u16, Error>
async fn cancelable_read_u16(&mut self, c: CancelHandle) -> Result<u16, Error>
Read number in async way
Source§async fn cancelable_read_u32(&mut self, c: CancelHandle) -> Result<u32, Error>
async fn cancelable_read_u32(&mut self, c: CancelHandle) -> Result<u32, Error>
Read number in async way
Source§async fn cancelable_read_u64(&mut self, c: CancelHandle) -> Result<u64, Error>
async fn cancelable_read_u64(&mut self, c: CancelHandle) -> Result<u64, Error>
Read number in async way
Source§async fn cancelable_read_u128(&mut self, c: CancelHandle) -> Result<u128, Error>
async fn cancelable_read_u128(&mut self, c: CancelHandle) -> Result<u128, Error>
Read number in async way
Source§async fn cancelable_read_i8(&mut self, c: CancelHandle) -> Result<i8, Error>
async fn cancelable_read_i8(&mut self, c: CancelHandle) -> Result<i8, Error>
Read number in async way
Source§async fn cancelable_read_i16(&mut self, c: CancelHandle) -> Result<i16, Error>
async fn cancelable_read_i16(&mut self, c: CancelHandle) -> Result<i16, Error>
Read number in async way
Source§async fn cancelable_read_i32(&mut self, c: CancelHandle) -> Result<i32, Error>
async fn cancelable_read_i32(&mut self, c: CancelHandle) -> Result<i32, Error>
Read number in async way
Source§async fn cancelable_read_i64(&mut self, c: CancelHandle) -> Result<i64, Error>
async fn cancelable_read_i64(&mut self, c: CancelHandle) -> Result<i64, Error>
Read number in async way
Source§async fn cancelable_read_i128(&mut self, c: CancelHandle) -> Result<i128, Error>
async fn cancelable_read_i128(&mut self, c: CancelHandle) -> Result<i128, Error>
Read number in async way
Source§async fn cancelable_read_f32(&mut self, c: CancelHandle) -> Result<f32, Error>
async fn cancelable_read_f32(&mut self, c: CancelHandle) -> Result<f32, Error>
Read number in async way
Source§async fn cancelable_read_f64(&mut self, c: CancelHandle) -> Result<f64, Error>
async fn cancelable_read_f64(&mut self, c: CancelHandle) -> Result<f64, Error>
Read number in async way
Source§async fn cancelable_read_u8_le(&mut self, c: CancelHandle) -> Result<u8, Error>
async fn cancelable_read_u8_le(&mut self, c: CancelHandle) -> Result<u8, Error>
Read number in async way
Source§async fn cancelable_read_u16_le(
&mut self,
c: CancelHandle,
) -> Result<u16, Error>
async fn cancelable_read_u16_le( &mut self, c: CancelHandle, ) -> Result<u16, Error>
Read number in async way
Source§async fn cancelable_read_u32_le(
&mut self,
c: CancelHandle,
) -> Result<u32, Error>
async fn cancelable_read_u32_le( &mut self, c: CancelHandle, ) -> Result<u32, Error>
Read number in async way
Source§async fn cancelable_read_u64_le(
&mut self,
c: CancelHandle,
) -> Result<u64, Error>
async fn cancelable_read_u64_le( &mut self, c: CancelHandle, ) -> Result<u64, Error>
Read number in async way
Source§async fn cancelable_read_u128_le(
&mut self,
c: CancelHandle,
) -> Result<u128, Error>
async fn cancelable_read_u128_le( &mut self, c: CancelHandle, ) -> Result<u128, Error>
Read number in async way
Source§async fn cancelable_read_i8_le(&mut self, c: CancelHandle) -> Result<i8, Error>
async fn cancelable_read_i8_le(&mut self, c: CancelHandle) -> Result<i8, Error>
Read number in async way
Source§async fn cancelable_read_i16_le(
&mut self,
c: CancelHandle,
) -> Result<i16, Error>
async fn cancelable_read_i16_le( &mut self, c: CancelHandle, ) -> Result<i16, Error>
Read number in async way
Source§async fn cancelable_read_i32_le(
&mut self,
c: CancelHandle,
) -> Result<i32, Error>
async fn cancelable_read_i32_le( &mut self, c: CancelHandle, ) -> Result<i32, Error>
Read number in async way
Source§async fn cancelable_read_i64_le(
&mut self,
c: CancelHandle,
) -> Result<i64, Error>
async fn cancelable_read_i64_le( &mut self, c: CancelHandle, ) -> Result<i64, Error>
Read number in async way
Source§async fn cancelable_read_i128_le(
&mut self,
c: CancelHandle,
) -> Result<i128, Error>
async fn cancelable_read_i128_le( &mut self, c: CancelHandle, ) -> Result<i128, Error>
Read number in async way
Source§async fn cancelable_read_f32_le(
&mut self,
c: CancelHandle,
) -> Result<f32, Error>
async fn cancelable_read_f32_le( &mut self, c: CancelHandle, ) -> Result<f32, Error>
Read number in async way
Source§async fn cancelable_read_f64_le(
&mut self,
c: CancelHandle,
) -> Result<f64, Error>
async fn cancelable_read_f64_le( &mut self, c: CancelHandle, ) -> Result<f64, Error>
Read number in async way
Source§impl<A> CancelableAsyncWriteRentExt for Awhere
A: CancelableAsyncWriteRent + ?Sized,
impl<A> CancelableAsyncWriteRentExt for Awhere
A: CancelableAsyncWriteRent + ?Sized,
Source§impl<T> Splitable for Twhere
T: Split + AsyncWriteRent,
impl<T> Splitable for Twhere
T: Split + AsyncWriteRent,
Source§type OwnedRead = OwnedReadHalf<T>
type OwnedRead = OwnedReadHalf<T>
Owned Read Split
Source§type OwnedWrite = OwnedWriteHalf<T>
type OwnedWrite = OwnedWriteHalf<T>
Owned Write Split
Source§fn into_split(
self,
) -> (<T as Splitable>::OwnedRead, <T as Splitable>::OwnedWrite)
fn into_split( self, ) -> (<T as Splitable>::OwnedRead, <T as Splitable>::OwnedWrite)
Split into owned parts