Struct iroh_blobs::protocol::RangeSpec
source · 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 a [ChunkRanges
] 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 fn new(ranges: impl AsRef<ChunkRangesRef>) -> Self
pub fn new(ranges: impl AsRef<ChunkRangesRef>) -> Self
Creates a new RangeSpec
from a range set.
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 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
.
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>,
source§impl PartialEq for RangeSpec
impl PartialEq for RangeSpec
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§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
§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
§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.