1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use async_std::sync::{Arc, Mutex};
use serde::{Deserialize, Serialize};
use std::fmt;
#[derive(Clone, Default)]
pub struct ReadyIndicator(Arc<Mutex<bool>>);
impl ReadyIndicator {
pub fn new(ready: bool) -> Self {
ReadyIndicator(Arc::new(Mutex::new(ready)))
}
pub async fn ready(&self) {
*self.0.lock().await = true;
}
pub async fn not_ready(&self) {
*self.0.lock().await = false;
}
pub async fn inner(&self) -> bool {
*self.0.lock().await
}
}
#[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(untagged)]
pub enum ID {
Num(u64),
Str(String),
Null(serde_json::Value),
}
impl std::fmt::Display for ID {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
ID::Num(ref e) => write!(f, "{}", e),
ID::Str(ref e) => write!(f, "{}", e),
ID::Null(ref _e) => write!(f, "null"),
}
}
}