Struct capnp::serialize::SegmentLengthsBuilder
source · 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 SegmentsLengthsBuilder
, 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 push_segment(&mut self, length_in_words: usize)
pub fn push_segment(&mut self, length_in_words: usize)
Pushes a new segment length. The n
th time (starting at 0) this is called specifies the length of
the segment with ID n
.
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]) -> SliceSegments<'_>
pub fn into_slice_segments(self, slice: &[u8]) -> SliceSegments<'_>
Constructs a SliceSegments
, where the passed-in slice is assumed to contain the segments.
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.