pub struct ReadSlice<P>where
P: PosRead,{ /* private fields */ }
Expand description
Re-implements Read
and Seek
over PosRead
using only positioned
reads, and by maintaining instance independent start, end, and position.
PosRead
is implemented for any Borrow<File>
so
this can own via ReadSlice<File>
or use a shared reference, as in
ReadSlice<&File>
or ReadSlice<Arc<File>>
.
As compared with ReadPos
, ReadSlice
adds a
general start offset, and limits access to the start..end range. Seeks are
relative, so a seek to SeekFrom::Start(0)
is always the first byte of
the slice.
Fixed start
and end
offsets are passed on construction and used to
constrain reads and interpret SeekFrom::Start
and SeekFrom::End
. These
offsets are neither checked against nor updated from the inner PosRead
(for example via file metadata) and could deviate if concurrent writes or
truncation is possible. Reads beyond end
or the end of the inner
PosRead
will return 0 length. Seeking past the end is allowed by the
platforms for File
, and is also allowed for ReadSlice
.
Implementations§
Source§impl<P> ReadSlice<P>where
P: PosRead,
impl<P> ReadSlice<P>where
P: PosRead,
Sourcepub fn new(pos_read: P, start: u64, end: u64) -> Self
pub fn new(pos_read: P, start: u64, end: u64) -> Self
New instance by PosRead
instance, fixed start and end offsets. The
initial position is at the start (relative offset 0).
Source§impl<P> ReadSlice<P>
impl<P> ReadSlice<P>
Sourcepub fn subslice(&self, start: u64, end: u64) -> ReadSlice<P> ⓘ
pub fn subslice(&self, start: u64, end: u64) -> ReadSlice<P> ⓘ
Return a new and independent ReadSlice
by clone of the inner
PosRead
, for the range of byte offsets start..end
which are
relative to, and must be fully contained by self. This implementation
panics on overflow, if start..end is not fully contained, or if
start is greater-than end.
Trait Implementations§
Source§impl<P> PosRead for ReadSlice<P>where
P: PosRead,
impl<P> PosRead for ReadSlice<P>where
P: PosRead,
Source§fn pread(&self, buf: &mut [u8], offset: u64) -> Result<usize>
fn pread(&self, buf: &mut [u8], offset: u64) -> Result<usize>
Source§impl<P> Read for ReadSlice<P>where
P: PosRead,
impl<P> Read for ReadSlice<P>where
P: PosRead,
Source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
1.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>
read
, except that it reads into a slice of buffers. Read moreSource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
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>
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>
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>
buf
. Read moreSource§fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)Source§fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)cursor
. Read more1.0.0 · Source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read
. Read moreSource§impl<P> Seek for ReadSlice<P>where
P: PosRead,
impl<P> Seek for ReadSlice<P>where
P: PosRead,
Source§fn seek(&mut self, from: SeekFrom) -> Result<u64>
fn seek(&mut self, from: SeekFrom) -> Result<u64>
Seek to an offset, in bytes, in a stream. In this implementation,
seeks are relative to the fixed start offset so a seek to
SeekFrom::Start(0)
is always the first byte of the slice.
1.55.0 · Source§fn rewind(&mut self) -> Result<(), Error>
fn rewind(&mut self) -> Result<(), Error>
Source§fn stream_len(&mut self) -> Result<u64, Error>
fn stream_len(&mut self) -> Result<u64, Error>
seek_stream_len
)Auto Trait Implementations§
impl<P> Freeze for ReadSlice<P>where
P: Freeze,
impl<P> RefUnwindSafe for ReadSlice<P>where
P: RefUnwindSafe,
impl<P> Send for ReadSlice<P>where
P: Send,
impl<P> Sync for ReadSlice<P>where
P: Sync,
impl<P> Unpin for ReadSlice<P>where
P: Unpin,
impl<P> UnwindSafe for ReadSlice<P>where
P: 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)