[−][src]Struct positioned_io_preview::Slice
A window into another ReadAt
or WriteAt
.
Given an existing positioned I/O, this presents a limited view of it.
Examples
Some slices have size restrictions:
use positioned_io::{ReadAt, Slice}; let a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; let slice = Slice::new(&a[..], 4, Some(4)); let mut buf = [0; 4]; let bytes = slice.read_at(2, &mut buf)?; assert_eq!(bytes, 2); assert_eq!(buf, [6, 7, 0, 0]);
Some slices do not:
use positioned_io::{WriteAt, Slice}; let mut v = vec![0, 1, 2, 3, 4, 5]; let buf = [9; 3]; { let mut slice = Slice::new(&mut v, 2, None); slice.write_all_at(3, &buf)?; } // The write goes right past the end. assert_eq!(v, vec![0, 1, 2, 3, 4, 9, 9, 9]);
Methods
impl<I> Slice<I>
[src]
pub fn new(io: I, offset: u64, size: Option<u64>) -> Self
[src]
Create a new Slice
.
The slice will be a view of size
bytes, starting at offset
in io
.
If you do not pass a size, the size won't be limited.
impl<I: Size> Slice<I>
[src]
pub fn new_to_end(io: I, offset: u64) -> Result<Self>
[src]
Create a new Slice
that goes to the end of io
.
Note that you can create a larger slice by passing a larger size to
new()
, but it won't do you any good for reading.
Trait Implementations
impl<I: ReadAt> ReadAt for Slice<I>
[src]
fn read_at(&self, pos: u64, buf: &mut [u8]) -> Result<usize>
[src]
fn read_exact_at(&self, pos: u64, buf: &mut [u8]) -> Result<()>
[src]
Reads the exact number of bytes required to fill buf
from an offset. Read more
impl<I: WriteAt> WriteAt for Slice<I>
[src]
fn write_at(&mut self, pos: u64, buf: &[u8]) -> Result<usize>
[src]
fn flush(&mut self) -> Result<()>
[src]
fn write_all_at(&mut self, pos: u64, buf: &[u8]) -> Result<()>
[src]
Writes a complete buffer at an offset. Read more
impl<I> Size for Slice<I>
[src]
impl<I: Clone> Clone for Slice<I>
[src]
fn clone(&self) -> Slice<I>
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl<I: Debug> Debug for Slice<I>
[src]
Auto Trait Implementations
Blanket Implementations
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
impl<T> From for T
[src]
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,