The RivetKit Rust client provides a way to connect to and interact with actors from Rust applications.

Quickstart

1

Create a new Rust project

Create a new Rust project:

cargo new my-app
cd my-app
2

Add dependencies

Add RivetKit client & related dependencies to your project:

cargo add rivetkit-client
cargo add serde_json
cargo add tokio --features full
3

Create your client

Modify src/main.rs to connect to your actor:

src/main.rs
use rivetkit_client::{Client, EncodingKind, GetOrCreateOptions, TransportKind};
use serde_json::json;
use std::time::Duration;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Replace with your endpoint URL after deployment
    let client = Client::new(
        "http://localhost:8080",
        TransportKind::Sse,
        EncodingKind::Json
    );
    
    // Get or create an actor instance
    let options = GetOrCreateOptions::default();
    let counter = client.get("counter", [].into(), options)?
      .connect();
    
    // Subscribe to events
    counter.on_event("newCount", |args| {
        let count = args[0].as_i64().unwrap();
        println!("Event: {}", count);
    }).await;
    
    // Call an action
    let result = counter.action("increment", vec![json!(5)]).await?;
    println!("Action: {}", result);
    
    // Wait to receive events
    tokio::time::sleep(Duration::from_secs(1)).await;
    
    Ok(())
}
4

Run your client

In a separate terminal, run your client code:

cargo run

You should see output like:

Event: 5
Action: 5

Run it again to see the state update.