pub(crate) fn erasure_shard_index(&self) -> Option<usize> {
        match self.shred_type() {
            ShredType::Data => {
                let index = self.index().checked_sub(self.fec_set_index())?;
                usize::try_from(index).ok()
            }
            ShredType::Code => {
                // Assert that the last shred index in the erasure set does not
                // overshoot u32.
                self.fec_set_index().checked_add(u32::from(
                    self.coding_header.num_data_shreds.checked_sub(1)?,
                ))?;
                self.first_coding_index()?.checked_add(u32::from(
                    self.coding_header.num_coding_shreds.checked_sub(1)?,
                ))?;
                let num_data_shreds = usize::from(self.coding_header.num_data_shreds);
                let num_coding_shreds = usize::from(self.coding_header.num_coding_shreds);
                let position = usize::from(self.coding_header.position);
                let fec_set_size = num_data_shreds.checked_add(num_coding_shreds)?;
                let index = position.checked_add(num_data_shreds)?;
                (index < fec_set_size).then(|| index)
            }
        }
    }
// Returns the shard index within the erasure coding set.
Returns the shard index within the erasure coding set.
Returns the shard index within the erasure coding set .
pub(crate) fn erasure_shard_index(&self) -> Option<usize> {
        match self.shred_type() {
            ShredType::Data => {
                let index = self.index().checked_sub(self.fec_set_index())?;
                usize::try_from(index).ok()
            }
            ShredType::Code => {
                // Assert that the last shred index in the erasure set does not
                // overshoot u32.
                self.fec_set_index().checked_add(u32::from(
                    self.coding_header.num_data_shreds.checked_sub(1)?,
                ))?;
                self.first_coding_index()?.checked_add(u32::from(
                    self.coding_header.num_coding_shreds.checked_sub(1)?,
                ))?;
                let num_data_shreds = usize::from(self.coding_header.num_data_shreds);
                let num_coding_shreds = usize::from(self.coding_header.num_coding_shreds);
                let position = usize::from(self.coding_header.position);
                let fec_set_size = num_data_shreds.checked_add(num_coding_shreds)?;
                let index = position.checked_add(num_data_shreds)?;
                (index < fec_set_size).then(|| index)
            }
        }
    }
pub ( crate ) fn erasure_shard_index ( & self ) -> Option < usize > { match self . shred_type ( ) { ShredType :: Data => { let index = self . index ( ) . checked_sub ( self . fec_set_index ( ) ) ? ; usize :: try_from ( index ) . ok ( ) } ShredType :: Code => { // Assert that the last shred index in the erasure set does not // overshoot u32. self . fec_set_index ( ) . checked_add ( u32 :: from ( self . coding_header . num_data_shreds . checked_sub ( 1 ) ? , ) ) ? ; self . first_coding_index ( ) ? . checked_add ( u32 :: from ( self . coding_header . num_coding_shreds . checked_sub ( 1 ) ? , ) ) ? ; let num_data_shreds = usize :: from ( self . coding_header . num_data_shreds ) ; let num_coding_shreds = usize :: from ( self . coding_header . num_coding_shreds ) ; let position = usize :: from ( self . coding_header . position ) ; let fec_set_size = num_data_shreds . checked_add ( num_coding_shreds ) ? ; let index = position . checked_add ( num_data_shreds ) ? ; ( index < fec_set_size ) . then ( | | index ) } } }
Returns the shard index within the erasure coding set.
Returns the shard index within the erasure coding set .
&self
&self