arty 0.5.0

Single-threaded, thread-aware application runtime.
Documentation
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

//! Scoped execution preserves owned and borrowed captures.

#![cfg(feature = "rt")]

testing_aids::init_tracing!();

use arty::runtime::Runtime;

#[test]
fn capture_by_value() {
    #[expect(clippy::useless_vec, reason = "using a vec to test with a type using pointers on the inside")]
    let vec = vec![10, 11];
    let result = Runtime::new()
        .expect("Failed to create runtime")
        .scheduler()
        .block_on(async move |_ctx| vec.len() + 10)
        .unwrap();
    assert_eq!(result, 12);
}

#[test]
fn move_and_spawn() {
    #[expect(clippy::useless_vec, reason = "using a vec to test with a type using pointers on the inside")]
    let vec = vec![10, 11];
    let result = Runtime::new()
        .expect("Failed to create runtime")
        .scheduler()
        .block_on(async move |ctx| {
            let child = ctx.scheduler().spawn(async move |_ctx| vec.len() + 10);
            child.await.unwrap()
        })
        .unwrap();
    assert_eq!(result, 12);
}

#[test]
fn capture_reference() {
    let vec = vec![10, 11];
    let result = Runtime::new()
        .expect("Failed to create runtime")
        .scheduler()
        .block_on(async |_ctx| {
            let vec_ref = &vec;
            vec_ref.len() + 10
        })
        .unwrap();
    assert_eq!(vec.len() + 10, result);
}

#[test]
fn capture_mut_reference() {
    let mut vec = vec![10, 11];
    let result = Runtime::new()
        .expect("Failed to create runtime")
        .scheduler()
        .block_on(async |_ctx| {
            let vec_ref = &mut vec;
            vec_ref.push(15);
            vec_ref.len() + 10
        })
        .unwrap();
    assert_eq!(vec.len() + 10, result);
    assert_eq!(vec.len(), 3);
}