Struct positioned_io_preview::Slice
source · pub struct Slice<I> { /* private fields */ }
Expand description
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]);
Implementations
Trait Implementations
sourceimpl<I: ReadAt> ReadAt for Slice<I>
impl<I: ReadAt> ReadAt for Slice<I>
sourceimpl<I: WriteAt> WriteAt for Slice<I>
impl<I: WriteAt> WriteAt for Slice<I>
Auto Trait Implementations
impl<I> RefUnwindSafe for Slice<I>where
I: RefUnwindSafe,
impl<I> Send for Slice<I>where
I: Send,
impl<I> Sync for Slice<I>where
I: Sync,
impl<I> Unpin for Slice<I>where
I: Unpin,
impl<I> UnwindSafe for Slice<I>where
I: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more