Skip to main content

View

Struct View 

Source
pub struct View<'a> { /* private fields */ }
Expand description

A bounded window over one address space.

The readable bytes are held as the slice itself, so View::window is a field read with no range to recompute, and the bytes the cursor has not passed are held as a suffix of that slice, so View::unread, View::remaining and View::take are slice operations with no offset to recompute. start and end place the window in the space: end - start == window.len(), and unread is a suffix of window for every view. The two constructors are the only places those bounds are proven — over_space takes a whole buffer, and child carves the sub-slice with the same get that bounds the child.

end restates start + window.len(). This file denies clippy::arithmetic_side_effects and usize states no total addition, so every spelling of View::end that derives the bound is either that denied + or a checked_add whose None no view can reach. The bound is therefore stored, and over_space and child are the only places it is proven.

Implementations§

Source§

impl<'a> View<'a>

Source

pub fn over_retained(bytes: &'a [u8]) -> View<'a>

Bounded window over retained bytes that left the live space chain.

Prefer views returned by DecodeContext. This constructor exists for opportunistic scanners over owned payloads that were copied out of the arena; locations report SpaceId::ROOT.

Source

pub fn position(self) -> usize

Returns the absolute position within the space.

Source

pub fn read_len(self) -> usize

Returns the window offset of the current position.

Every view holds the unread bytes as a suffix of the window, so the bytes already read are the rest of it. abs_diff is total at that count: unread is never longer than window.

Source

pub fn start(self) -> usize

Returns the window’s inclusive lower bound.

Source

pub fn end(self) -> usize

Returns the window’s exclusive upper bound.

Source

pub fn unread(self) -> &'a [u8] ⓘ

Returns the unread bytes of the window.

The cursor is the split of the window, so this is a field read.

Source

pub fn remaining(self) -> usize

Returns the number of unread bytes before the window’s end.

Source

pub fn is_empty(self) -> bool

Returns whether all bounded bytes have been read.

Source

pub fn location(self) -> SourceLocation

Returns this view’s current source location.

Source

pub fn location_at(self, offset: usize) -> SourceLocation

Returns a source location at an absolute offset in this view’s space.

Source

pub fn window(self) -> &'a [u8] ⓘ

Returns the readable window start..end as a slice.

Source

pub fn take(&mut self, count: usize) -> Option<&'a [u8]>

Takes count bytes, advancing only on success.

The unread slice is the upper bound: split_at_checked refuses a count the unread bytes cannot serve, so no separate end test stands beside it, and the cursor moves only when the split holds.

Source

pub fn array<const N: usize>(&mut self) -> Option<[u8; N]>

Takes a fixed-size byte array, advancing only on success.

Source

pub fn skip(&mut self, count: usize) -> Option<()>

Skips exactly count bytes.

Source

pub fn seek(&mut self, position: usize) -> Option<()>

Moves to an absolute offset, honoring the stored lower bound.

The window states both bounds: offset_of refuses a position under the window’s own start, and get refuses one past its end.

Source

pub fn seek_to_end(&mut self)

Moves the cursor to the window’s exclusive upper bound.

This is the one seek the window proves at construction. seek(end) reads offset_of(end), which is the window length, and the suffix of a slice at its own length is the empty slice, so neither bound of seek can refuse it. The suffix is taken from window itself: split_at is total for every mid <= len by its own contract, and the mid here is that length, so the invariant that unread is a suffix of window holds by derivation and the move states no refusal to thread. remaining is then 0, read_len the whole window, and position the stored end.

Source

pub fn u8(&mut self) -> Option<u8>

Reads a single byte.

Source

pub fn child(self, start: usize, end: usize) -> Option<View<'a>>

Returns an exactly contained child window.

The containment test is the sub-slice itself: offset_of refuses a lower bound under this window’s own, and get refuses an inverted range or an upper bound past this window’s end.

Source

pub fn counted( self, count: u64, min_element_size: usize, ) -> Option<BoundedCount>

Proves a declared element count could fit in the unread bytes.

Source

pub fn req_take(&mut self, count: usize) -> Result<&'a [u8], ParseError>

Required-read mirror of View::take.

Source

pub fn req_take_child(&mut self, count: usize) -> Result<View<'a>, ParseError>

Takes count bytes as a bounded child window, or states the truncation.

The child window carries the same bounds and space as the optional take this mirrors: View::start of the result is the position the take began at and View::end is the position it reached. The view states the same located truncation as View::req_take for the same count, and leaves the view unmoved when it does.

Source

pub fn req_u8(&mut self) -> Result<u8, ParseError>

Required-read mirror of View::u8.

Source§

impl View<'_>

Source

pub fn u16_le(&mut self) -> Option<u16>

Probe read of a u16 in the serialized byte order.

Source

pub fn req_u16_le(&mut self) -> Result<u16, ParseError>

Required-read mirror of View::u16_le.

Source

pub fn u16_le_at(bytes: &[u8], offset: usize) -> Option<u16>

Offset probe of a u16 over retained bytes. Sequential readers should keep a live View and call View::u16_le instead.

Source

pub fn i16_le(&mut self) -> Option<i16>

Probe read of a i16 in the serialized byte order.

Source

pub fn req_i16_le(&mut self) -> Result<i16, ParseError>

Required-read mirror of View::i16_le.

Source

pub fn i16_le_at(bytes: &[u8], offset: usize) -> Option<i16>

Offset probe of a i16 over retained bytes. Sequential readers should keep a live View and call View::i16_le instead.

Source

pub fn u32_le(&mut self) -> Option<u32>

Probe read of a u32 in the serialized byte order.

Source

pub fn req_u32_le(&mut self) -> Result<u32, ParseError>

Required-read mirror of View::u32_le.

Source

pub fn u32_le_at(bytes: &[u8], offset: usize) -> Option<u32>

Offset probe of a u32 over retained bytes. Sequential readers should keep a live View and call View::u32_le instead.

Source

pub fn i32_le(&mut self) -> Option<i32>

Probe read of a i32 in the serialized byte order.

Source

pub fn req_i32_le(&mut self) -> Result<i32, ParseError>

Required-read mirror of View::i32_le.

Source

pub fn i32_le_at(bytes: &[u8], offset: usize) -> Option<i32>

Offset probe of a i32 over retained bytes. Sequential readers should keep a live View and call View::i32_le instead.

Source

pub fn u64_le(&mut self) -> Option<u64>

Probe read of a u64 in the serialized byte order.

Source

pub fn req_u64_le(&mut self) -> Result<u64, ParseError>

Required-read mirror of View::u64_le.

Source

pub fn u64_le_at(bytes: &[u8], offset: usize) -> Option<u64>

Offset probe of a u64 over retained bytes. Sequential readers should keep a live View and call View::u64_le instead.

Source

pub fn i64_le(&mut self) -> Option<i64>

Probe read of a i64 in the serialized byte order.

Source

pub fn req_i64_le(&mut self) -> Result<i64, ParseError>

Required-read mirror of View::i64_le.

Source

pub fn i64_le_at(bytes: &[u8], offset: usize) -> Option<i64>

Offset probe of a i64 over retained bytes. Sequential readers should keep a live View and call View::i64_le instead.

Source

pub fn f32_le(&mut self) -> Option<f32>

Probe read of a f32 in the serialized byte order.

Source

pub fn req_f32_le(&mut self) -> Result<f32, ParseError>

Required-read mirror of View::f32_le.

Source

pub fn f32_le_at(bytes: &[u8], offset: usize) -> Option<f32>

Offset probe of a f32 over retained bytes. Sequential readers should keep a live View and call View::f32_le instead.

Source

pub fn f64_le(&mut self) -> Option<f64>

Probe read of a f64 in the serialized byte order.

Source

pub fn req_f64_le(&mut self) -> Result<f64, ParseError>

Required-read mirror of View::f64_le.

Source

pub fn f64_le_at(bytes: &[u8], offset: usize) -> Option<f64>

Offset probe of a f64 over retained bytes. Sequential readers should keep a live View and call View::f64_le instead.

Source

pub fn u16_be(&mut self) -> Option<u16>

Probe read of a u16 in the serialized byte order.

Source

pub fn u16_be_at(bytes: &[u8], offset: usize) -> Option<u16>

Offset probe of a u16 over retained bytes. Sequential readers should keep a live View and call View::u16_be instead.

Source

pub fn i16_be(&mut self) -> Option<i16>

Probe read of a i16 in the serialized byte order.

Source

pub fn i16_be_at(bytes: &[u8], offset: usize) -> Option<i16>

Offset probe of a i16 over retained bytes. Sequential readers should keep a live View and call View::i16_be instead.

Source

pub fn u32_be(&mut self) -> Option<u32>

Probe read of a u32 in the serialized byte order.

Source

pub fn req_u32_be(&mut self) -> Result<u32, ParseError>

Required-read mirror of View::u32_be.

Source

pub fn u32_be_at(bytes: &[u8], offset: usize) -> Option<u32>

Offset probe of a u32 over retained bytes. Sequential readers should keep a live View and call View::u32_be instead.

Source

pub fn u64_be(&mut self) -> Option<u64>

Probe read of a u64 in the serialized byte order.

Source

pub fn u64_be_at(bytes: &[u8], offset: usize) -> Option<u64>

Offset probe of a u64 over retained bytes. Sequential readers should keep a live View and call View::u64_be instead.

Source

pub fn f32_be(&mut self) -> Option<f32>

Probe read of a f32 in the serialized byte order.

Source

pub fn req_f32_be(&mut self) -> Result<f32, ParseError>

Required-read mirror of View::f32_be.

Source

pub fn f32_be_at(bytes: &[u8], offset: usize) -> Option<f32>

Offset probe of a f32 over retained bytes. Sequential readers should keep a live View and call View::f32_be instead.

Source

pub fn f64_be(&mut self) -> Option<f64>

Probe read of a f64 in the serialized byte order.

Source

pub fn f64_be_at(bytes: &[u8], offset: usize) -> Option<f64>

Offset probe of a f64 over retained bytes. Sequential readers should keep a live View and call View::f64_be instead.

Source§

impl View<'_>

Source

pub fn u24_le_at(bytes: &[u8], offset: usize) -> Option<u32>

Reads a three-byte little-endian integer from retained bytes.

Source

pub fn u24_be_at(bytes: &[u8], offset: usize) -> Option<u32>

Reads a three-byte big-endian integer from retained bytes.

Trait Implementations§

Source§

impl<'a> Clone for View<'a>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<'a> Copy for View<'a>

Source§

impl<'a> Debug for View<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for View<'a>

§

impl<'a> RefUnwindSafe for View<'a>

§

impl<'a> Send for View<'a>

§

impl<'a> Sync for View<'a>

§

impl<'a> Unpin for View<'a>

§

impl<'a> UnsafeUnpin for View<'a>

§

impl<'a> UnwindSafe for View<'a>

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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 T
where 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 T
where T: Clone,

Source§

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 T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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.