Implement sessions.

This commit is contained in:
Gav
2018-01-19 10:34:55 +01:00
parent 400008028b
commit 81cd156d2a
7 changed files with 83 additions and 38 deletions
@@ -3,14 +3,14 @@ use endiansensitive::EndianSensitive;
use runtime_support;
pub trait Storage {
fn into(_key: &[u8]) -> Self where Self: Sized { unimplemented!() }
fn into(key: &[u8]) -> Self where Self: Sized + Default { Self::try_into(key).unwrap_or_else(Default::default) }
fn try_into(_key: &[u8]) -> Option<Self> where Self: Sized { unimplemented!() }
fn store(&self, key: &[u8]);
}
impl<T: Default + Sized + EndianSensitive> Storage for T {
fn into(key: &[u8]) -> Self {
fn try_into(key: &[u8]) -> Option<Self> {
Slicable::set_as_slice(|out| runtime_support::read_storage(key, out) == out.len())
.unwrap_or_else(Default::default)
}
fn store(&self, key: &[u8]) {
self.as_slice_then(|slice| runtime_support::set_storage(key, slice));