Trait segsource::Source[][src]

pub trait Source: Sized + Sync + Send {
    type Item;
    fn from_vec_with_offset(
        items: Vec<Self::Item>,
        initial_offset: usize
    ) -> Result<Self>;
fn size(&self) -> usize;
fn initial_offset(&self) -> usize;
fn segment(
        &self,
        start: usize,
        end: usize
    ) -> Result<Segment<'_, Self::Item>>; fn from_vec(items: Vec<Self::Item>) -> Result<Self> { ... }
fn validate_offset(&self, offset: usize) -> Result<()> { ... }
fn all(&self) -> Result<Segment<'_, Self::Item>> { ... }
fn get_n(
        &self,
        offset: usize,
        num_items: usize
    ) -> Result<Segment<'_, Self::Item>> { ... }
fn all_before(&self, offset: usize) -> Result<Segment<'_, Self::Item>> { ... }
fn all_after(&self, offset: usize) -> Result<Segment<'_, Self::Item>> { ... }
fn lower_offset_limit(&self) -> usize { ... }
fn upper_offset_limit(&self) -> usize { ... } }
Expand description

Sources own their own data and are used to generate Segments. The following sources are included with segsource (although others can be implemented):

  1. VecSource: A source that stores its items as a simple Vec. This source is always available.
  2. BytesSource: A source that uses a Bytes object from the wonderful bytes crate to store its data. This source can only use u8s as its item. Requires the bytes feature.
  3. MappedFileSource: A source that stores its data using a memory mapped file. This source can only use u8s as its item. Requires the mmap feature.

When a Source creates a new Segment, that segment will have the same initial offset and (if applicable) the same endidness as the source.

Associated Types

The type of item the Source and its generated Segments will hold.

Required methods

Creates a new source with the provided initial offset, using the items in theVec for its data.

The amount of data in the reader. If the reader’s size changes (which none of the implementations currently do), then this should return how much data was initially in the reader.

The initial offset of the Source. For more information, see the Offsets section of the Source documentation.

Creates a segment from the start offset (inclusive) to the end offset (exclusive).

Provided methods

Creates a new source using the data in the Vec for its data.

Checks to make sure that the provided offset is valid. If it is, then an Ok(()) will be returned. Otherwise, the appropriate error will be returned.

Returns a single segment containing all data in the source.

Gets a segment of n items, starting at the given offset.

Gets all items in the source before the provided offset (exclusive).

Gets all items in the source after the provided offset (inclusive).

The lowest valid offset that can be requested.

The highest valid offset that can be requested.

Implementors