diff --git a/Cargo.toml b/Cargo.toml index 8494d59..2e29527 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,3 +26,4 @@ cc = "1" [dependencies] libc = "0.2.29" +serde = {version = "1.0.118", features = ["derive"]} diff --git a/lib.rs b/lib.rs index 76bacd5..70f2c64 100644 --- a/lib.rs +++ b/lib.rs @@ -6,6 +6,11 @@ //! extern crate libc; +extern crate serde; + +use serde::{Deserialize, Serialize}; + + use std::ffi; use std::fmt; @@ -39,7 +44,7 @@ static OS_KERN_BOOTTIME: libc::c_int = 21; /// System load average value. #[repr(C)] -#[derive(Debug)] +#[derive(Debug, Serialize)] pub struct LoadAvg { /// Average load within one minite. pub one: f64, @@ -51,7 +56,7 @@ pub struct LoadAvg { /// System memory information. #[repr(C)] -#[derive(Debug)] +#[derive(Debug, Deserialize, Serialize)] pub struct MemInfo { /// Total physical memory. pub total: u64, @@ -66,9 +71,11 @@ pub struct MemInfo { pub swap_free: u64, } +// // implement Serialize for MemInfo + /// The os release info of Linux #[derive(Debug)] -#[derive(Default)] +#[derive(Default, Deserialize, Serialize)] pub struct LinuxOSReleaseInfo { pub id: Option, pub id_like: Option, @@ -94,7 +101,7 @@ pub struct LinuxOSReleaseInfo { /// Disk information. #[repr(C)] -#[derive(Debug)] +#[derive(Debug, Deserialize, Serialize)] pub struct DiskInfo { pub total: u64, pub free: u64,