pub struct RangeSpec(/* private fields */);Expand description
A chunk range specification as a sequence of chunk offsets.
This is just the wire encoding of a ChunkRanges. You should rarely have to
interact with this directly.
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
RangeSpeccan be converted to aChunkRangesusing 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 verified_size() -> Self
pub fn verified_size() -> Self
Creates a RangeSpec selecting the last chunk, which is also a size proof.
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 chunks(&self) -> (u64, Option<u64>)
pub fn chunks(&self) -> (u64, Option<u64>)
Returns the number of chunks selected by this RangeSpec, as a tuple
with the minimum and maximum number of chunks.
Sourcepub fn to_chunk_ranges(&self) -> ChunkRanges
pub fn to_chunk_ranges(&self) -> ChunkRanges
Creates a ChunkRanges from this RangeSpec.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for RangeSpec
impl<'de> Deserialize<'de> for RangeSpec
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for RangeSpec
impl StructuralPartialEq for RangeSpec
Auto Trait Implementations§
impl Freeze for RangeSpec
impl RefUnwindSafe for RangeSpec
impl Send for RangeSpec
impl Sync for RangeSpec
impl Unpin for RangeSpec
impl UnwindSafe for RangeSpec
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> CompatExt for T
impl<T> CompatExt for T
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.