Struct simple_bytes::Offset

source ·
pub struct Offset<T> { /* private fields */ }
Expand description

A struct which holds a specific offset for any BytesRead, BytesWrite or BytesSeek implementation.

Example

let mut offset = Offset::new(BytesOwned::from(vec![1, 2, 3, 4]), 2);
assert_eq!(offset.as_slice(), &[3, 4]);
assert_eq!(offset.remaining(), &[3, 4]);
offset.write_u8(5);
assert_eq!(offset.as_slice(), &[5, 4]);
assert_eq!(offset.remaining(), &[4]);
offset.seek(2);
offset.write_u8(5);
assert_eq!(offset.as_slice(), &[5, 4, 5]);

Implementations§

source§

impl<T> Offset<T>

source

pub fn new(inner: T, offset: usize) -> Selfwhere T: BytesRead + BytesSeek,

Creates a new Cursor.

May panic if the offset is bigger than the inner len. Depending on inner.

source

pub fn set_offset(&mut self, offset: usize)where T: BytesSeek,

Updates the offset.

Maybe panic if there aren’t enough bytes left.

source

pub fn offset(&self) -> usize

Returns the current offset.

source

pub fn inner(&self) -> &T

Returns the inner value as a reference.

source

pub fn inner_mut(&mut self) -> &mut T

Returns the inner value as a mutable reference. Shrinking the inner len or updating the position may lead to panics when reading or writing.

source

pub fn into_inner(self) -> T

Returns the inner value, discarding the offset.

Trait Implementations§

source§

impl<T> BytesRead for Offset<T>where T: BytesRead,

source§

fn as_slice(&self) -> &[u8]

Returns the entire slice.
source§

fn remaining(&self) -> &[u8]

Returns all remaining bytes.
source§

fn try_read(&mut self, len: usize) -> Result<&[u8], ReadError>

Try to read a given length of bytes. Read more
source§

fn peek(&self, len: usize) -> Option<&[u8]>

Tries to read a given length without updating the internal position. Returns None if there are not enought bytes remaining.
source§

fn len(&self) -> usize

Returns the length of the entire slice.
source§

fn read(&mut self, len: usize) -> &[u8]

Reads a given length of bytes. Read more
source§

fn try_read_u8(&mut self) -> Result<u8, ReadError>

Try to read 1 bytes in big-endian converting them into an u8.
source§

fn read_u8(&mut self) -> u8

Reads 1 bytes in big-endian converting them into an u8. Read more
source§

fn try_read_u16(&mut self) -> Result<u16, ReadError>

Try to read 2 bytes in big-endian converting them into an u16.
source§

fn read_u16(&mut self) -> u16

Reads 2 bytes in big-endian converting them into an u16. Read more
source§

fn try_read_u32(&mut self) -> Result<u32, ReadError>

Try to read 4 bytes in big-endian converting them into an u32.
source§

fn read_u32(&mut self) -> u32

Reads 4 bytes in big-endian converting them into an u32. Read more
source§

fn try_read_u64(&mut self) -> Result<u64, ReadError>

Try to read 8 bytes in big-endian converting them into an u64.
source§

fn read_u64(&mut self) -> u64

Reads 8 bytes in big-endian converting them into an u64. Read more
source§

fn try_read_u128(&mut self) -> Result<u128, ReadError>

Try to read 16 bytes in big-endian converting them into an u128.
source§

fn read_u128(&mut self) -> u128

Reads 16 bytes in big-endian converting them into an u128. Read more
source§

fn try_read_i8(&mut self) -> Result<i8, ReadError>

Try to read 1 bytes in big-endian converting them into an i8.
source§

fn read_i8(&mut self) -> i8

Reads 1 bytes in big-endian converting them into an i8. Read more
source§

fn try_read_i16(&mut self) -> Result<i16, ReadError>

Try to read 2 bytes in big-endian converting them into an i16.
source§

fn read_i16(&mut self) -> i16

Reads 2 bytes in big-endian converting them into an i16. Read more
source§

fn try_read_i32(&mut self) -> Result<i32, ReadError>

Try to read 4 bytes in big-endian converting them into an i32.
source§

fn read_i32(&mut self) -> i32

Reads 4 bytes in big-endian converting them into an i32. Read more
source§

fn try_read_i64(&mut self) -> Result<i64, ReadError>

Try to read 8 bytes in big-endian converting them into an i64.
source§

fn read_i64(&mut self) -> i64

Reads 8 bytes in big-endian converting them into an i64. Read more
source§

fn try_read_i128(&mut self) -> Result<i128, ReadError>

Try to read 16 bytes in big-endian converting them into an i128.
source§

fn read_i128(&mut self) -> i128

Reads 16 bytes in big-endian converting them into an i128. Read more
source§

fn try_read_f32(&mut self) -> Result<f32, ReadError>

Try to read 4 bytes in big-endian converting them into an f32.
source§

fn read_f32(&mut self) -> f32

Reads 4 bytes in big-endian converting them into an f32. Read more
source§

fn try_read_f64(&mut self) -> Result<f64, ReadError>

Try to read 8 bytes in big-endian converting them into an f64.
source§

fn read_f64(&mut self) -> f64

Reads 8 bytes in big-endian converting them into an f64. Read more
source§

fn try_read_le_u8(&mut self) -> Result<u8, ReadError>

Try to read 1 bytes in little-endian converting them into an u8.
source§

fn read_le_u8(&mut self) -> u8

Reads 1 bytes in little-endian converting them into an u8. Read more
source§

fn try_read_le_u16(&mut self) -> Result<u16, ReadError>

Try to read 2 bytes in little-endian converting them into an u16.
source§

fn read_le_u16(&mut self) -> u16

Reads 2 bytes in little-endian converting them into an u16. Read more
source§

fn try_read_le_u32(&mut self) -> Result<u32, ReadError>

Try to read 4 bytes in little-endian converting them into an u32.
source§

fn read_le_u32(&mut self) -> u32

Reads 4 bytes in little-endian converting them into an u32. Read more
source§

fn try_read_le_u64(&mut self) -> Result<u64, ReadError>

Try to read 8 bytes in little-endian converting them into an u64.
source§

fn read_le_u64(&mut self) -> u64

Reads 8 bytes in little-endian converting them into an u64. Read more
source§

fn try_read_le_u128(&mut self) -> Result<u128, ReadError>

Try to read 16 bytes in little-endian converting them into an u128.
source§

fn read_le_u128(&mut self) -> u128

Reads 16 bytes in little-endian converting them into an u128. Read more
source§

fn try_read_le_i8(&mut self) -> Result<i8, ReadError>

Try to read 1 bytes in little-endian converting them into an i8.
source§

fn read_le_i8(&mut self) -> i8

Reads 1 bytes in little-endian converting them into an i8. Read more
source§

fn try_read_le_i16(&mut self) -> Result<i16, ReadError>

Try to read 2 bytes in little-endian converting them into an i16.
source§

fn read_le_i16(&mut self) -> i16

Reads 2 bytes in little-endian converting them into an i16. Read more
source§

fn try_read_le_i32(&mut self) -> Result<i32, ReadError>

Try to read 4 bytes in little-endian converting them into an i32.
source§

fn read_le_i32(&mut self) -> i32

Reads 4 bytes in little-endian converting them into an i32. Read more
source§

fn try_read_le_i64(&mut self) -> Result<i64, ReadError>

Try to read 8 bytes in little-endian converting them into an i64.
source§

fn read_le_i64(&mut self) -> i64

Reads 8 bytes in little-endian converting them into an i64. Read more
source§

fn try_read_le_i128(&mut self) -> Result<i128, ReadError>

Try to read 16 bytes in little-endian converting them into an i128.
source§

fn read_le_i128(&mut self) -> i128

Reads 16 bytes in little-endian converting them into an i128. Read more
source§

fn try_read_le_f32(&mut self) -> Result<f32, ReadError>

Try to read 4 bytes in little-endian converting them into an f32.
source§

fn read_le_f32(&mut self) -> f32

Reads 4 bytes in little-endian converting them into an f32. Read more
source§

fn try_read_le_f64(&mut self) -> Result<f64, ReadError>

Try to read 8 bytes in little-endian converting them into an f64.
source§

fn read_le_f64(&mut self) -> f64

Reads 8 bytes in little-endian converting them into an f64. Read more
source§

impl<T> BytesSeek for Offset<T>where T: BytesSeek,

source§

fn position(&self) -> usize

Returns the internal position.

source§

fn try_seek(&mut self, pos: usize) -> Result<(), SeekError>

Sets the internal position.

Panics

Depending on the implementation.

source§

fn seek(&mut self, pos: usize)

Sets the internal position.
source§

fn try_advance(&mut self, adv: usize) -> Result<(), SeekError>

Advances the internal position if possible.
source§

fn advance(&mut self, adv: usize)

Advances the internal position. Read more
source§

impl<T> BytesWrite for Offset<T>where T: BytesWrite,

source§

fn as_mut(&mut self) -> &mut [u8]

Returns the entire slice mutably.
source§

fn as_bytes(&self) -> Bytes<'_>

Returns the entire slice as a bytes struct setting the position of the new Bytes to 0.
source§

fn remaining_mut(&mut self) -> &mut [u8]

Returns the remaining bytes mutably.
source§

fn try_write(&mut self, slice: impl AsRef<[u8]>) -> Result<(), WriteError>

Writes a slice.
source§

fn write(&mut self, slice: impl AsRef<[u8]>)

Writes a slice. Read more
source§

fn try_write_u8(&mut self, num: u8) -> Result<(), WriteError>

Try to write u8 in big-endian.`
source§

fn write_u8(&mut self, num: u8)

Writes an u8 in big-endian. Read more
source§

fn try_write_u16(&mut self, num: u16) -> Result<(), WriteError>

Try to write u16 in big-endian.`
source§

fn write_u16(&mut self, num: u16)

Writes an u16 in big-endian. Read more
source§

fn try_write_u32(&mut self, num: u32) -> Result<(), WriteError>

Try to write u32 in big-endian.`
source§

fn write_u32(&mut self, num: u32)

Writes an u32 in big-endian. Read more
source§

fn try_write_u64(&mut self, num: u64) -> Result<(), WriteError>

Try to write u64 in big-endian.`
source§

fn write_u64(&mut self, num: u64)

Writes an u64 in big-endian. Read more
source§

fn try_write_u128(&mut self, num: u128) -> Result<(), WriteError>

Try to write u128 in big-endian.`
source§

fn write_u128(&mut self, num: u128)

Writes an u128 in big-endian. Read more
source§

fn try_write_i8(&mut self, num: i8) -> Result<(), WriteError>

Try to write i8 in big-endian.`
source§

fn write_i8(&mut self, num: i8)

Writes an i8 in big-endian. Read more
source§

fn try_write_i16(&mut self, num: i16) -> Result<(), WriteError>

Try to write i16 in big-endian.`
source§

fn write_i16(&mut self, num: i16)

Writes an i16 in big-endian. Read more
source§

fn try_write_i32(&mut self, num: i32) -> Result<(), WriteError>

Try to write i32 in big-endian.`
source§

fn write_i32(&mut self, num: i32)

Writes an i32 in big-endian. Read more
source§

fn try_write_i64(&mut self, num: i64) -> Result<(), WriteError>

Try to write i64 in big-endian.`
source§

fn write_i64(&mut self, num: i64)

Writes an i64 in big-endian. Read more
source§

fn try_write_i128(&mut self, num: i128) -> Result<(), WriteError>

Try to write i128 in big-endian.`
source§

fn write_i128(&mut self, num: i128)

Writes an i128 in big-endian. Read more
source§

fn try_write_f32(&mut self, num: f32) -> Result<(), WriteError>

Try to write f32 in big-endian.`
source§

fn write_f32(&mut self, num: f32)

Writes an f32 in big-endian. Read more
source§

fn try_write_f64(&mut self, num: f64) -> Result<(), WriteError>

Try to write f64 in big-endian.`
source§

fn write_f64(&mut self, num: f64)

Writes an f64 in big-endian. Read more
source§

fn try_write_le_u8(&mut self, num: u8) -> Result<(), WriteError>

Try to write u8 in little-endian.`
source§

fn write_le_u8(&mut self, num: u8)

Writes an u8 in little-endian. Read more
source§

fn try_write_le_u16(&mut self, num: u16) -> Result<(), WriteError>

Try to write u16 in little-endian.`
source§

fn write_le_u16(&mut self, num: u16)

Writes an u16 in little-endian. Read more
source§

fn try_write_le_u32(&mut self, num: u32) -> Result<(), WriteError>

Try to write u32 in little-endian.`
source§

fn write_le_u32(&mut self, num: u32)

Writes an u32 in little-endian. Read more
source§

fn try_write_le_u64(&mut self, num: u64) -> Result<(), WriteError>

Try to write u64 in little-endian.`
source§

fn write_le_u64(&mut self, num: u64)

Writes an u64 in little-endian. Read more
source§

fn try_write_le_u128(&mut self, num: u128) -> Result<(), WriteError>

Try to write u128 in little-endian.`
source§

fn write_le_u128(&mut self, num: u128)

Writes an u128 in little-endian. Read more
source§

fn try_write_le_i8(&mut self, num: i8) -> Result<(), WriteError>

Try to write i8 in little-endian.`
source§

fn write_le_i8(&mut self, num: i8)

Writes an i8 in little-endian. Read more
source§

fn try_write_le_i16(&mut self, num: i16) -> Result<(), WriteError>

Try to write i16 in little-endian.`
source§

fn write_le_i16(&mut self, num: i16)

Writes an i16 in little-endian. Read more
source§

fn try_write_le_i32(&mut self, num: i32) -> Result<(), WriteError>

Try to write i32 in little-endian.`
source§

fn write_le_i32(&mut self, num: i32)

Writes an i32 in little-endian. Read more
source§

fn try_write_le_i64(&mut self, num: i64) -> Result<(), WriteError>

Try to write i64 in little-endian.`
source§

fn write_le_i64(&mut self, num: i64)

Writes an i64 in little-endian. Read more
source§

fn try_write_le_i128(&mut self, num: i128) -> Result<(), WriteError>

Try to write i128 in little-endian.`
source§

fn write_le_i128(&mut self, num: i128)

Writes an i128 in little-endian. Read more
source§

fn try_write_le_f32(&mut self, num: f32) -> Result<(), WriteError>

Try to write f32 in little-endian.`
source§

fn write_le_f32(&mut self, num: f32)

Writes an f32 in little-endian. Read more
source§

fn try_write_le_f64(&mut self, num: f64) -> Result<(), WriteError>

Try to write f64 in little-endian.`
source§

fn write_le_f64(&mut self, num: f64)

Writes an f64 in little-endian. Read more
source§

impl<T: Clone> Clone for Offset<T>

source§

fn clone(&self) -> Offset<T>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T: Debug> Debug for Offset<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T: Hash> Hash for Offset<T>

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<T: PartialEq> PartialEq<Offset<T>> for Offset<T>

source§

fn eq(&self, other: &Offset<T>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T: Copy> Copy for Offset<T>

source§

impl<T: Eq> Eq for Offset<T>

source§

impl<T> StructuralEq for Offset<T>

source§

impl<T> StructuralPartialEq for Offset<T>

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for Offset<T>where T: RefUnwindSafe,

§

impl<T> Send for Offset<T>where T: Send,

§

impl<T> Sync for Offset<T>where T: Sync,

§

impl<T> Unpin for Offset<T>where T: Unpin,

§

impl<T> UnwindSafe for Offset<T>where T: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.