Trait Source

Source
pub trait Source:
    Sized
    + Sync
    + Send {
    type Item;

    // Required methods
    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>>;

    // Provided methods
    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.

Required Associated Types§

Source

type Item

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

Required Methods§

Source

fn from_vec_with_offset( items: Vec<Self::Item>, initial_offset: usize, ) -> Result<Self>

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

Source

fn size(&self) -> usize

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.

Source

fn initial_offset(&self) -> usize

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

Source

fn segment(&self, start: usize, end: usize) -> Result<Segment<'_, Self::Item>>

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

Provided Methods§

Source

fn from_vec(items: Vec<Self::Item>) -> Result<Self>

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

Source

fn validate_offset(&self, offset: usize) -> Result<()>

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.

Source

fn all(&self) -> Result<Segment<'_, Self::Item>>

Returns a single segment containing all data in the source.

Source

fn get_n( &self, offset: usize, num_items: usize, ) -> Result<Segment<'_, Self::Item>>

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

Source

fn all_before(&self, offset: usize) -> Result<Segment<'_, Self::Item>>

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

Source

fn all_after(&self, offset: usize) -> Result<Segment<'_, Self::Item>>

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

Source

fn lower_offset_limit(&self) -> usize

The lowest valid offset that can be requested.

Source

fn upper_offset_limit(&self) -> usize

The highest valid offset that can be requested.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§