#[repr(C)]pub struct Command<T: Copy> {
pub payload: T,
/* private fields */
}
Expand description
A cFS-flavor CCSDS command packet, as a Rust structure.
Fields§
§payload: T
The message’s payload. As messages are copied
willy-nilly, T
needs to be Copy
.
Implementations§
source§impl<T: Copy> Command<T>
impl<T: Copy> Command<T>
sourcepub fn new(msg_id: u32, function_code: u16, payload: T) -> Result<Self, ()>
pub fn new(msg_id: u32, function_code: u16, payload: T) -> Result<Self, ()>
If msg_id
and function_code
are a permissible message ID and a permissible command code (respectively),
returns a new Command
with the payload initialized to payload
; otherwise returns an error.
sourcepub fn new_default(msg_id: u32, function_code: u16) -> Result<Self, ()>where
T: Default,
pub fn new_default(msg_id: u32, function_code: u16) -> Result<Self, ()>where
T: Default,
Self::new
, but using Default::default
()
as the payload.
sourcepub fn as_bytes(&self) -> &[u8] ⓘ
pub fn as_bytes(&self) -> &[u8] ⓘ
Returns a view of the Command
as a sequence of bytes, ready for transmission.
sourcepub unsafe fn from_bytes(bytes: &[u8]) -> Result<Self, ()>
pub unsafe fn from_bytes(bytes: &[u8]) -> Result<Self, ()>
Turns a sequence of bytes representing a message into a Command
,
assuming bytes
is the correct length and the header bytes have sane values.
§Safety
Using this function is only safe if the part of bytes
at bytes 8..(8 + std::mem::size_of::<T>())
is byte-for-byte equal to a valid item of type T
.
sourcepub fn function_code(&self) -> u16
pub fn function_code(&self) -> u16
Returns the message’s command code.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Command<T>where
T: Freeze,
impl<T> RefUnwindSafe for Command<T>where
T: RefUnwindSafe,
impl<T> Send for Command<T>where
T: Send,
impl<T> Sync for Command<T>where
T: Sync,
impl<T> Unpin for Command<T>where
T: Unpin,
impl<T> UnwindSafe for Command<T>where
T: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)