You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
async-std/examples/task-local.rs

21 lines
375 B
Rust

5 years ago
//! Creates a task-local value.
#![feature(async_await)]
use std::cell::Cell;
5 years ago
use async_std::prelude::*;
use async_std::task;
5 years ago
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()));
})
}