wisp/request.rs
1use std::sync::atomic::{AtomicU64, Ordering};
2
3/// Correlates an in-flight request with its eventual result.
4#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
5pub struct RequestId(u64);
6
7impl RequestId {
8 /// Returns an ID no other caller will hand out.
9 pub fn next() -> Self {
10 static NEXT: AtomicU64 = AtomicU64::new(1);
11 Self(NEXT.fetch_add(1, Ordering::Relaxed))
12 }
13}
14
15impl From<u64> for RequestId {
16 fn from(value: u64) -> Self {
17 Self(value)
18 }
19}