add MMDS version type struct
// SPDX-License-Identifier: Apache-2.0
use crate::MAX_DATA_STORE_SIZE;
+use serde::Deserialize;
use serde_json::{to_vec, Value};
use std::fmt;
use std::fmt::{Display, Formatter};
@@ -16,12 +17,18 @@ pub struct Mmds {
}
/// MMDS version.
-#[derive(Clone, Copy)]
+#[derive(Clone, Copy, Deserialize)]
pub enum MmdsVersion {
V1,
V2,
}
+impl Default for MmdsVersion {
+ fn default() -> Self {
+ MmdsVersion::V1
+ }
+}
+
impl Display for MmdsVersion {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
match self {
@@ -37,6 +44,28 @@ pub enum OutputFormat {
Imds,
}
+/// Keeps the MMDS version configuration.
+#[derive(Default, Deserialize)]
+#[serde(deny_unknown_fields)]
+pub struct MmdsVersionType {
+ /// MMDS configured version
+ #[serde(default)]
+ pub version: MmdsVersion,
+}
+
+impl MmdsVersionType {
+ /// Returns the IMDS version.
+ pub fn version(&self) -> MmdsVersion {
+ self.version
+ }
+}
+
+impl From<MmdsVersion> for MmdsVersionType {
+ fn from(version: MmdsVersion) -> Self {
+ MmdsVersionType { version }
+ }
+}
+
#[derive(Debug, PartialEq)]
pub enum Error {
DataStoreLimitExceeded,
@@ -65,7 +94,7 @@ impl Default for Mmds {
data_store: Value::default(),
is_initialized: false,
data_store_limit: MAX_DATA_STORE_SIZE,
- version: MmdsVersion::V1,
+ version: MmdsVersion::default(),
}
}
}
