From ad02d027352829c721198fc234505f390de24ded Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 16 Jan 2025 18:02:51 +0100 Subject: [PATCH] Implement `Deserialize` on `DiskKind`, `MacAddr`, `IpNetwork`, `Signal`, `ProcessStatus` and `ThreadKind` --- Cargo.toml | 2 +- src/common/disk.rs | 1 + src/common/network.rs | 2 ++ src/common/system.rs | 3 +++ 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index c0942922d..0ca8da4cf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -94,7 +94,7 @@ rustdoc-args = ["--generate-link-to-definition"] [dependencies] memchr = { version = "2.5", optional = true } rayon = { version = "^1.8", optional = true } -serde = { version = "^1.0.190", optional = true } +serde = { version = "^1.0.190", optional = true, features = ["derive"] } [target.'cfg(windows)'.dependencies] ntapi = { version = "0.4", optional = true } diff --git a/src/common/disk.rs b/src/common/disk.rs index fee3dbaea..833c25df5 100644 --- a/src/common/disk.rs +++ b/src/common/disk.rs @@ -372,6 +372,7 @@ impl std::ops::DerefMut for Disks { /// } /// ``` #[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "serde", derive(serde::Deserialize))] pub enum DiskKind { /// HDD type. HDD, diff --git a/src/common/network.rs b/src/common/network.rs index 9d62196e6..b350c7f32 100644 --- a/src/common/network.rs +++ b/src/common/network.rs @@ -412,6 +412,7 @@ impl NetworkData { /// /// It is returned by [`NetworkData::mac_address`][crate::NetworkData::mac_address]. #[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "serde", derive(serde::Deserialize))] pub struct MacAddr(pub [u8; 6]); impl MacAddr { @@ -483,6 +484,7 @@ impl FromStr for MacAddr { /// /// It is returned by [`NetworkData::ip_networks`][crate::NetworkData::ip_networks]. #[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "serde", derive(serde::Deserialize))] pub struct IpNetwork { /// The IP of the network interface. pub addr: IpAddr, diff --git a/src/common/system.rs b/src/common/system.rs index f09095b9e..283660524 100644 --- a/src/common/system.rs +++ b/src/common/system.rs @@ -861,6 +861,7 @@ pub struct LoadAvg { /// If you want the list of the supported signals on the current system, use /// [`SUPPORTED_SIGNALS`][crate::SUPPORTED_SIGNALS]. #[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "serde", derive(serde::Deserialize))] pub enum Signal { /// Hangup detected on controlling terminal or death of controlling process. Hangup, @@ -985,6 +986,7 @@ pub struct CGroupLimits { /// Enum describing the different status of a process. #[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "serde", derive(serde::Deserialize))] pub enum ProcessStatus { /// ## Linux /// @@ -1102,6 +1104,7 @@ pub enum ProcessStatus { /// Enum describing the different kind of threads. #[derive(Clone, Copy, Debug, PartialEq, Eq)] +#[cfg_attr(feature = "serde", derive(serde::Deserialize))] pub enum ThreadKind { /// Kernel thread. Kernel,