Skip to main content

Crate rabia_counter_example

Crate rabia_counter_example 

Source
Expand description

§Counter SMR Example

A simple counter implementation that demonstrates how to create a State Machine Replication (SMR) application using the Rabia consensus protocol.

This example shows the minimal implementation needed to create an SMR application:

  • Command types for operations
  • Response types for results
  • State type for the machine state
  • StateMachine trait implementation

§Example Usage

use rabia_counter_example::{CounterSMR, CounterCommand};
use rabia_core::smr::StateMachine;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut counter = CounterSMR::new();
     
    let command = CounterCommand::Increment(5);
    let response = counter.apply_command(command).await;
    println!("Counter value: {}", response.value);
     
    Ok(())
}

Structs§

CounterResponse
Response from counter operations
CounterSMR
Simple counter state machine implementation
CounterState
State of the counter state machine

Enums§

CounterCommand
Commands that can be applied to the counter