Skip to content

Commit

Permalink
0.6.2: add support for optional serde feature
Browse files Browse the repository at this point in the history
  • Loading branch information
ilya-zlobintsev committed Nov 13, 2022
1 parent f6cc540 commit 09642d9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pciid-parser"
version = "0.6.1"
version = "0.6.2"
authors = ["Ilya Zlobintsev <[email protected]>"]
edition = "2021"
license = "MIT"
Expand All @@ -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]
Expand Down
6 changes: 4 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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";
Expand All @@ -27,6 +28,7 @@ pub enum VendorDataError {
}

#[derive(Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Database {
pub vendors: HashMap<String, Vendor>,
pub classes: HashMap<String, Class>,
Expand Down
8 changes: 8 additions & 0 deletions src/schema.rs
Original file line number Diff line number Diff line change
@@ -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>,
Expand All @@ -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<String, Device>,
}

#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Device {
pub name: String,
pub subdevices: HashMap<SubDeviceId, String>,
}

#[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<String, SubClass>,
}

#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct SubClass {
pub name: String,
pub prog_ifs: HashMap<String, String>,
Expand Down

0 comments on commit 09642d9

Please sign in to comment.