1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
//! Implementations of our traits for various [core] types

use crate::error::RenderableOnMinimal;
use core::fmt::Debug;

impl RenderableOnMinimal for core::convert::Infallible {
    type Error<IE: RenderableOnMinimal + Debug> = core::convert::Infallible;

    fn render<M: crate::MinimalWritableMessage>(
        self,
        _: &mut M,
    ) -> Result<(), core::convert::Infallible> {
        match self {}
    }
}

impl<T: RenderableOnMinimal, E: RenderableOnMinimal> RenderableOnMinimal for Result<T, E> {
    type Error<IE: RenderableOnMinimal + Debug> = Result<T::Error<IE>, E::Error<IE>>;

    fn render<M: crate::MinimalWritableMessage>(
        self,
        msg: &mut M,
    ) -> Result<(), Self::Error<M::UnionError>> {
        Ok(match self {
            Ok(t) => t.render(msg).map_err(Ok)?,
            Err(e) => e.render(msg).map_err(Err)?,
        })
    }
}