mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 20:27:58 +00:00
add sort & try_append to bounded_vec (#11196)
This commit is contained in:
@@ -129,6 +129,16 @@ impl<T, S> BoundedVec<T, S> {
|
||||
self.0.sort_by(compare)
|
||||
}
|
||||
|
||||
/// Exactly the same semantics as [`slice::sort`].
|
||||
///
|
||||
/// This is safe since sorting cannot change the number of elements in the vector.
|
||||
pub fn sort(&mut self)
|
||||
where
|
||||
T: sp_std::cmp::Ord,
|
||||
{
|
||||
self.0.sort()
|
||||
}
|
||||
|
||||
/// Exactly the same semantics as `Vec::remove`.
|
||||
///
|
||||
/// # Panics
|
||||
@@ -374,6 +384,17 @@ impl<T, S: Get<u32>> BoundedVec<T, S> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Exactly the same semantics as [`Vec::append`], but returns an error and does nothing if the
|
||||
/// length of the outcome is larger than the bound.
|
||||
pub fn try_append(&mut self, other: &mut Vec<T>) -> Result<(), ()> {
|
||||
if other.len().saturating_add(self.len()) <= Self::bound() {
|
||||
self.0.append(other);
|
||||
Ok(())
|
||||
} else {
|
||||
Err(())
|
||||
}
|
||||
}
|
||||
|
||||
/// Consumes self and mutates self via the given `mutate` function.
|
||||
///
|
||||
/// If the outcome of mutation is within bounds, `Some(Self)` is returned. Else, `None` is
|
||||
|
||||
Reference in New Issue
Block a user