pub struct RangeSpec(/* private fields */);
Expand description
A chunk range specification as a sequence of chunk offsets.
Offsets encode alternating spans starting on 0, where the first span is always deselected.
§Examples:
-
[2, 5, 3, 1]
encodes five spans, of which two are selected:[0, 0+2) = [0, 2)
is not selected.[2, 2+5) = [2, 7)
is selected.[7, 7+3) = [7, 10)
is not selected.[10, 10+1) = [10, 11)
is selected.[11, inf)
is deselected.
Such a
RangeSpec
can be converted to aChunkRanges
using containing just the selected ranges:ChunkRanges{2..7, 10..11}
usingRangeSpec::to_chunk_ranges
. -
An empty range selects no spans, encoded as
[]
. This means nothing of the blob is selected. -
To select an entire blob create a single half-open span starting at the first chunk:
[0]
. -
To select the tail of a blob, create a single half-open span:
[15]
.
This is a SmallVec so we can avoid allocations for the very common case of a single chunk range.
Implementations§
Source§impl RangeSpec
impl RangeSpec
Sourcepub const EMPTY: Self
pub const EMPTY: Self
A RangeSpec
selecting nothing from the blob.
This is called “empty” because the representation is an empty set.
Sourcepub fn new(ranges: impl AsRef<ChunkRangesRef>) -> Self
pub fn new(ranges: impl AsRef<ChunkRangesRef>) -> Self
Creates a new RangeSpec
from a range set.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Checks if this RangeSpec
does not select any chunks in the blob.
Sourcepub fn to_chunk_ranges(&self) -> ChunkRanges
pub fn to_chunk_ranges(&self) -> ChunkRanges
Creates a ChunkRanges
from this RangeSpec
.