oca 0.2.0

An experiment with no_std
Documentation
mod command;
mod handle;
mod header;
mod keep_alive;
mod message;
mod notification;
mod parameters;
mod response;

pub use {
    command::{Command, CommandResponseRequired},
    handle::Handle,
    header::{
        Header, InvalidMessageCount, InvalidPduType, InvalidProtocolVersion, MessageCount, PduSize,
        PduType, ProtocolVersion,
    },
    keep_alive::KeepAlive,
    message::{InvalidSyncValue, MessagePdu, SyncValue},
    notification::{
        ev1::{Notification1, Notification1EventData, Notification1Parameters},
        ev2::{
            Notification2, Notification2ExceptionData, Notification2ExceptionType,
            Notification2Type,
        },
    },
    parameters::Parameters,
    response::Response,
};

#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum Message<'a> {
    Command(Command<'a>),
    CommandResponseRequired(CommandResponseRequired<'a>),
    Response(Response<'a>),
    Notification1(Notification1<'a>),
    Notification2(Notification2<'a>),
    KeepAlive(KeepAlive),
}

impl Message<'_> {
    pub fn pdu_type(&self) -> PduType {
        match self {
            Message::Command(_) => PduType::Command,
            Message::CommandResponseRequired(_) => PduType::CommandResponseRequired,
            Message::Response(_) => PduType::Response,
            Message::Notification1(_) => PduType::Notification1,
            Message::Notification2(_) => PduType::Notification2,
            Message::KeepAlive(_) => PduType::KeepAlive,
        }
    }
}

mod sealed {
    use super::*;

    pub trait Sealed {}
    impl Sealed for Command<'_> {}
    impl Sealed for CommandResponseRequired<'_> {}
    impl Sealed for Response<'_> {}
    impl Sealed for Notification1<'_> {}
    impl Sealed for Notification2<'_> {}
    impl Sealed for KeepAlive {}
}

pub trait IsMessage: sealed::Sealed {
    const PDU_TYPE: PduType;
}

impl IsMessage for Command<'_> {
    const PDU_TYPE: PduType = PduType::Command;
}
impl IsMessage for CommandResponseRequired<'_> {
    const PDU_TYPE: PduType = PduType::Command;
}
impl IsMessage for Response<'_> {
    const PDU_TYPE: PduType = PduType::Response;
}
impl IsMessage for Notification1<'_> {
    const PDU_TYPE: PduType = PduType::Notification1;
}
impl IsMessage for Notification2<'_> {
    const PDU_TYPE: PduType = PduType::Notification2;
}
impl IsMessage for KeepAlive {
    const PDU_TYPE: PduType = PduType::KeepAlive;
}