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 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.
Required Associated Types§
Required Methods§
Sourcefn from_vec_with_offset(
items: Vec<Self::Item>,
initial_offset: usize,
) -> Result<Self>
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.
Sourcefn size(&self) -> usize
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.
Sourcefn initial_offset(&self) -> usize
fn initial_offset(&self) -> usize
Provided Methods§
Sourcefn from_vec(items: Vec<Self::Item>) -> Result<Self>
fn from_vec(items: Vec<Self::Item>) -> Result<Self>
Creates a new source using the data in the Vec
for its data.
Sourcefn 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.
Sourcefn all(&self) -> Result<Segment<'_, Self::Item>>
fn all(&self) -> Result<Segment<'_, Self::Item>>
Returns a single segment containing all data in the source.
Sourcefn get_n(
&self,
offset: usize,
num_items: usize,
) -> Result<Segment<'_, Self::Item>>
fn get_n( &self, offset: usize, num_items: usize, ) -> Result<Segment<'_, Self::Item>>
Gets a segment of n items, starting at the given offset.
Sourcefn all_before(&self, offset: usize) -> Result<Segment<'_, Self::Item>>
fn all_before(&self, offset: usize) -> Result<Segment<'_, Self::Item>>
Gets all items in the source before the provided offset (exclusive).
Sourcefn all_after(&self, offset: usize) -> Result<Segment<'_, Self::Item>>
fn all_after(&self, offset: usize) -> Result<Segment<'_, Self::Item>>
Gets all items in the source after the provided offset (inclusive).
Sourcefn lower_offset_limit(&self) -> usize
fn lower_offset_limit(&self) -> usize
The lowest valid offset that can be requested.
Sourcefn upper_offset_limit(&self) -> usize
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.