pub struct BlockedVec { /* private fields */ }Expand description
A vector of blocks.
See the module documentation for details.
Implementations§
Source§impl BlockedVec
impl BlockedVec
Sourcepub fn new_paged(page_layout: Layout) -> Self
pub fn new_paged(page_layout: Layout) -> Self
Creates a new BlockedVec with a given page layout.
Sourcepub fn with_len(len: usize) -> Self
pub fn with_len(len: usize) -> Self
Creates a new BlockedVec with an initial length, with the cursor
placed at the front.
§Panics
Panics if the queried page size cannot be made into a layout.
Sourcepub fn with_len_paged(len: usize, page_layout: Layout) -> Self
pub fn with_len_paged(len: usize, page_layout: Layout) -> Self
Creates a new BlockedVec with a given page layout and an initial
length, with the cursor placed at the front.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the length of this BlockedVec.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Checks if this BlockedVec is empty.
Sourcepub fn extend(&mut self, additional: usize)
pub fn extend(&mut self, additional: usize)
Extend the BlockedVec, with the possible additional areas filled with
zero.
§Panics
Panics if the seeker or blocks are inconsistent.
Sourcepub fn append_vectored(&mut self, buf: &mut [impl IoSlice<'_>]) -> usize
pub fn append_vectored(&mut self, buf: &mut [impl IoSlice<'_>]) -> usize
Sourcepub fn read_vectored(&mut self, buf: &mut [impl IoSliceMut<'_>]) -> usize
pub fn read_vectored(&mut self, buf: &mut [impl IoSliceMut<'_>]) -> usize
Like read, except that it reads into a slice of buffers.
Sourcepub fn read_at_vectored(
&self,
pos: usize,
buf: &mut [impl IoSliceMut<'_>],
) -> usize
pub fn read_at_vectored( &self, pos: usize, buf: &mut [impl IoSliceMut<'_>], ) -> usize
Like read_at, except that it reads into a slice of buffers.
Sourcepub fn read(&mut self, buf: &mut [u8]) -> usize
pub fn read(&mut self, buf: &mut [u8]) -> usize
Pull some bytes from this BlockedVec into the specified buffer,
returning how many bytes were read.
Sourcepub fn read_at(&self, pos: usize, buf: &mut [u8]) -> usize
pub fn read_at(&self, pos: usize, buf: &mut [u8]) -> usize
Pull some bytes from this BlockedVec into the specified buffer at a
specified position, returning how many bytes were read.
Sourcepub fn write_vectored(&mut self, buf: &mut [impl IoSlice<'_>]) -> usize
pub fn write_vectored(&mut self, buf: &mut [impl IoSlice<'_>]) -> usize
Like write, except that it writes from a slice of buffers.
Sourcepub fn write_at_vectored(
&mut self,
pos: usize,
buf: &mut [impl IoSlice<'_>],
) -> usize
pub fn write_at_vectored( &mut self, pos: usize, buf: &mut [impl IoSlice<'_>], ) -> usize
Like write_at, except that it writes from a slice of buffers.
Sourcepub fn write(&mut self, buf: &[u8]) -> usize
pub fn write(&mut self, buf: &[u8]) -> usize
Write a buffer into this writer, returning how many bytes were written.
Sourcepub fn write_at(&mut self, pos: usize, buf: &[u8]) -> usize
pub fn write_at(&mut self, pos: usize, buf: &[u8]) -> usize
Write a buffer into this writer at a specified position, returning how many bytes were written.
Sourcepub fn seek(&mut self, pos: SeekFrom) -> Option<usize>
pub fn seek(&mut self, pos: SeekFrom) -> Option<usize>
Seek to an offset, in bytes, in this BlockedVec.
Sourcepub fn truncate(&mut self, len: usize) -> bool
pub fn truncate(&mut self, len: usize) -> bool
Shortens this BlockedVec to the specified length.
Sourcepub fn resize(&mut self, new_len: usize)
pub fn resize(&mut self, new_len: usize)
Resizes the BlockedVec in-place so that len is equal to new_len,
with the possible additional area filled with zero.
Sourcepub fn iter_mut(&mut self) -> BlockIterMut<'_>
pub fn iter_mut(&mut self) -> BlockIterMut<'_>
Returns the mutable iterator of blocks (i.e. byte slices).
Sourcepub fn bytes(&self) -> impl Iterator<Item = u8> + Clone + Debug + '_
pub fn bytes(&self) -> impl Iterator<Item = u8> + Clone + Debug + '_
Returns every byte of this BlockedVec.
Sourcepub fn range<R>(&self, range: R) -> RangeIter<'_>where
R: RangeBounds<usize>,
pub fn range<R>(&self, range: R) -> RangeIter<'_>where
R: RangeBounds<usize>,
Returns the iterator of blocks (i.e. byte slices) in a selected range.
The possible blocks parts that are out of range are not returned.
§Examples
use std::alloc::Layout;
use blocked_vec::BlockedVec;
let layout = Layout::new::<[u8; 4]>();
// Allocated 4 pages at one time, thus continuous.
let vec = BlockedVec::with_len_paged(16, layout);
let mut range = vec.range(7..14);
assert_eq!(range.next(), Some(&[0u8; 7] as &[u8]));
assert_eq!(range.next(), None);
// Allocated 4 pages independently, thus discrete.
let mut vec = BlockedVec::with_len_paged(4, layout);
vec.append(&[1; 4]);
vec.append(&[2; 4]);
vec.append(&[3; 4]);
let mut range = vec.range(7..14);
assert_eq!(range.next(), Some(&[1u8; 1] as &[u8]));
assert_eq!(range.next(), Some(&[2u8; 4] as &[u8]));
assert_eq!(range.next(), Some(&[3u8; 2] as &[u8]));
assert_eq!(range.next(), None);Sourcepub fn range_mut<R>(&mut self, range: R) -> RangeIterMut<'_>where
R: RangeBounds<usize>,
pub fn range_mut<R>(&mut self, range: R) -> RangeIterMut<'_>where
R: RangeBounds<usize>,
Returns the mutable iterator of blocks (i.e. byte slices) in a selected range.
The possible blocks parts that are out of range are not returned.
§Examples
use std::alloc::Layout;
use blocked_vec::BlockedVec;
let layout = Layout::new::<[u8; 4]>();
// Allocated 4 pages at one time, thus continuous.
let mut vec = BlockedVec::with_len_paged(16, layout);
let mut range = vec.range_mut(7..14);
assert_eq!(range.next(), Some(&mut [0u8; 7] as &mut [u8]));
assert_eq!(range.next(), None);
// Allocated 4 pages independently, thus discrete.
let mut vec = BlockedVec::with_len_paged(4, layout);
vec.append(&[1; 4]);
vec.append(&[2; 4]);
vec.append(&[3; 4]);
let mut range = vec.range_mut(7..14);
assert_eq!(range.next(), Some(&mut [1u8; 1] as &mut [u8]));
assert_eq!(range.next(), Some(&mut [2u8; 4] as &mut [u8]));
assert_eq!(range.next(), Some(&mut [3u8; 2] as &mut [u8]));
assert_eq!(range.next(), None);Trait Implementations§
Source§impl Clone for BlockedVec
impl Clone for BlockedVec
Source§impl Debug for BlockedVec
impl Debug for BlockedVec
Source§impl Default for BlockedVec
Available on crate feature std only.
impl Default for BlockedVec
std only.Source§impl Read for BlockedVec
Available on crate feature std only.
impl Read for BlockedVec
std only.Source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
Source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize>
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 more1.0.0 · Source§fn chain<R>(self, next: R) -> Chain<Self, R>
fn chain<R>(self, next: R) -> Chain<Self, R>
Source§impl Seek for BlockedVec
Available on crate feature std only.
impl Seek for BlockedVec
std only.Source§fn seek(&mut self, pos: SeekFrom) -> Result<u64>
fn seek(&mut self, pos: SeekFrom) -> Result<u64>
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)Source§impl Write for BlockedVec
Available on crate feature std only.
impl Write for BlockedVec
std only.Source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
Source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
Source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector)1.0.0 · Source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
Source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored)