async-std 1.13.1

Deprecated in favor of `smol` - Async version of the Rust standard library
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//! Creates a task-local value.

use std::cell::Cell;

use async_std::prelude::*;
use async_std::task;

task_local! {
    static VAR: Cell<i32> = Cell::new(1);
}

fn main() {
    task::block_on(async {
        println!("var = {}", VAR.with(|v| v.get()));
        VAR.with(|v| v.set(2));
        println!("var = {}", VAR.with(|v| v.get()));
    })
}