use simple_json_server::{actor, Actor};
#[derive(Debug, Clone)]
pub struct DocumentedActor {
pub name: String,
pub count: i32,
}
impl DocumentedActor {
pub fn new(name: String) -> Self {
Self { name, count: 0 }
}
}
#[actor]
impl DocumentedActor {
pub async fn add(&self, a: i32, b: i32) -> i32 {
a + b
}
pub async fn get_count(&self) -> i32 {
self.count
}
pub async fn greet(&self, name: String) -> String {
format!("Hello {}, I'm {}!", name, self.name)
}
pub async fn calculate_area(&self, width: f64, height: f64) -> f64 {
width * height
}
pub async fn is_even(&self, number: i32) -> bool {
number % 2 == 0
}
pub async fn info(&self) -> String {
format!(
"DocumentedActor named '{}' with count {}",
self.name, self.count
)
}
pub async fn ping(&self) -> String {
"pong".to_string()
}
}
#[tokio::main]
async fn main() {
let actor = DocumentedActor::new("TestActor".to_string());
println!("Testing documented actor methods:");
let result = actor.dispatch("add", r#"{"a": 10, "b": 5}"#).await;
println!("add(10, 5) = {}", result);
let result = actor.dispatch("greet", r#"{"name": "World"}"#).await;
println!("greet(\"World\") = {}", result);
let result = actor.dispatch("ping", "{}").await;
println!("ping() = {}", result);
let result = actor.dispatch("is_even", r#"{"number": 42}"#).await;
println!("is_even(42) = {}", result);
println!("\nTo see the generated documentation, run:");
println!("cargo doc --open");
}