2个不稳定版本
使用旧的Rust 2015
0.2.3 | 2017年2月6日 |
---|---|
0.1.0 | 2017年2月2日 |
在#cs中排名8
7KB
149 行
acid-state
Rust事务状态库
#[macro_use] extern crate acid-state;
#[derive(Debug, RustcEncodable, RustcDecodable)]
struct A {
i: u64,
}
acid_state! {
pub a: A = A { i: 0 };
}
fn main() {
println!("a initialized or loaded from disk is {}", *a);
acid! {
a.i += 1
}
println!("a is now {}", *a);
}
lib.rs
:
acid-state
为任何可序列化结构添加了持久的交易支持。事务状态。
示例
#[macro_use]
extern crate acid_state;
#[macro_use]
extern crate lazy_static;
extern crate rustc_serialize;
use std::collections::HashMap;
#[derive(Debug, RustcDecodable, RustcEncodable)]
struct Cs {
v: u64,
}
acid_state! {
A: HashMap<String, u64> = HashMap::new();
B: u64 = 0;
C: Cs = Cs {
v: 0
};
}
let key = "yo".to_owned();
acid! {
(A => a, B => b, C => c) => {
// A, B, C have been pulled off disk
let mut current = a.entry(key).or_insert(0);
**b += 1;
*current += 1;
c.v += 1;
println!("a is now {:?}", current);
println!("b is now {:?}", **b);
println!("c is now {:?}", c.v);
// new values of A, B, C are now synced on disk
}
};
依赖关系
~1.5MB
~28K SLoC