Skip to main content

Command

Trait Command 

Source
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§

Source

fn to_bytes(&self) -> Result<Vec<u8>, CodecError>

Encode this command to postcard bytes for the log/wire.

§Errors

Returns CodecError if serialization fails.

Source

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".

Implementors§

Source§

impl<T> Command for T
where T: Clone + Send + 'static + Serialize + DeserializeOwned,