Skip to main content

Coverage

Struct Coverage 

Source
pub struct Coverage { /* private fields */ }
Expand description

A bitmap over discovery-block indices: bit i records whether block i (bytes [i * DISCOVERY_BLOCK_BYTES, (i + 1) * DISCOVERY_BLOCK_BYTES)) is covered.

Bit-packed as Vec<u8>: bit i lives at byte i / 8, bit position i % 8 (little-endian within the byte). Serializes over postcard as a length-prefixed byte vector — cheap on the wire and trivial to union/merge byte-wise if a future caller needs to.

Carries no num_blocks field. A Coverage built locally (via Self::from_block_indices / Self::full) leaves the trailing partial byte’s unused high bits zero. A Coverage deserialized from untrusted wire does not: the byte length only rounds the block count up to the next multiple of 8, and nothing on the wire pins the exact count, so a peer may set spurious high bits in that trailing byte. Self::covers and Self::covered_blocks report the raw bits as-is, so such a bit makes covers(i) true for an i past the blob’s real block count. Consumers MUST clamp interpretation to the blob’s own num_blocks(total_bytes) — query only i < num_blocks, and ignore any Self::covered_blocks index beyond it. The signed size, not the bitmap, is the authority on how many blocks exist.

Implementations§

Source§

impl Coverage

Source

pub fn empty() -> Self

No blocks covered.

Source

pub fn full(num_blocks: u32) -> Self

Every block in 0..num_blocks covered.

Source

pub fn from_block_indices( num_blocks: u32, set: impl Iterator<Item = u32>, ) -> Self

Builds a Coverage sized for num_blocks blocks with exactly the indices from set covered. Indices >= num_blocks in set are dropped rather than growing the bitmap past its declared size.

Source

pub fn covers(&self, block: u32) -> bool

Is block covered?

Source

pub fn is_empty(&self) -> bool

No block is covered — every byte of the bitmap is zero.

Source

pub fn covered_blocks(&self) -> impl Iterator<Item = u32> + '_

Iterates the covered block indices in ascending order. Reports raw set bits: a Coverage from untrusted wire may yield indices past the blob’s real block count (see the type doc), so a consumer bounds these against its own num_blocks(total_bytes).

Trait Implementations§

Source§

impl Clone for Coverage

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Coverage

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Coverage

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Coverage

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for Coverage

Source§

impl PartialEq for Coverage

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for Coverage

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Coverage

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.