some improvements to bounded vec API (#10590)

* some improvements to bounded vec

* revert license tweak

* more tests

* fix

* Update frame/support/src/storage/bounded_vec.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* add the same stuff for btree map and set as well

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
Kian Paimani
2022-01-06 11:55:21 +01:00
committed by GitHub
parent 50d1666d33
commit c3add6ee09
5 changed files with 301 additions and 32 deletions
@@ -23,6 +23,16 @@ use scale_info::{build::Fields, meta_type, Path, Type, TypeInfo, TypeParameter};
use sp_runtime::{traits::Block as BlockT, DispatchError};
use sp_std::{cmp::Ordering, prelude::*};
/// Try and collect into a collection `C`.
pub trait TryCollect<C> {
type Error;
/// Consume self and try to collect the results into `C`.
///
/// This is useful in preventing the undesirable `.collect().try_into()` call chain on
/// collections that need to be converted into a bounded type (e.g. `BoundedVec`).
fn try_collect(self) -> Result<C, Self::Error>;
}
/// Anything that can have a `::len()` method.
pub trait Len {
/// Return the length of data type.