pub trait Command:
Clone
+ Send
+ 'static {
// Required methods
fn to_bytes(&self) -> Result<Vec<u8>, CodecError>;
fn from_bytes(bytes: &[u8]) -> Result<Self, CodecError>
where Self: Sized;
}Expand description
A replicated command applied to the StateMachine.
Commands are serialized into the Raft log, shipped to peers, and later
decoded and applied, so they must be self-owned ('static), Cloneable
(a leader may retry replication), and Send (they cross task/actor
boundaries). Any type meeting those bounds plus serde gets a Command
implementation for free via the blanket impl below — derive
#[derive(Clone, Serialize, Deserialize)] and you are done.
Required Methods§
Sourcefn to_bytes(&self) -> Result<Vec<u8>, CodecError>
fn to_bytes(&self) -> Result<Vec<u8>, CodecError>
Encode this command to postcard bytes for the log/wire.
§Errors
Returns CodecError if serialization fails.
Sourcefn from_bytes(bytes: &[u8]) -> Result<Self, CodecError>where
Self: Sized,
fn from_bytes(bytes: &[u8]) -> Result<Self, CodecError>where
Self: Sized,
Decode a command from postcard bytes read back from the log/wire.
§Errors
Returns CodecError if deserialization fails.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".