Thread with 5 posts

jump to expanded post

a friend asked me about concurrency in Rust and honest to god, I had never done it before, I only just now looked at the Rust manual, and I managed to write something perfectly correct and safe and really simple, first try

Open thread at this post

like, this is a thread-safe one-time-set global flag:

use std::sync::OnceLock;

static VERBOSE: OnceLock<bool> = OnceLock::new();

fn set_verbose_once(value: bool) {
    VERBOSE.set(value).unwrap()
}
fn get_verbose() -> bool {
    VERBOSE.get().copied().unwrap()
}
Open thread at this post