use anyhow::Result;
use tracing::info;
use rogue_runtime::prelude::*;
rpc! {
pub trait TestTrait {
async fn a(&self) -> i32;
async fn b(&self) -> i32;
}
struct TraitTest(InstanceId);
impl TraitTest {
pub async fn new() -> Self {
Self(InstanceId::new())
}
}
impl Identity for TraitTest {
fn id(&self) -> &InstanceId {
&self.0
}
}
impl TestTrait for TraitTest {
async fn a(&self) -> i32 {
42
}
async fn b(&self) -> i32 {
9001
}
}
}
async fn test_fn(x: impl TestTrait) {
let a = x.a().await;
let b = x.b().await;
info!(a = %a, b = %b);
}
#[tokio::main]
async fn main() -> Result<()> {
tracing_subscriber::fmt()
.with_env_filter("traits=info,runtime=trace")
.pretty()
.init();
info!("starting local example");
let runtime = Runtime::create("traits".to_string()).await?;
runtime
.execute_local(async move {
let x = TraitTest::new().await;
info!(id = %x.id());
test_fn(x).await;
Ok(())
})
.await?;
Ok(())
}