Introduce storage types, to builds abstraction on storage (to be used in pallet attribute macro) (#7278)

* introduce storage types

* fix line width

* improve doc

* typo

* Apply suggestions from code review

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

* remove redundant function

* some more doc improvment

* disallow: some value on empty with option query

tests are update to still test default value is used when it is supposed
to be used.

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
Guillaume Thiolliere
2020-11-03 11:08:36 +01:00
committed by GitHub
parent 7fcf0ff610
commit ff6b603d69
7 changed files with 1501 additions and 0 deletions
+18
View File
@@ -1724,6 +1724,24 @@ pub trait Instance: 'static {
const PREFIX: &'static str;
}
/// An instance of a storage.
///
/// It is required the the couple `(PalletInfo::name<Pallet>(), STORAGE_PREFIX)` is unique.
/// Any storage with same couple will collide.
pub trait StorageInstance {
type Pallet: 'static;
type PalletInfo: PalletInfo;
const STORAGE_PREFIX: &'static str;
}
/// Implement Get by returning Default for any type that implements Default.
pub struct GetDefault;
impl<T: Default> crate::traits::Get<T> for GetDefault {
fn get() -> T {
T::default()
}
}
/// A trait similar to `Convert` to convert values from `B` an abstract balance type
/// into u64 and back from u128. (This conversion is used in election and other places where complex
/// calculation over balance type is needed)