Skip to main content

apis_saltans_aps/frame/
command.rs

1//! APS Command Frame.
2
3use le_stream::{FromLeStream, ToLeStream};
4
5pub use self::header::Header;
6
7mod header;
8
9/// APS Command Frame.
10#[derive(Clone, Debug, Eq, Hash, PartialEq, FromLeStream, ToLeStream)]
11pub struct Frame<T> {
12    header: Header,
13    payload: T,
14}
15
16impl<T> Frame<T> {
17    /// Create a new command frame.
18    ///
19    /// # Safety
20    ///
21    /// The caller must ensure that the provided header is consistent with the payload.
22    #[expect(unsafe_code)]
23    #[must_use]
24    pub const unsafe fn new_unchecked(header: Header, payload: T) -> Self {
25        Self { header, payload }
26    }
27
28    /// Return a reference to the header.
29    #[must_use]
30    pub const fn header(&self) -> &Header {
31        &self.header
32    }
33
34    /// Return a reference to the payload.
35    #[must_use]
36    pub const fn payload(&self) -> &T {
37        &self.payload
38    }
39
40    /// Return the header and payload consuming the frame.
41    #[must_use]
42    pub fn into_parts(self) -> (Header, T) {
43        (self.header, self.payload)
44    }
45}