effect-rs 0.1.0

A high-performance, strictly-typed, functional effect system for Rust.
Documentation
use effect_rs::{Effect, Env, Exit, Runtime};

struct KeyService {
    key: String,
}

#[test]
fn test_env_injection() {
    let rt = Runtime::new();

    let mut env = Env::new();
    env.insert(KeyService {
        key: "secret".to_string(),
    });

    let program: Effect<Env, (), String> =
        Effect::access_async(|env_ref: effect_rs::EnvRef<Env>, _| {
            // Manually accessing Env for now.
            // We need a helper `Effect::service` eventually.
            let service = env_ref.value.get::<KeyService>().unwrap();
            let key = service.key.clone();
            async move { key }
        });

    let result = rt.block_on(program, env);

    match result {
        Exit::Success(val) => assert_eq!(val, "secret"),
        Exit::Failure(_) => panic!("Expected success"),
    }
}