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

Creates a new Cursor.

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

Updates the offset.

Maybe panic if there aren’t enough bytes left.

Returns the current offset.

Returns the inner value as a reference.

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

Returns the inner value, discarding the offset.

Trait Implementations

Returns the entire slice.

Returns all remaining bytes.

Try to read a given length of bytes. Read more

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

Returns the length of the entire slice.

Reads a given length of bytes. Read more

Try to read 1 bytes in big-endian converting them into an u8. Read more

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

Try to read 2 bytes in big-endian converting them into an u16. Read more

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

Try to read 4 bytes in big-endian converting them into an u32. Read more

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

Try to read 8 bytes in big-endian converting them into an u64. Read more

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

Try to read 16 bytes in big-endian converting them into an u128. Read more

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

Try to read 1 bytes in big-endian converting them into an i8. Read more

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

Try to read 2 bytes in big-endian converting them into an i16. Read more

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

Try to read 4 bytes in big-endian converting them into an i32. Read more

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

Try to read 8 bytes in big-endian converting them into an i64. Read more

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

Try to read 16 bytes in big-endian converting them into an i128. Read more

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

Try to read 4 bytes in big-endian converting them into an f32. Read more

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

Try to read 8 bytes in big-endian converting them into an f64. Read more

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

Try to read 1 bytes in little-endian converting them into an u8. Read more

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

Try to read 2 bytes in little-endian converting them into an u16. Read more

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

Try to read 4 bytes in little-endian converting them into an u32. Read more

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

Try to read 8 bytes in little-endian converting them into an u64. Read more

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

Try to read 16 bytes in little-endian converting them into an u128. Read more

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

Try to read 1 bytes in little-endian converting them into an i8. Read more

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

Try to read 2 bytes in little-endian converting them into an i16. Read more

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

Try to read 4 bytes in little-endian converting them into an i32. Read more

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

Try to read 8 bytes in little-endian converting them into an i64. Read more

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

Try to read 16 bytes in little-endian converting them into an i128. Read more

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

Try to read 4 bytes in little-endian converting them into an f32. Read more

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

Try to read 8 bytes in little-endian converting them into an f64. Read more

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

Returns the internal position.

Sets the internal position.

Panics

Depending on the implementation.

Sets the internal position.

Advances the internal position if possible.

Advances the internal position. Read more

Returns the entire slice mutably.

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

Returns the remaining bytes mutably.

Writes a slice.

Writes a slice. Read more

Try to write u8 in big-endian.` Read more

Writes an u8 in big-endian. Read more

Try to write u16 in big-endian.` Read more

Writes an u16 in big-endian. Read more

Try to write u32 in big-endian.` Read more

Writes an u32 in big-endian. Read more

Try to write u64 in big-endian.` Read more

Writes an u64 in big-endian. Read more

Try to write u128 in big-endian.` Read more

Writes an u128 in big-endian. Read more

Try to write i8 in big-endian.` Read more

Writes an i8 in big-endian. Read more

Try to write i16 in big-endian.` Read more

Writes an i16 in big-endian. Read more

Try to write i32 in big-endian.` Read more

Writes an i32 in big-endian. Read more

Try to write i64 in big-endian.` Read more

Writes an i64 in big-endian. Read more

Try to write i128 in big-endian.` Read more

Writes an i128 in big-endian. Read more

Try to write f32 in big-endian.` Read more

Writes an f32 in big-endian. Read more

Try to write f64 in big-endian.` Read more

Writes an f64 in big-endian. Read more

Try to write u8 in little-endian.` Read more

Writes an u8 in little-endian. Read more

Try to write u16 in little-endian.` Read more

Writes an u16 in little-endian. Read more

Try to write u32 in little-endian.` Read more

Writes an u32 in little-endian. Read more

Try to write u64 in little-endian.` Read more

Writes an u64 in little-endian. Read more

Try to write u128 in little-endian.` Read more

Writes an u128 in little-endian. Read more

Try to write i8 in little-endian.` Read more

Writes an i8 in little-endian. Read more

Try to write i16 in little-endian.` Read more

Writes an i16 in little-endian. Read more

Try to write i32 in little-endian.` Read more

Writes an i32 in little-endian. Read more

Try to write i64 in little-endian.` Read more

Writes an i64 in little-endian. Read more

Try to write i128 in little-endian.` Read more

Writes an i128 in little-endian. Read more

Try to write f32 in little-endian.` Read more

Writes an f32 in little-endian. Read more

Try to write f64 in little-endian.` Read more

Writes an f64 in little-endian. Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Feeds this value into the given Hasher. Read more

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

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.

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

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.