pub struct SegmentLengthsBuilder { /* private fields */ }Expand description
Helper object for constructing an OwnedSegments or a SliceSegments.
Implementations§
Source§impl SegmentLengthsBuilder
impl SegmentLengthsBuilder
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Creates a new SegmentLengthsBuilder, initializing the segment_indices vector with
Vec::with_capacitiy(capacity). capacity should equal the number of times that push_segment()
is expected to be called.
Sourcepub fn try_push_segment(&mut self, length_in_words: usize) -> Result<()>
pub fn try_push_segment(&mut self, length_in_words: usize) -> Result<()>
Pushes a new segment length. The nth time (starting at 0) this is called specifies the length of
the segment with ID n. If the segment overflows the total word count, then this returns
a MessageSizeOverflow error.
Sourcepub fn into_owned_segments(self) -> OwnedSegments
pub fn into_owned_segments(self) -> OwnedSegments
Constructs an OwnedSegments, allocating a single buffer of 8-byte aligned memory to hold
all segments.
Sourcepub fn into_slice_segments(
self,
slice: &[u8],
segment_table_bytes_len: usize,
) -> BufferSegments<&'_ [u8]>
pub fn into_slice_segments( self, slice: &[u8], segment_table_bytes_len: usize, ) -> BufferSegments<&'_ [u8]>
Constructs a SliceSegments.
slice contains the full message (including the segment header).
Sourcepub fn total_words(&self) -> usize
pub fn total_words(&self) -> usize
Returns the sum of the lengths of the segments pushed so far.
Sourcepub fn to_segment_indices(self) -> Vec<(usize, usize)>
pub fn to_segment_indices(self) -> Vec<(usize, usize)>
Returns the vector of segment indices. Each entry is a pair (start_word_index, end_word_index). This method primarily exists to enable testing.