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
use coap_message::error::RenderableOnMinimal;

/// Error type for manipulation of [crate::inmemory_write] messages.
///
/// This is presented externally as an internal server error, but has enough structure to be useful
/// for debugging through `dbg!()`.
#[derive(Debug)]
#[non_exhaustive]
pub enum WriteError {
    OutOfSequence,
    OutOfSpace,
}

impl RenderableOnMinimal for WriteError {
    type Error<IE: RenderableOnMinimal + core::fmt::Debug> = IE;
    fn render<M: coap_message::MinimalWritableMessage>(
        self,
        msg: &mut M,
    ) -> Result<(), Self::Error<M::UnionError>> {
        coap_message_utils::Error::internal_server_error().render::<M>(msg)
    }
}

impl From<core::convert::Infallible> for WriteError {
    fn from(never: core::convert::Infallible) -> Self {
        match never {}
    }
}