mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 05:51:02 +00:00
fix grumbles
This commit is contained in:
@@ -17,7 +17,8 @@
|
||||
//! Endian manager.
|
||||
|
||||
/// Trait to allow conversion to a know endian representation when sensitive.
|
||||
pub trait EndianSensitive: Sized {
|
||||
// note: the copy bound and static lifetimes are necessary for safety of `Slicable` blanket implementation.
|
||||
pub trait EndianSensitive: Copy + 'static {
|
||||
fn to_le(self) -> Self { self }
|
||||
fn to_be(self) -> Self { self }
|
||||
fn from_le(self) -> Self { self }
|
||||
@@ -48,3 +49,20 @@ impl_endians!(u16, u32, u64, usize, i16, i32, i64, isize);
|
||||
impl_non_endians!(u8, i8, [u8; 1], [u8; 2], [u8; 3], [u8; 4], [u8; 5], [u8; 6], [u8; 7], [u8; 8],
|
||||
[u8; 10], [u8; 12], [u8; 14], [u8; 16], [u8; 20], [u8; 24], [u8; 28], [u8; 32], [u8; 40],
|
||||
[u8; 48], [u8; 56], [u8; 64], [u8; 80], [u8; 96], [u8; 112], [u8; 128]);
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::EndianSensitive;
|
||||
|
||||
#[test]
|
||||
fn endian_sensitive_is_copy() {
|
||||
fn _takes_copy<T: Copy>() { }
|
||||
fn _takes_endian_sensitive<T: EndianSensitive>() { _takes_copy::<T>() }
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn endian_sensitive_outlives_static() {
|
||||
fn _takes_static<T: 'static>() { }
|
||||
fn _takes_endian_sensitive<T: EndianSensitive>() { _takes_static::<T>() }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
//! Vec<u8> serialiser.
|
||||
|
||||
use runtime_support::vec::Vec;
|
||||
use runtime_support::prelude::*;
|
||||
use slicable::Slicable;
|
||||
|
||||
/// Trait to allow itself to be serialised into a `Vec<u8>`
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
//! Serialiser and prepender.
|
||||
|
||||
use runtime_support::vec::Vec;
|
||||
use runtime_support::prelude::*;
|
||||
use slicable::Slicable;
|
||||
|
||||
/// Trait to allow itselg to be serialised and prepended by a given slice.
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
//! Serialisation.
|
||||
|
||||
use runtime_support::vec::Vec;
|
||||
use runtime_support::prelude::*;
|
||||
use runtime_support::{mem, slice};
|
||||
use joiner::Joiner;
|
||||
use endiansensitive::EndianSensitive;
|
||||
@@ -44,8 +44,7 @@ pub trait Slicable: Sized {
|
||||
/// Trait to mark that a type is not trivially (essentially "in place") serialisable.
|
||||
pub trait NonTrivialSlicable: Slicable {}
|
||||
|
||||
// note: the copy bound and static lifetimes are necessary for safety of `set_as_slice`.
|
||||
impl<T: Copy + EndianSensitive + 'static> Slicable for T {
|
||||
impl<T: EndianSensitive> Slicable for T {
|
||||
fn set_as_slice<F: FnOnce(&mut [u8]) -> bool>(fill_slice: F) -> Option<Self> {
|
||||
let size = mem::size_of::<T>();
|
||||
let mut result: T = unsafe { mem::zeroed() };
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
//! Conensus module for runtime; manages the authority set ready for the native code.
|
||||
|
||||
use runtime_support::vec::Vec;
|
||||
use runtime_support::prelude::*;
|
||||
use storable::StorageVec;
|
||||
use primitives::SessionKey;
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
//! Session manager: is told the validators and allows them to manage their session keys for the
|
||||
//! consensus module.
|
||||
|
||||
use runtime_support::vec::Vec;
|
||||
use runtime_support::prelude::*;
|
||||
use keyedvec::KeyedVec;
|
||||
use storable::{kill, Storable, StorageVec};
|
||||
use primitives::{AccountID, SessionKey, BlockNumber};
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
//! Staking manager: Handles balances and periodically determines the best set of validators.
|
||||
|
||||
use runtime_support::vec::Vec;
|
||||
use runtime_support::prelude::*;
|
||||
use keyedvec::KeyedVec;
|
||||
use storable::{Storable, StorageVec};
|
||||
use primitives::{BlockNumber, AccountID};
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
use primitives::{Block, BlockNumber, Hash, UncheckedTransaction, TxOrder, Hashable};
|
||||
use runtime_support::mem;
|
||||
use runtime_support::vec::Vec;
|
||||
use runtime_support::prelude::*;
|
||||
use storable::Storable;
|
||||
use keyedvec::KeyedVec;
|
||||
use environment::with_env;
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
//! Primitive types.
|
||||
|
||||
use runtime_support::vec::Vec;
|
||||
use runtime_support::prelude::*;
|
||||
use streamreader::StreamReader;
|
||||
use joiner::Joiner;
|
||||
use slicable::{Slicable, NonTrivialSlicable};
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
use slicable::Slicable;
|
||||
use endiansensitive::EndianSensitive;
|
||||
use keyedvec::KeyedVec;
|
||||
use runtime_support::vec::Vec;
|
||||
use runtime_support::prelude::*;
|
||||
use runtime_support::{self, twox_128};
|
||||
|
||||
/// Trait for a value which may be stored in the storage DB.
|
||||
@@ -37,7 +37,7 @@ pub trait Storable {
|
||||
/// Remove `key` from storage.
|
||||
pub fn kill(key: &[u8]) { runtime_support::set_storage(&twox_128(key)[..], b""); }
|
||||
|
||||
impl<T: Default + Copy + EndianSensitive + 'static> Storable for T {
|
||||
impl<T: Default + EndianSensitive> Storable for T {
|
||||
fn lookup(key: &[u8]) -> Option<Self> {
|
||||
Slicable::set_as_slice(|out| runtime_support::read_storage(&twox_128(key)[..], out) == out.len())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user