rogue-runtime 0.1.0

Async RPC Runtime
Documentation
use anyhow::Result;

use rogue_runtime::prelude::*;

// Recursive binomial coefficient (n choose k) via RPC
rpc! {
    pub async fn binom(n: u32, k: u32) -> u32 {
        if k == 0 || k == n {
            1
        } else {
            // Each recursive call is dispatched via RPC
            let left = binom(n - 1, k - 1).await;
            let right = binom(n - 1, k).await;
            left + right
        }
    }
}

#[tokio::test]
async fn test_rpc_runtime() -> Result<()> {
    let runtime = Runtime::create("test".to_string()).await?;

    runtime
        .execute_local(async move {
            assert_eq!(binom(10, 3).await, 120);
            assert_eq!(binom(10, 5).await, 252);
            assert_eq!(binom(15, 0).await, 1);
            assert_eq!(binom(15, 15).await, 1);
            Ok(())
        })
        .await?;

    Ok(())
}