simple_jsonrpc_client/id_generator.rs
1use std::sync::atomic::{AtomicU64, Ordering};
2
3#[derive(Debug)]
4pub struct IdGenerator {
5 state: AtomicU64,
6}
7
8impl Default for IdGenerator {
9 fn default() -> Self {
10 IdGenerator {
11 state: AtomicU64::new(1),
12 }
13 }
14}
15
16impl IdGenerator {
17 pub fn new() -> IdGenerator {
18 IdGenerator::default()
19 }
20
21 pub fn next(&self) -> u64 {
22 self.state.fetch_add(1, Ordering::SeqCst)
23 }
24}