Skip to main content

define_command

Macro define_command 

Source
macro_rules! define_command {
    ($name:ident, Read, $kind:expr, $number:expr, $I:ty, $O:ty) => { ... };
    ($name:ident, Write, $kind:expr, $number:expr, $I:ty, $O:ty) => { ... };
    ($name:ident, $direction:expr, $kind:expr, $number:expr, $I:ty, $O:ty) => { ... };
}
Expand description

Defines a control command: a unit struct implementing ControlCommand.

The input and output types are the command payload types. They must be plain data (PlainData): every payload byte pattern is then a valid value of the payload type, so a guest can never send an invalid value such as 2 for a bool. A bool or enum cannot be a payload type because not every byte pattern is one of its values; store such values as integers in the payload and convert them with TryFrom where the value is read.

ⓘ
use file_system::{ControlCommand, define_command};

// `bool` is not plain data: the payload byte `2` would be an invalid `bool`.
define_command!(EXAMPLE, Read, b'x', 0, bool, ());