posemesh_compute_node/storage/token.rs
1//! TokenRef for hot-swappable bearer tokens used by storage requests.
2
3#[derive(Clone)]
4pub struct TokenRef(std::sync::Arc<parking_lot::RwLock<String>>);
5
6impl TokenRef {
7 /// Create a new token reference with an initial value.
8 pub fn new(initial: String) -> Self {
9 Self(std::sync::Arc::new(parking_lot::RwLock::new(initial)))
10 }
11
12 /// Get a clone of the current token.
13 pub fn get(&self) -> String {
14 self.0.read().clone()
15 }
16
17 /// Swap the token value with a new one.
18 pub fn swap(&self, v: String) {
19 *self.0.write() = v;
20 }
21}