mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-15 10:21:05 +00:00
committed by
Bastian Köcher
parent
06e0204694
commit
d80d2a5039
@@ -35,7 +35,7 @@ pub use chain::{
|
||||
UnderlyingChainProvider,
|
||||
};
|
||||
pub use frame_support::storage::storage_prefix as storage_value_final_key;
|
||||
use num_traits::{CheckedAdd, CheckedSub, One};
|
||||
use num_traits::{CheckedAdd, CheckedSub, One, SaturatingAdd, Zero};
|
||||
pub use storage_proof::{
|
||||
record_all_keys as record_all_trie_keys, Error as StorageProofError,
|
||||
ProofSize as StorageProofSize, RawStorageProof, StorageProofChecker,
|
||||
@@ -527,17 +527,27 @@ impl<T> Debug for StrippableError<T> {
|
||||
pub trait RangeInclusiveExt<Idx> {
|
||||
/// Computes the length of the `RangeInclusive`, checking for underflow and overflow.
|
||||
fn checked_len(&self) -> Option<Idx>;
|
||||
/// Computes the length of the `RangeInclusive`, saturating in case of underflow or overflow.
|
||||
fn saturating_len(&self) -> Idx;
|
||||
}
|
||||
|
||||
impl<Idx> RangeInclusiveExt<Idx> for RangeInclusive<Idx>
|
||||
where
|
||||
Idx: CheckedSub + CheckedAdd + One,
|
||||
Idx: CheckedSub + CheckedAdd + SaturatingAdd + One + Zero,
|
||||
{
|
||||
fn checked_len(&self) -> Option<Idx> {
|
||||
self.end()
|
||||
.checked_sub(self.start())
|
||||
.and_then(|len| len.checked_add(&Idx::one()))
|
||||
}
|
||||
|
||||
fn saturating_len(&self) -> Idx {
|
||||
let len = match self.end().checked_sub(self.start()) {
|
||||
Some(len) => len,
|
||||
None => return Idx::zero(),
|
||||
};
|
||||
len.saturating_add(&Idx::one())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
Reference in New Issue
Block a user