Skip to content

Commit

Permalink
serde
Browse files Browse the repository at this point in the history
  • Loading branch information
Jasper-Bekkers committed Jul 9, 2024
1 parent 03466c4 commit 4ec1d33
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 20 deletions.
21 changes: 21 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 2 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,14 @@ name = "cpuinfo-rs"
version = "0.1.0"
authors = ["Traverse Research <support@traverseresearch.nl>"]
edition = "2021"
license = "MIT"
homepage = "https://traverseresearch.nl"
repository = "https://github.com/Traverse-Research/cpuinfo-rs"
description = "A useful description"
include = ["src", "LICENSE"]
categories = [] # https://crates.io/category_slugs
keywords = []

[features]
generate_bindings = ["dep:bindgen"]

[dependencies]
bytemuck = "1"
serde = { version = "1", features = ["derive", "rc"] }

[build-dependencies]
bindgen = { version = "0.69", optional = true }
cc = "1.0.83"
27 changes: 14 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
mod bindings;
use bindings::*;

use std::borrow::Cow;
use std::sync::{Arc, Once};

static INITIALIZED: Once = Once::new();
Expand All @@ -21,7 +22,7 @@ impl CpuInfo {
fn uarch(uarch: cpuinfo_uarch) -> Uarch {
Uarch {
uarch,
name: uarch_to_string(uarch),
name: uarch_to_string(uarch).into(),
}
}

Expand Down Expand Up @@ -84,7 +85,7 @@ impl CpuInfo {
fn vendor(vendor: cpuinfo_vendor) -> Vendor {
Vendor {
vendor,
name: vendor_to_string(vendor),
name: vendor_to_string(vendor).into(),
}
}

Expand Down Expand Up @@ -181,7 +182,7 @@ impl CpuInfo {
}

#[repr(C)]
#[derive(Debug, Clone)]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct Cache {
#[doc = " Cache size in bytes"]
pub size: u32,
Expand All @@ -201,7 +202,7 @@ pub struct Cache {
pub processor_count: u32,
}

#[derive(Debug, Clone)]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct Processor {
#[doc = " SMT (hyperthread) ID within a core"]
pub smt_id: u32,
Expand All @@ -221,7 +222,7 @@ pub struct Processor {
}

#[repr(C)]
#[derive(Debug, Clone)]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct CacheInfo {
#[doc = " Level 1 instruction cache"]
pub l1i: Option<Cache>,
Expand All @@ -235,13 +236,13 @@ pub struct CacheInfo {
pub l4: Option<Cache>,
}

#[derive(Debug, Clone)]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct Vendor {
pub vendor: cpuinfo_vendor,
pub name: &'static str,
pub name: Cow<'static, str>,
}

#[derive(Debug, Clone)]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct Core {
#[doc = " Index of the first logical processor on this core."]
pub processor_start: u32,
Expand All @@ -263,7 +264,7 @@ pub struct Core {
pub frequency: u64,
}

#[derive(Debug, Clone)]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct Cluster {
#[doc = " Index of the first logical processor in the cluster"]
pub processor_start: u32,
Expand All @@ -287,7 +288,7 @@ pub struct Cluster {
pub frequency: u64,
}

#[derive(Debug, Clone)]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct Package {
#[doc = " SoC or processor chip model name"]
pub name: String,
Expand All @@ -305,16 +306,16 @@ pub struct Package {
pub cluster_count: u32,
}

#[derive(Debug, Clone)]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct Uarch {
#[doc = " Type of CPU microarchitecture"]
pub uarch: cpuinfo_uarch,

#[doc = " Type of CPU microarchitecture as text"]
pub name: &'static str,
pub name: Cow<'static, str>,
}

#[derive(Debug, Clone)]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct UarchInfo {
#[doc = " Type of CPU microarchitecture"]
pub uarch: Uarch,
Expand Down

0 comments on commit 4ec1d33

Please sign in to comment.