diff --git a/Cargo.toml b/Cargo.toml index f5e2791..e1bac88 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pciid-parser" -version = "0.6.1" +version = "0.6.2" authors = ["Ilya Zlobintsev "] edition = "2021" license = "MIT" @@ -13,6 +13,7 @@ description = "A library for parsing PCI ID tables" [dependencies] ureq = { version = "2.4", optional = true } tracing = "0.1.34" +serde = { version = "1.0.147", features = ["derive"], optional = true } [features] diff --git a/src/lib.rs b/src/lib.rs index ed1a2e3..238b031 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,9 +4,12 @@ mod error; mod parser; pub mod schema; +use crate::parser::{parse_class, parse_prog_if, parse_subclass}; use error::Error; use parser::{drain_id_and_name, parse_subdevice_id}; use schema::{Class, Device, DeviceInfo, SubClass, SubDeviceId, Vendor}; +#[cfg(feature = "serde")] +use serde::{Deserialize, Serialize}; use std::{ collections::HashMap, fs::File, @@ -15,8 +18,6 @@ use std::{ }; use tracing::trace; -use crate::parser::{parse_class, parse_prog_if, parse_subclass}; - const DB_PATHS: &[&str] = &["/usr/share/hwdata/pci.ids", "/usr/share/misc/pci.ids"]; #[cfg(feature = "online")] const URL: &str = "https://pci-ids.ucw.cz/v2.2/pci.ids"; @@ -27,6 +28,7 @@ pub enum VendorDataError { } #[derive(Debug)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct Database { pub vendors: HashMap, pub classes: HashMap, diff --git a/src/schema.rs b/src/schema.rs index 1777801..23741a7 100644 --- a/src/schema.rs +++ b/src/schema.rs @@ -1,6 +1,9 @@ +#[cfg(feature = "serde")] +use serde::{Deserialize, Serialize}; use std::{collections::HashMap, hash::Hash}; #[derive(Default, Clone, Debug)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct DeviceInfo<'a> { pub vendor_name: Option<&'a str>, pub device_name: Option<&'a str>, @@ -9,30 +12,35 @@ pub struct DeviceInfo<'a> { } #[derive(Debug, PartialEq, Eq)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct Vendor { pub name: String, pub devices: HashMap, } #[derive(Debug, Clone, PartialEq, Eq)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct Device { pub name: String, pub subdevices: HashMap, } #[derive(Debug, Clone, PartialEq, Eq, Hash)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct SubDeviceId { pub subvendor: String, pub subdevice: String, } #[derive(Debug, Clone, PartialEq, Eq)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct Class { pub name: String, pub subclasses: HashMap, } #[derive(Debug, Clone, PartialEq, Eq)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct SubClass { pub name: String, pub prog_ifs: HashMap,