Skip to main content

StreamReader

Struct StreamReader 

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

Scans a buffer for commits and exposes the committed region, block by block, and its records. Zero-copy: accessors return slices into the original buffer.

Implementations§

Source§

impl<'a> StreamReader<'a>

Source

pub fn new(buf: &'a [u8]) -> Self

A reader that stops at the first damaged block.

Source

pub fn continuing(buf: &'a [u8]) -> Self

A reader that skips damaged blocks and reads on.

Source

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

Source

pub fn committed_end(&self) -> usize

Offset just past the last ETB and its payload.

Source

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

The committed region of the buffer.

Source

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

Everything after the last commit.

Source

pub fn torn(&self) -> bool

Whether data trails the last commit (layout, notes and EOT alone do not count).

Source

pub fn torn_regions(&self) -> &[(usize, usize)]

[start, end) of every region torn by a SYN inside the stream: the uncommitted bytes between a commit (or the start) and the SYN that began the next document. They belong to no block and deliver nothing. Layout alone before a SYN is not a tear. The torn tail after the last commit is StreamReader::torn, not listed here.

Source

pub fn continue_past_damage(&self) -> bool

Whether the reader goes on past a damaged block.

Source

pub fn block_count(&self) -> usize

Source

pub fn block(&self, i: usize) -> &'a [u8] ⓘ

Committed block i: the bytes from the previous commit to this block’s ETB (marker and payload excluded).

Source

pub fn block_ranges(&self) -> &[(usize, usize)]

[start, end) of every committed block.

Source

pub fn blocks(&self) -> impl Iterator<Item = &'a [u8]> + '_

Source

pub fn block_end(&self, i: usize) -> usize

Offset after a block’s ETB and payload: the start of the next block.

Source

pub fn damaged(&self) -> &[usize]

Indexes of committed blocks that are not well-formed.

Source

pub fn is_damaged(&self, i: usize) -> bool

Source

pub fn undamaged(&self) -> Cow<'a, [u8]>

The committed region with damaged blocks removed: borrowed when no block is damaged, otherwise the sound blocks concatenated.

Source

pub fn container(&self) -> Result<&Container<'a>>

The committed region as documents, damaged blocks left out. Fails with Error::DamagedBlock when a block is damaged, unless the reader continues past damage.

Source

pub fn document(&self) -> Result<&Document<'a>>

The first document of the committed region.

Source

pub fn each_record<F: FnMut(&Record<'a>)>(&self, f: F) -> Result<()>

Every committed record in order, up to the first damaged block; then Error::DamagedBlock, unless continuing, in which case every record of every sound block.

Source

pub fn records(&self) -> Result<Vec<Vec<Vec<u8>>>>

Logical values of every committed record (headings and header rows excluded); see StreamReader::each_record.

Auto Trait Implementations§

§

impl<'a> Forget for StreamReader<'a>

§

impl<'a> Freeze for StreamReader<'a>

§

impl<'a> Move for StreamReader<'a>

§

impl<'a> RefUnwindSafe for StreamReader<'a>

§

impl<'a> Send for StreamReader<'a>

§

impl<'a> Sync for StreamReader<'a>

§

impl<'a> Unpin for StreamReader<'a>

§

impl<'a> UnsafeUnpin for StreamReader<'a>

§

impl<'a> UnwindSafe for StreamReader<'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> 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, 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.