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

ActorCore is still pre-v1.0. Please help us by report bugs on GitHub Issues!

Quickstart

1

Create a new Rust project

Create a new Rust project:

cargo new my-app
cd my-app
2

Add dependencies

Add ActorCore client & related dependencies to your project:

cargo add actor-core-client
cargo add serde_json
cargo add tokio --features full
3

Define your actor

Create a file actors/app.ts in your project with your actor definition:

actors/app.ts
import { actor, setup } from "actor-core";

// Create actor
const counter = actor({
  state: { count: 0 },
  actions: {
    increment: (c, x: number) => {
  	c.state.count += x;
  	c.broadcast("newCount", c.state.count);
  	return c.state.count;
    }
  }
});

// Create the application
export const app = setup({
  actors: { counter },
  cors: { origin: "*" } // Configure CORS for your production domains in production
});

// Export app type for client usage
export type App = typeof app;
4

Create your client

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

src/main.rs
use actor_core_client::{Client, GetOptions, TransportKind, EncodingKind};
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:6420".to_string(),
        TransportKind::WebSocket,
        EncodingKind::Cbor,
    );
    
    // Get or create an actor instance
    let options = GetOptions::default();
    let counter = client.get("counter", options).await?;
    
    // 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(())
}
5

Start your ActorCore development server

Launch the development server with:

npx @actor-core/cli@latest dev actors/app.ts

This will automatically start your app and open the studio in your browser. The studio supports hot-reloading, state inspection, visual RPC testing, and more debugging tools.

6

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.

7

Deploy your ActorCore app

Now that you have your project running, deploy your application to one of these platforms:

Next Steps