Crates.io | goon_rs |
lib.rs | goon_rs |
version | 0.1.0 |
source | src |
created_at | 2024-02-19 17:02:57.220722 |
updated_at | 2024-02-19 17:02:57.220722 |
description | Static Refs for Rust on the Network Level. |
homepage | |
repository | https://github.com/JustBobinAround/goon-rs |
max_upload_size | |
id | 1145474 |
size | 6,021 |
That's right! Globals (ie static refs) to share program state on LANs. No need to touch a web protocol, we do it for you.
use std::time::Duration;
use goon::*;
// any program that has this section
// will share variable states of the same name:
declare_global!{
A: u32 = 0;
}
#[goon_init]
fn main() {
// variables being used must be redeclared
// in current scope
global!(A);
println!("listening for peers...");
for i in 0..10000 {
std::thread::sleep(Duration::from_millis(100));
// local-global variables are
// then handle as lowercase to avoid name overlaps
lock_globals!(|a| => {
println!("sending update");
*a= i;
});
std::thread::sleep(Duration::from_millis(100));
read_globals!(|a| => {
println!("reading current val: {}", *a);
});
}
}