jam_std_common/util/
null.rs1use scale::Decode;
2
3pub struct Null;
4
5impl Null {
6 pub fn new() -> Self {
7 Self
8 }
9}
10
11impl scale::Input for Null {
12 fn read(&mut self, bytes: &mut [u8]) -> Result<(), scale::Error> {
13 bytes.fill(0);
14 Ok(())
15 }
16 fn remaining_len(&mut self) -> Result<Option<usize>, scale::Error> {
17 Ok(None)
18 }
19}
20
21pub trait DecodeInto {
22 fn decode_into<T: Decode>(&mut self) -> Result<T, scale::Error>;
23}
24
25impl<T: scale::Input> DecodeInto for T {
26 fn decode_into<U: Decode>(&mut self) -> Result<U, scale::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}