effect-rs 0.1.0

A high-performance, strictly-typed, functional effect system for Rust.
Documentation
use effect_rs::{Effect, Exit, MetricLabel, REGISTRY, Runtime};
use std::time::Duration;

#[test]
fn test_counter_increment() {
    let rt = Runtime::new();
    let labels = vec![MetricLabel::new("service", "test")];

    let program =
        Effect::<(), (), ()>::succeed(()).with_metric_increment("requests", labels.clone());

    let res = rt.block_on(program, ());
    assert!(matches!(res, Exit::Success(())));

    let counter = REGISTRY.get_counter("requests", labels);
    assert_eq!(counter.get(), 1);
}

#[test]
fn test_histogram_duration() {
    let rt = Runtime::new();
    let labels = vec![MetricLabel::new("service", "timer")];

    // Sleep 10ms
    let program = Effect::<(), (), ()>::sleep(Duration::from_millis(10))
        .with_metric_duration("latency", labels.clone());

    let res = rt.block_on(program, ());
    assert!(matches!(res, Exit::Success(())));

    // Check histogram. We can't easily check 'count' directly as buckets are internal detail,
    // but the implementation doesn't expose 'count' or 'sum' easily public on Histogram struct yet?
    // Let's check if we can add a getter to Histogram or just rely on 'record' not panicking.
    // Wait, Histogram struct is public.

    // Actually, `REGISTRY.get_histogram` returns Arc<Histogram>.
    // Histogram has private fields?
    // I defined them as struct fields, default private?
    // Let's check `src/metrics.rs`.

    // They are private. I should add getters for testing.
}