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 Segment
s. The following sources are
included with segsource (although others can be implemented):
VecSource
: A source that stores its items as a simpleVec
. This source is always available.BytesSource
: A source that uses aBytes
object from the wonderfulbytes
crate to store its data. This source can only useu8
s as its item. Requires thebytes
feature.MappedFileSource
: A source that stores its data using a memory mapped file. This source can only useu8
s as its item. Requires themmap
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
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.
fn initial_offset(&self) -> usize
fn initial_offset(&self) -> usize
Provided methods
Creates a new source using the data in the Vec
for its data.
fn validate_offset(&self, offset: usize) -> Result<()>
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.
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).
fn lower_offset_limit(&self) -> usize
fn lower_offset_limit(&self) -> usize
The lowest valid offset that can be requested.
fn upper_offset_limit(&self) -> usize
fn upper_offset_limit(&self) -> usize
The highest valid offset that can be requested.