Block import and export (#272)

* Block export and import

* Export and import using std streams

* Made AuthorituId::from_slice private
This commit is contained in:
Arkadiy Paronyan
2018-07-03 20:20:53 +02:00
committed by Gav Wood
parent 12268ae700
commit aa747e3fae
10 changed files with 267 additions and 25 deletions
@@ -38,6 +38,7 @@ pub trait Input {
}
}
#[cfg(not(feature = "std"))]
impl<'a> Input for &'a [u8] {
fn read(&mut self, into: &mut [u8]) -> usize {
let len = ::core::cmp::min(into.len(), self.len());
@@ -47,6 +48,13 @@ impl<'a> Input for &'a [u8] {
}
}
#[cfg(feature = "std")]
impl<R: ::std::io::Read> Input for R {
fn read(&mut self, into: &mut [u8]) -> usize {
(self as &mut ::std::io::Read).read(into).unwrap_or(0)
}
}
/// Trait that allows zero-copy read/write of value-references to/from slices in LE format.
pub trait Slicable: Sized {
/// Attempt to deserialise the value from input.