Implement PartialOrd and Ord on BoundedSlice and WeakBoundedVec (#11655)

* Implement PartialOrd and Ord on BoundedSlice and WeakBoundedVec

* More implementations of PartialEq and PartialOrd

* cargo fmt

* Fixes
This commit is contained in:
Keith Yeung
2022-06-13 22:55:48 +02:00
committed by GitHub
parent 4e2fb0af60
commit 19684de7d8
4 changed files with 221 additions and 18 deletions
@@ -66,6 +66,11 @@ where
K: Ord,
S: Get<u32>,
{
/// Create `Self` from `t` without any checks.
fn unchecked_from(t: BTreeMap<K, V>) -> Self {
Self(t, Default::default())
}
/// Exactly the same semantics as `BTreeMap::retain`.
///
/// The is a safe `&mut self` borrow because `retain` can only ever decrease the length of the
@@ -344,8 +349,7 @@ where
if self.len() > Bound::get() as usize {
Err("iterator length too big")
} else {
Ok(BoundedBTreeMap::<K, V, Bound>::try_from(self.collect::<BTreeMap<K, V>>())
.expect("length checked above; qed"))
Ok(BoundedBTreeMap::<K, V, Bound>::unchecked_from(self.collect::<BTreeMap<K, V>>()))
}
}
}