Seeker

Struct Seeker 

Source
pub struct Seeker<R> { /* private fields */ }
Expand description

A specialized CSV stream seeker.

Implementations§

Source§

impl<R: Read + Seek> Seeker<R>

Source

pub fn has_headers(&self) -> bool

Returns whether this seeker has been configured to interpret the first record as a header.

Source

pub fn initial_position(&self) -> u64

Returns the position the seekable stream was in when instantiating the seeker.

Source

pub fn first_record_position(&self) -> u64

Returns the absolute byte offset of the first record (excluding header) of the seekable stream.

Source

pub fn stream_len(&self) -> u64

Returns the total number of bytes contained in the seekable stream.

Source

pub fn lookahead_len(&self) -> u64

Returns the number of bytes that will be read when performing a lookahead in the seekable stream when using Seeker::find_record_after.

Source

pub fn range(&self) -> Range<u64>

Returns the first_record_position..stream_len range of the seeker.

Source

pub fn exact_count(&self) -> Option<u64>

Returns the exact number of records (header excluded) contained in the seekable stream, if the initial sample built when instantiating the seeker exhausted the whole stream.

Source

pub fn approx_count(&self) -> u64

Either returns the exact number of records (header excluded) contained in the seekable stream or an approximation based on statistics sampled from the beginning of the stream and the total stream length.

Source

pub fn find_record_after( &mut self, from_pos: u64, ) -> Result<Option<(u64, ByteRecord)>>

Attempt to find the position, in the seekable stream, of the beginning of the CSV record just after the one where from_pos would end in.

Beware: if from_pos is the exact first byte of a CSV record, this method will still return the position of next CSV record because it has no way of knowing whether the byte just before from_pos is a newline.

This method will return an error if given from_pos is out of bounds.

This method will return None if it did not succeed in finding the next CSV record starting position. This can typically happen when seeking too close to the end of the stream, since this method needs to read ahead of the stream to test its heuristics.

match seeker.find_record_after(1024) {
    Ok(Some((pos, record))) => {
        // Everything went fine
    },
    Ok(None) => {
        // Lookahead failed
    },
    Err(err) => {
        // Either `from_pos` was out-of-bounds, or some IO error occurred
    }
}
Source

pub fn segments(&mut self, count: usize) -> Result<Vec<(u64, u64)>>

Split the seekable stream into a maximum of count segments.

This method might return less than count segments if the stream seems too small to safely return that many segments.

Source

pub fn byte_headers(&self) -> &ByteRecord

Returns the headers of the seekable stream, or just the first record the seeker was configured thusly.

Source

pub fn first_byte_record(&mut self) -> Result<Option<ByteRecord>>

Attempt to read the first record of the seekable stream.

Source

pub fn last_byte_record(&mut self) -> Result<Option<ByteRecord>>

Attempt to read the last record of the seekable stream by reading it in reverse.

Source

pub fn into_inner(self) -> R

Returns the underlying reader without unwinding its position.

Source

pub fn into_zero_copy_reader(self) -> Result<ZeroCopyReader<R>>

Transform the seeker into a ZeroCopyReader. Underlying reader will be correctly reset to the stream initial position beforehand.

Source

pub fn into_splitter(self) -> Result<Splitter<R>>

Transform the seeker into a Splitter. Underlying reader will be correctly reset to the stream initial position beforehand.

Auto Trait Implementations§

§

impl<R> Freeze for Seeker<R>
where R: Freeze,

§

impl<R> RefUnwindSafe for Seeker<R>
where R: RefUnwindSafe,

§

impl<R> Send for Seeker<R>
where R: Send,

§

impl<R> Sync for Seeker<R>
where R: Sync,

§

impl<R> Unpin for Seeker<R>
where R: Unpin,

§

impl<R> UnwindSafe for Seeker<R>
where R: UnwindSafe,

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 = 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 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.