Move bounded type definitions to sp-runtime (#11645)

* Move bounded type definitions to sp-runtime

* cargo fmt

* Fix compile error

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Move TryCollect to sp-runtime

* Write some docs

* Import missing types

Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
This commit is contained in:
Keith Yeung
2022-06-13 14:31:42 +02:00
committed by GitHub
parent 8c1865d2f2
commit 2d6b0ecc21
13 changed files with 2484 additions and 2323 deletions
+1 -11
View File
@@ -24,7 +24,7 @@ use sp_arithmetic::traits::{CheckedAdd, CheckedMul, CheckedSub, Saturating};
#[doc(hidden)]
pub use sp_runtime::traits::{
ConstBool, ConstI128, ConstI16, ConstI32, ConstI64, ConstI8, ConstU128, ConstU16, ConstU32,
ConstU64, ConstU8, Get, GetDefault, TypedGet,
ConstU64, ConstU8, Get, GetDefault, TryCollect, TypedGet,
};
use sp_runtime::{traits::Block as BlockT, DispatchError};
use sp_std::{cmp::Ordering, prelude::*};
@@ -367,16 +367,6 @@ impl<T: Saturating + CheckedAdd + CheckedMul + CheckedSub> DefensiveSaturating f
}
}
/// 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.