coap-message 0.2.3

Interface to CoAP messages
Documentation
// Long-term, it'd be good to also have an interface like this:
// (Some of that may be possible now, but I rather wait for const generics than hack around with
// typenum)
//
// pub struct TypedStateWritableCoAPOverUDPMessage<const OPTION: u16, const STORAGE: usize>(() /* well */);
// trait OptionAppendableMessage<const OPTION: u16, const OPTLEN: usize> {
//     type AfterAppend;
//
//     // fn append...
// }
// impl<const OPTOLD: u16, const OPTNEW: u16, const OPTLEN: usize, const STORAGENEW: usize> OptionAppendableMessage<{OPTNEW}, {OPTLEN}> for TypedStateWritableCoAPOverUDPMessage<OPTOLD, {STORAGENEW + 1}>
// //     where
// //         OPTOLD: OPTNEW
// {
//     type AfterAppend = TypedStateWritableCoAPOverUDPMessage<{OPTNEW}, {STORAGENEW /*.wrapping_sub(5 /* or something sharper */ + OPTLEN )*/}>;
// }

// Besides the cumbersome notation for operations, the additional hoops one'd need to jump through
// to make &[u8; OPTLEN] work add to the impracticality of this in favor of waiting for const
// generics.

pub struct TypedStateWritableCoAPOverUDPMessage<
    OPTION: typenum::Unsigned,
    STORAGE: typenum::Unsigned,
> {
    /* ... */
    _phantom: core::marker::PhantomData<(OPTION, STORAGE)>,
}
trait OptionAppendableMessage<OPTION: typenum::Unsigned, OPTLEN: typenum::Unsigned> {
    type AfterAppend;

    //     fn append(self, option: &[u8; OPTLEN]) -> Self::AfterAppend;
}
impl<OPTOLD, OPTNEW, OPTLEN, STORAGEBEFORE> OptionAppendableMessage<OPTNEW, OPTLEN>
    for TypedStateWritableCoAPOverUDPMessage<OPTOLD, STORAGEBEFORE>
where
    OPTOLD: typenum::Unsigned,
    OPTNEW: typenum::Unsigned + typenum::type_operators::IsGreaterOrEqual<OPTOLD>,
    OPTLEN: typenum::Unsigned,
    STORAGEBEFORE: typenum::Unsigned + core::ops::Sub<OPTLEN>,
    <OPTNEW as typenum::type_operators::IsGreaterOrEqual<OPTOLD>>::Output: typenum::NonZero,
    // No need to do any comparison here -- this does the comparison implicitly and is needed
    // anyway
    <STORAGEBEFORE as core::ops::Sub<OPTLEN>>::Output: typenum::Unsigned,
{
    type AfterAppend = TypedStateWritableCoAPOverUDPMessage<
        OPTNEW,
        <STORAGEBEFORE as core::ops::Sub<OPTLEN>>::Output,
    >;

    //     fn append(self, option: &[u8; OPTLEN]) -> Self::AfterAppend {
    //         unimplemented!()
    //     }
}