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