Struct positioned_io::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§
source§impl<I> Slice<I>
impl<I> Slice<I>
sourcepub fn new(io: I, offset: u64, size: Option<u64>) -> Self
pub fn new(io: I, offset: u64, size: Option<u64>) -> Self
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.
sourcepub fn into_inner(self) -> I
pub fn into_inner(self) -> I
Consumes the slice, returning the underlying value.
sourcepub fn get_ref(&self) -> &I
pub fn get_ref(&self) -> &I
Get a reference to the underlying value in this slice.
Note that IO on the returned value may escape the slice.
sourcepub fn get_mut(&mut self) -> &mut I
pub fn get_mut(&mut self) -> &mut I
Get a mutable reference to the underlying value in this slice.
Note that IO on the returned value may escape the slice.
sourcepub fn set_offset(&mut self, offset: u64)
pub fn set_offset(&mut self, offset: u64)
Set the offset that this slice starts at within the underlying IO.
Trait Implementations§
source§impl<I: ReadAt> ReadAt for Slice<I>
impl<I: ReadAt> ReadAt for Slice<I>
source§impl<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§
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<R> ReadBytesAtExt for Rwhere
R: ReadAt,
impl<R> ReadBytesAtExt for Rwhere R: ReadAt,
source§fn read_u16_at<T: ByteOrder>(&self, pos: u64) -> Result<u16>
fn read_u16_at<T: ByteOrder>(&self, pos: u64) -> Result<u16>
Reads an unsigned 16-bit integer at an offset.
source§fn read_i16_at<T: ByteOrder>(&self, pos: u64) -> Result<i16>
fn read_i16_at<T: ByteOrder>(&self, pos: u64) -> Result<i16>
Reads a signed 16-bit integer at an offset.
source§fn read_u32_at<T: ByteOrder>(&self, pos: u64) -> Result<u32>
fn read_u32_at<T: ByteOrder>(&self, pos: u64) -> Result<u32>
Reads an unsigned 32-bit integer at an offset.
source§fn read_i32_at<T: ByteOrder>(&self, pos: u64) -> Result<i32>
fn read_i32_at<T: ByteOrder>(&self, pos: u64) -> Result<i32>
Reads a signed 32-bit integer at an offset.
source§fn read_u64_at<T: ByteOrder>(&self, pos: u64) -> Result<u64>
fn read_u64_at<T: ByteOrder>(&self, pos: u64) -> Result<u64>
Reads an unsigned 64-bit integer at an offset.
source§fn read_i64_at<T: ByteOrder>(&self, pos: u64) -> Result<i64>
fn read_i64_at<T: ByteOrder>(&self, pos: u64) -> Result<i64>
Reads a signed 64-bit integer at an offset.
source§fn read_uint_at<T: ByteOrder>(&self, pos: u64, nbytes: usize) -> Result<u64>
fn read_uint_at<T: ByteOrder>(&self, pos: u64, nbytes: usize) -> Result<u64>
Reads an unsigned
nbytes
-bit integer at an offset.source§fn read_int_at<T: ByteOrder>(&self, pos: u64, nbytes: usize) -> Result<i64>
fn read_int_at<T: ByteOrder>(&self, pos: u64, nbytes: usize) -> Result<i64>
Reads a signed
nbytes
-bit integer at an offset.source§impl<W> WriteBytesAtExt for Wwhere
W: WriteAt,
impl<W> WriteBytesAtExt for Wwhere W: WriteAt,
source§fn write_u8_at(&mut self, pos: u64, n: u8) -> Result<()>
fn write_u8_at(&mut self, pos: u64, n: u8) -> Result<()>
Writes an unsigned 8-bit integer to an offset.
source§fn write_i8_at(&mut self, pos: u64, n: i8) -> Result<()>
fn write_i8_at(&mut self, pos: u64, n: i8) -> Result<()>
Writes a signed 8-bit integer to an offset.
source§fn write_u16_at<T: ByteOrder>(&mut self, pos: u64, n: u16) -> Result<()>
fn write_u16_at<T: ByteOrder>(&mut self, pos: u64, n: u16) -> Result<()>
Writes an unsigned 16-bit integer to an offset.
source§fn write_i16_at<T: ByteOrder>(&mut self, pos: u64, n: i16) -> Result<()>
fn write_i16_at<T: ByteOrder>(&mut self, pos: u64, n: i16) -> Result<()>
Writes a signed 16-bit integer to an offset.
source§fn write_u32_at<T: ByteOrder>(&mut self, pos: u64, n: u32) -> Result<()>
fn write_u32_at<T: ByteOrder>(&mut self, pos: u64, n: u32) -> Result<()>
Writes an unsigned 32-bit integer to an offset.
source§fn write_i32_at<T: ByteOrder>(&mut self, pos: u64, n: i32) -> Result<()>
fn write_i32_at<T: ByteOrder>(&mut self, pos: u64, n: i32) -> Result<()>
Writes a signed 32-bit integer to an offset.
source§fn write_u64_at<T: ByteOrder>(&mut self, pos: u64, n: u64) -> Result<()>
fn write_u64_at<T: ByteOrder>(&mut self, pos: u64, n: u64) -> Result<()>
Writes an unsigned 64-bit integer to an offset.
source§fn write_i64_at<T: ByteOrder>(&mut self, pos: u64, n: i64) -> Result<()>
fn write_i64_at<T: ByteOrder>(&mut self, pos: u64, n: i64) -> Result<()>
Writes a signed 64-bit integer to an offset.
source§fn write_uint_at<T: ByteOrder>(
&mut self,
pos: u64,
n: u64,
nbytes: usize
) -> Result<()>
fn write_uint_at<T: ByteOrder>( &mut self, pos: u64, n: u64, nbytes: usize ) -> Result<()>
Writes an unsigned
nbytes
-bit integer to an offset.source§fn write_int_at<T: ByteOrder>(
&mut self,
pos: u64,
n: i64,
nbytes: usize
) -> Result<()>
fn write_int_at<T: ByteOrder>( &mut self, pos: u64, n: i64, nbytes: usize ) -> Result<()>
Writes a signed
nbytes
-bit integer to an offset.