1 个不稳定版本
0.1.0 | 2024年2月19日 |
---|
#18 在 #lan
7KB
105 代码行
GOON-RS: 我们的网络上有全局变量吗?!
没错!在局域网中共享程序状态的全局变量(即静态引用)。无需触摸网络协议,我们为您完成。
使用方法
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);
});
}
}
待定
依赖项
~0.7–1.6MB
~35K SLoC