Closed Techno-Fox closed 3 years ago
I'm gonna need some help with this.
Here's how the lib.rs is looking like
//! This library provides a way to access system information such as CPU load, mounted filesystems,
//! network interfaces, etc.
#[cfg(windows)]
extern crate winapi;
extern crate libc;
extern crate time;
extern crate chrono;
extern crate bytesize;
#[cfg_attr(any(target_os = "freebsd", target_os = "openbsd", target_os = "macos"), macro_use)]
extern crate lazy_static;
#[cfg(any(target_os = "linux", target_os = "android"))]
extern crate nom;
#[cfg(feature = "serde")]
extern crate real_serde as serde;
pub mod platform;
pub mod data;
pub use self::platform::Platform;
pub use self::platform::PlatformImpl as System;
pub use self::data::*;
Cargo.toml :
[package]
name = "systemstat"
version = "0.1.7"
authors = [ "Greg V <greg@unrelenting.technology>" ]
keywords = [ "System", "Info" ]
description = "systemstat"
license = "Unlicense"
readme = "README.md"
homepage = "https://github.com/myfreeweb/systemstat"
repository = "https://github.com/myfreeweb/systemstat"
[dependencies]
time = "0.1"
chrono = "0.4"
lazy_static = "1.0"
bytesize = "1.0"
libc = "0.2"
real_serde = { version = "1.0", package = "serde", features = ["derive"], optional = true }
[target.'cfg(any(target_os = "linux", target_os = "android"))'.dependencies]
nom = "6.0"
[target.'cfg(windows)'.dependencies.winapi]
version = "0.3"
features = ["fileapi", "sysinfoapi", "minwindef", "winbase", "winerror", "ws2def", "ws2ipdef", "pdh"]
[package.metadata.docs.rs]
targets = [
"x86_64-unknown-freebsd",
"x86_64-unknown-openbsd",
"x86_64-unknown-linux-gnu",
"x86_64-apple-darwin",
"x86_64-pc-windows-msvc"
]
[features]
serde = ["real_serde", "bytesize/serde", "chrono/serde"]
I added #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] to the data types.
Now I'm getting a compilation error
^^^^^^^^^^^ can't find crate
Hm, maybe https://crates.io/crates/serde-feature-hack actually is necessary.
Same error happens (Sorry it took so long to comment back)
extern crate serde_feature_hack as serde;
[package]
name = "systemstat"
version = "0.1.7"
authors = [ "Greg V <greg@unrelenting.technology>" ]
keywords = [ "System", "Info" ]
description = "systemstat"
license = "Unlicense"
readme = "README.md"
homepage = "https://github.com/myfreeweb/systemstat"
repository = "https://github.com/myfreeweb/systemstat"
[dependencies]
time = "0.1"
chrono = "0.4"
lazy_static = "1.0"
bytesize = "1.0"
libc = "0.2"
serde-feature-hack = { version = "0.1.0", optional = true }
[target.'cfg(any(target_os = "linux", target_os = "android"))'.dependencies]
nom = "6.0"
[target.'cfg(windows)'.dependencies.winapi]
version = "0.3"
features = ["fileapi", "sysinfoapi", "minwindef", "winbase", "winerror", "ws2def", "ws2ipdef", "pdh"]
[package.metadata.docs.rs]
targets = [
"x86_64-unknown-freebsd",
"x86_64-unknown-openbsd",
"x86_64-unknown-linux-gnu",
"x86_64-apple-darwin",
"x86_64-pc-windows-msvc"
]
[features]
serde = ["serde-feature-hack", "bytesize/serde", "chrono/serde"]
Looks like the documentation there is outdated, you need version 0.2
, and then it would be just extern crate serde
(no as
!) and macros work fine.
it works. I'll commit changes
Thanks!
New to Rust, trying to get the gated serde serializes to work, so I can serialize the platform objects but they don't. Here is what my cargo.toml looks like.
` [package] name = "events" version = "0.1.0" edition = "2021"
[dependencies] systemstat = "0.2.2" rusqlite = { version = "0.28.0", features = ["vtab", "csvtab", "modern_sqlite", "bundled"] } json = "0.12.4" log = "0.4.17" env_logger = "0.9.3" nanoid = "0.4.0" serde = { version = "1.0.148", features = ["derive"], optional = true } serde_json = "1.0.64" regex = "1.7.0"
[features] default = ["serde"] `
Error:
the trait bound
Network: Serializeis not satisfied the following other types implement trait
Serialize:
@willhughes11 you haven't enabled the serde feature in systemstat, it should be
default = ["serde", "systemstat/serde"]
serde is the most popular crate for serializing and de-serializing structs, enums, etc. I added them to the public facing data types so users can serialize and de-serialize the data returned from this crate.