From f9e5e334df429d2d865e01cc6106a9828251bd14 Mon Sep 17 00:00:00 2001 From: Brandon Armstrong <45339160+KittyTechnoProgrammer@users.noreply.github.com> Date: Thu, 24 Dec 2020 20:02:26 +0000 Subject: [PATCH 1/5] Update lib.rs Added Deserialize and Serialize for json --- lib.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib.rs b/lib.rs index 76bacd5..0380168 100644 --- a/lib.rs +++ b/lib.rs @@ -6,6 +6,12 @@ //! extern crate libc; +extern crate serde; + +use serde::ser::{Serialize, Serializer, SerializeStruct}; +use serde::de::{Deserialize}; + + use std::ffi; use std::fmt; @@ -39,7 +45,7 @@ static OS_KERN_BOOTTIME: libc::c_int = 21; /// System load average value. #[repr(C)] -#[derive(Debug)] +#[derive(Debug, serde::Deserialize, serde::Serialize)] pub struct LoadAvg { /// Average load within one minite. pub one: f64, @@ -51,7 +57,7 @@ pub struct LoadAvg { /// System memory information. #[repr(C)] -#[derive(Debug)] +#[derive(Debug, serde::Deserialize, serde::Serialize)] pub struct MemInfo { /// Total physical memory. pub total: u64, @@ -66,9 +72,11 @@ pub struct MemInfo { pub swap_free: u64, } +// // implement Serialize for MemInfo + /// The os release info of Linux #[derive(Debug)] -#[derive(Default)] +#[derive(Default, serde::Deserialize, serde::Serialize)] pub struct LinuxOSReleaseInfo { pub id: Option, pub id_like: Option, @@ -94,7 +102,7 @@ pub struct LinuxOSReleaseInfo { /// Disk information. #[repr(C)] -#[derive(Debug)] +#[derive(serde::Deserialize, serde::Serialize)] pub struct DiskInfo { pub total: u64, pub free: u64, From 416c10806d20badc38dade998afcf42261b79457 Mon Sep 17 00:00:00 2001 From: Brandon Armstrong <45339160+KittyTechnoProgrammer@users.noreply.github.com> Date: Thu, 24 Dec 2020 20:03:54 +0000 Subject: [PATCH 2/5] Update Cargo.toml added serde dependeny --- Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Cargo.toml b/Cargo.toml index 8494d59..2272d1b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,3 +26,4 @@ cc = "1" [dependencies] libc = "0.2.29" +serde = "1.0.118" From fa64f902b71bcfcdf94eb87a7092b28aa984daad Mon Sep 17 00:00:00 2001 From: Brandon Armstrong <45339160+KittyTechnoProgrammer@users.noreply.github.com> Date: Thu, 24 Dec 2020 21:05:44 +0000 Subject: [PATCH 3/5] Update lib.rs --- lib.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lib.rs b/lib.rs index 0380168..ca6eac7 100644 --- a/lib.rs +++ b/lib.rs @@ -8,8 +8,7 @@ extern crate libc; extern crate serde; -use serde::ser::{Serialize, Serializer, SerializeStruct}; -use serde::de::{Deserialize}; +use serde::{Deserialize, Serialize}; @@ -45,7 +44,7 @@ static OS_KERN_BOOTTIME: libc::c_int = 21; /// System load average value. #[repr(C)] -#[derive(Debug, serde::Deserialize, serde::Serialize)] +#[derive(Debug, Serialize)] pub struct LoadAvg { /// Average load within one minite. pub one: f64, @@ -57,7 +56,7 @@ pub struct LoadAvg { /// System memory information. #[repr(C)] -#[derive(Debug, serde::Deserialize, serde::Serialize)] +#[derive(Debug, Deserialize, Serialize)] pub struct MemInfo { /// Total physical memory. pub total: u64, @@ -76,7 +75,7 @@ pub struct MemInfo { /// The os release info of Linux #[derive(Debug)] -#[derive(Default, serde::Deserialize, serde::Serialize)] +#[derive(Default, Deserialize, Serialize)] pub struct LinuxOSReleaseInfo { pub id: Option, pub id_like: Option, @@ -102,7 +101,7 @@ pub struct LinuxOSReleaseInfo { /// Disk information. #[repr(C)] -#[derive(serde::Deserialize, serde::Serialize)] +#[derive( Deserialize, Serialize)] pub struct DiskInfo { pub total: u64, pub free: u64, From 25beb1a273581f54e5a335ffb59e9716edcd79f6 Mon Sep 17 00:00:00 2001 From: Brandon Armstrong <45339160+KittyTechnoProgrammer@users.noreply.github.com> Date: Thu, 24 Dec 2020 21:06:39 +0000 Subject: [PATCH 4/5] Update Cargo.toml --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 2272d1b..2e29527 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,4 +26,4 @@ cc = "1" [dependencies] libc = "0.2.29" -serde = "1.0.118" +serde = {version = "1.0.118", features = ["derive"]} From afa6baa8ada0e65399795184aaf9cbe8d6a114b0 Mon Sep 17 00:00:00 2001 From: Brandon Armstrong <45339160+KittyTechnoProgrammer@users.noreply.github.com> Date: Thu, 24 Dec 2020 21:26:22 +0000 Subject: [PATCH 5/5] Update lib.rs --- lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib.rs b/lib.rs index ca6eac7..70f2c64 100644 --- a/lib.rs +++ b/lib.rs @@ -101,7 +101,7 @@ pub struct LinuxOSReleaseInfo { /// Disk information. #[repr(C)] -#[derive( Deserialize, Serialize)] +#[derive(Debug, Deserialize, Serialize)] pub struct DiskInfo { pub total: u64, pub free: u64,