opensearch_client/common/
wait_for_nodes.rs1use serde::{Deserialize, Serialize};
11
12
13
14#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
15#[serde(untagged)]
16pub enum WaitForNodes {
17 StringValue(String),
18 CountValue(u64),
19}
20
21impl std::fmt::Display for WaitForNodes {
22 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
23 match self {
24 WaitForNodes::StringValue(s) => write!(f, "{}", s),
25 WaitForNodes::CountValue(n) => write!(f, "{}", n),
26 }
27 }
28}
29
30
31impl WaitForNodes {
32 pub fn as_str(&self) -> String {
33 match self {
34 WaitForNodes::StringValue(s) => s.clone(),
35 WaitForNodes::CountValue(n) => n.to_string(),
36 }
37 }
38
39 pub fn as_num(&self) -> Option<u64> {
40 match self {
41 WaitForNodes::CountValue(n) => Some(*n),
42 _ => None,
43 }
44 }
45}
46
47impl From<u64> for WaitForNodes {
48 fn from(n: u64) -> Self {
49 WaitForNodes::CountValue(n)
50 }
51}
52
53impl From<&str> for WaitForNodes {
54 fn from(s: &str) -> Self {
55 WaitForNodes::StringValue(s.to_string())
56 }
57}
58
59impl From<String> for WaitForNodes {
60 fn from(s: String) -> Self {
61 WaitForNodes::StringValue(s)
62 }
63}