jam_std_common/util/
null.rs

1use codec::Decode;
2
3pub struct Null;
4
5impl Null {
6	pub fn new() -> Self {
7		Self
8	}
9}
10
11impl codec::Input for Null {
12	fn read(&mut self, bytes: &mut [u8]) -> Result<(), codec::Error> {
13		bytes.fill(0);
14		Ok(())
15	}
16	fn remaining_len(&mut self) -> Result<Option<usize>, codec::Error> {
17		Ok(None)
18	}
19}
20
21pub trait DecodeInto {
22	fn decode_into<T: Decode>(&mut self) -> Result<T, codec::Error>;
23}
24
25impl<T: codec::Input> DecodeInto for T {
26	fn decode_into<U: Decode>(&mut self) -> Result<U, codec::Error> {
27		Decode::decode(self)
28	}
29}
30
31pub trait NewNull {
32	#[allow(dead_code)]
33	fn new_null() -> Self;
34}
35
36impl<T: Decode> NewNull for T {
37	fn new_null() -> Self {
38		Null::new().decode_into().expect("infallible for nullable values; qed")
39	}
40}