Skip to main content

Query

Trait Query 

Source
pub trait Query: 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 read-only query served by the StateMachine.

Queries never enter the log; they are answered locally after the ReadIndex protocol confirms the leader is current (read-consistency). They still cross task boundaries and may be sent to a remote leader, hence Send + 'static + serde. Unlike a Command, a query need not be Clone.

Required Methods§

Source

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

Encode this query to postcard bytes for the wire.

§Errors

Returns CodecError if serialization fails.

Source

fn from_bytes(bytes: &[u8]) -> Result<Self, CodecError>
where Self: Sized,

Decode a query from postcard bytes.

§Errors

Returns CodecError if deserialization fails.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

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