jam-std-common 0.1.16

Common datatypes and utilities for the JAM nodes and tooling
Documentation
use scale::Decode;

pub struct Null;

impl Null {
	pub fn new() -> Self {
		Self
	}
}

impl scale::Input for Null {
	fn read(&mut self, bytes: &mut [u8]) -> Result<(), scale::Error> {
		bytes.fill(0);
		Ok(())
	}
	fn remaining_len(&mut self) -> Result<Option<usize>, scale::Error> {
		Ok(None)
	}
}

pub trait DecodeInto {
	fn decode_into<T: Decode>(&mut self) -> Result<T, scale::Error>;
}

impl<T: scale::Input> DecodeInto for T {
	fn decode_into<U: Decode>(&mut self) -> Result<U, scale::Error> {
		Decode::decode(self)
	}
}

pub trait NewNull {
	#[allow(dead_code)]
	fn new_null() -> Self;
}

impl<T: Decode> NewNull for T {
	fn new_null() -> Self {
		Null::new().decode_into().expect("infallible for nullable values; qed")
	}
}