mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 04:37:57 +00:00
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:
@@ -55,6 +55,7 @@ use sp_std::prelude::*;
|
||||
use codec::{Decode, Encode, MaxEncodedLen};
|
||||
use scale_info::TypeInfo;
|
||||
|
||||
pub mod bounded;
|
||||
pub mod curve;
|
||||
pub mod generic;
|
||||
pub mod legacy;
|
||||
@@ -69,6 +70,9 @@ pub mod transaction_validity;
|
||||
|
||||
pub use crate::runtime_string::*;
|
||||
|
||||
// Re-export bounded types
|
||||
pub use bounded::{BoundedBTreeMap, BoundedBTreeSet, BoundedSlice, BoundedVec, WeakBoundedVec};
|
||||
|
||||
// Re-export Multiaddress
|
||||
pub use multiaddress::MultiAddress;
|
||||
|
||||
@@ -825,6 +829,45 @@ macro_rules! assert_eq_error_rate {
|
||||
};
|
||||
}
|
||||
|
||||
/// Build a bounded vec from the given literals.
|
||||
///
|
||||
/// The type of the outcome must be known.
|
||||
///
|
||||
/// Will not handle any errors and just panic if the given literals cannot fit in the corresponding
|
||||
/// bounded vec type. Thus, this is only suitable for testing and non-consensus code.
|
||||
#[macro_export]
|
||||
#[cfg(feature = "std")]
|
||||
macro_rules! bounded_vec {
|
||||
($ ($values:expr),* $(,)?) => {
|
||||
{
|
||||
$crate::sp_std::vec![$($values),*].try_into().unwrap()
|
||||
}
|
||||
};
|
||||
( $value:expr ; $repetition:expr ) => {
|
||||
{
|
||||
$crate::sp_std::vec![$value ; $repetition].try_into().unwrap()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Build a bounded btree-map from the given literals.
|
||||
///
|
||||
/// The type of the outcome must be known.
|
||||
///
|
||||
/// Will not handle any errors and just panic if the given literals cannot fit in the corresponding
|
||||
/// bounded vec type. Thus, this is only suitable for testing and non-consensus code.
|
||||
#[macro_export]
|
||||
#[cfg(feature = "std")]
|
||||
macro_rules! bounded_btree_map {
|
||||
($ ( $key:expr => $value:expr ),* $(,)?) => {
|
||||
{
|
||||
$crate::traits::TryCollect::<$crate::BoundedBTreeMap<_, _, _>>::try_collect(
|
||||
$crate::sp_std::vec![$(($key, $value)),*].into_iter()
|
||||
).unwrap()
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/// Simple blob to hold an extrinsic without committing to its format and ensure it is serialized
|
||||
/// correctly.
|
||||
#[derive(PartialEq, Eq, Clone, Default, Encode, Decode, TypeInfo)]
|
||||
|
||||
Reference in New Issue
Block a user