1use serde::de::{self, Deserializer, Visitor};
2use serde::{Deserialize, Serialize};
3use std::fmt;
4use std::path::PathBuf;
5
6struct NumToBoolVisitor;
7
8impl<'de> Visitor<'de> for NumToBoolVisitor {
9 type Value = bool;
10
11 fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
12 formatter.write_str("0 or 1 or true or false")
13 }
14
15 fn visit_bool<E>(self, value: bool) -> Result<Self::Value, E>
16 where
17 E: de::Error,
18 {
19 Ok(value)
20 }
21
22 fn visit_i64<E>(self, value: i64) -> Result<Self::Value, E>
23 where
24 E: de::Error,
25 {
26 Ok(value != 0)
27 }
28
29 fn visit_u64<E>(self, value: u64) -> Result<Self::Value, E>
30 where
31 E: de::Error,
32 {
33 Ok(value != 0)
34 }
35}
36
37fn num_to_bool<'de, D>(deserializer: D) -> Result<bool, D::Error>
38where
39 D: Deserializer<'de>,
40{
41 deserializer.deserialize_any(NumToBoolVisitor)
42}
43
44#[derive(Debug, Clone, Serialize, Deserialize)]
46#[allow(non_snake_case)]
47pub struct SystemInfo {
48 pub ID: String,
49 pub Containers: u64,
50 pub Images: u64,
54 pub Driver: String,
55 pub DriverStatus: Vec<(String, String)>,
56 pub DockerRootDir: PathBuf,
57 #[serde(deserialize_with = "num_to_bool")]
58 pub MemoryLimit: bool,
59 #[serde(deserialize_with = "num_to_bool")]
60 pub SwapLimit: bool,
61 #[serde(deserialize_with = "num_to_bool")]
64 pub IPv4Forwarding: bool,
65 #[serde(deserialize_with = "num_to_bool")]
68 pub Debug: bool,
69 pub NFd: u64,
70 pub NGoroutines: u64,
71 pub NEventsListener: u64,
75 pub OperatingSystem: String,
77 pub NCPU: u64,
80 pub MemTotal: u64,
81 pub IndexServerAddress: String,
82 pub Labels: Option<Vec<String>>,
87 }
89
90#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
92#[allow(non_snake_case)]
93pub struct AuthToken {
94 Status: String,
95 IdentityToken: String,
96}
97
98impl AuthToken {
99 #[allow(dead_code)]
100 pub fn token(&self) -> String {
101 self.IdentityToken.clone()
102 }
103}