testnumbat_codec/impl_for_types/
impl_unit.rs

1use crate::{
2    dep_encode_from_no_err, nested_ser::NestedEncodeNoErr, top_encode_from_no_err,
3    top_ser::TopEncodeNoErr, DecodeError, EncodeError, NestedDecode, NestedDecodeInput,
4    NestedEncode, NestedEncodeOutput, TopDecode, TopDecodeInput, TopEncode, TopEncodeOutput,
5    TypeInfo,
6};
7
8impl TopEncodeNoErr for () {
9    #[inline]
10    fn top_encode_no_err<O: TopEncodeOutput>(&self, output: O) {
11        output.set_unit();
12    }
13}
14
15top_encode_from_no_err! {(), TypeInfo::Unit}
16
17impl TopDecode for () {
18    const TYPE_INFO: TypeInfo = TypeInfo::Unit;
19
20    fn top_decode<I: TopDecodeInput>(_: I) -> Result<Self, DecodeError> {
21        Ok(())
22    }
23
24    fn top_decode_or_exit<I: TopDecodeInput, ExitCtx: Clone>(
25        _: I,
26        _: ExitCtx,
27        _: fn(ExitCtx, DecodeError) -> !,
28    ) -> Self {
29    }
30}
31
32impl NestedEncodeNoErr for () {
33    fn dep_encode_no_err<O: NestedEncodeOutput>(&self, _: &mut O) {}
34}
35
36dep_encode_from_no_err! {(), TypeInfo::Unit}
37
38impl NestedDecode for () {
39    const TYPE_INFO: TypeInfo = TypeInfo::Unit;
40
41    fn dep_decode<I: NestedDecodeInput>(_: &mut I) -> Result<(), DecodeError> {
42        Ok(())
43    }
44
45    fn dep_decode_or_exit<I: NestedDecodeInput, ExitCtx: Clone>(
46        _: &mut I,
47        _: ExitCtx,
48        _: fn(ExitCtx, DecodeError) -> !,
49    ) -> Self {
50    }
51}