diff --git a/Cargo.toml b/Cargo.toml index 32d8aef..c7b4e62 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,11 +1,11 @@ [package] name = "wmi" -version = "0.4.2" +version = "0.4.3" authors = ["Ohad Ravid "] edition = "2018" license = "MIT OR Apache-2.0" readme = "README.md" -documentation = "https://ohadravid.github.io/wmi-rs/docs/wmi/" +documentation = "https://docs.rs/crate/wmi" homepage = "https://github.com/ohadravid/wmi-rs" repository = "https://github.com/ohadravid/wmi-rs" description = """ @@ -14,6 +14,9 @@ WMI crate for rust. categories = ["api-bindings", "os::windows-apis"] keywords = ["wmi", "com", "win32"] +[package.metadata.docs.rs] +default-target = "x86_64-pc-windows-msvc" + [features] test = ["lazy_static"] @@ -26,10 +29,14 @@ serde = { version = "1.0", features = ["derive"] } chrono = { version = "0.4", features = ["serde"] } lazy_static = { version = "1.2.0", optional = true } +[build-dependencies] +little-skeptic = "0.15" + [dev-dependencies] lazy_static = "1.2.0" serde_json = { version = "1.0" } criterion = "0.2" +little-skeptic = "0.15" [[bin]] name = "wmiq" diff --git a/README.md b/README.md index e5f4c04..deff129 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![Build Status](https://dev.azure.com/ohadrv/wmi-rs/_apis/build/status/ohadravid.wmi-rs?branchName=master)](https://dev.azure.com/ohadrv/wmi-rs/_build/latest?definitionId=1&branchName=master) ![crates.io](https://img.shields.io/crates/v/wmi.svg) -[Documentation](https://ohadravid.github.io/wmi-rs/docs/wmi/) +[Documentation](https://docs.rs/crate/wmi) WMI crate for rust. Currently in beta. @@ -19,35 +19,38 @@ wmi = "0.4" Queries can be deserialized info a free-form `HashMap` or a `struct`: ```rust -use std::collections::HashMap; use serde::Deserialize; +use wmi::{COMLibrary, Variant, WMIConnection, WMIDateTime}; +use std::collections::HashMap; -use wmi::{from_wbem_class_obj, COMLibrary, Variant, WMIConnection, WMIDateTime}; - -let com_con = COMLibrary::new().unwrap(); -let wmi_con = WMIConnection::new(com_con.into()).unwrap(); - -let results: Vec> = wmi_con.raw_query("SELECT * FROM Win32_OperatingSystem").unwrap(); - -for os in results { - println!("{:#?}", os); -} - -#[derive(Deserialize, Debug)] -struct Win32_OperatingSystem { - Caption: String, - Name: String, - CurrentTimeZone: i16, - Debug: bool, - EncryptionLevel: u32, - ForegroundApplicationBoost: u8, - LastBootUpTime: WMIDateTime, -} - -let results: Vec = wmi_con.query().unwrap(); - -for os in results { - println!("{:#?}", os); +fn main() -> Result<(), Box> { + let com_con = COMLibrary::new()?; + let wmi_con = WMIConnection::new(com_con.into())?; + + let results: Vec> = wmi_con.raw_query("SELECT * FROM Win32_OperatingSystem")?; + + for os in results { + println!("{:#?}", os); + } + + #[derive(Deserialize, Debug)] + struct Win32_OperatingSystem { + Caption: String, + Name: String, + CurrentTimeZone: i16, + Debug: bool, + EncryptionLevel: u32, + ForegroundApplicationBoost: u8, + LastBootUpTime: WMIDateTime, + } + + let results: Vec = wmi_con.query()?; + + for os in results { + println!("{:#?}", os); + } + + Ok(()) } ``` diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..9605982 --- /dev/null +++ b/build.rs @@ -0,0 +1,4 @@ +fn main() { + // generates doc tests for `README.md`. + little_skeptic::generate_doc_tests(&["README.md"]); +} diff --git a/src/lib.rs b/src/lib.rs index 081dcff..0367c44 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -45,6 +45,7 @@ //! Using `serde`, it is possible to return a struct representing the the data. //! //! ```edition2018 +//! # fn main() -> Result<(), failure::Error> { //! # use wmi::*; //! # let wmi_con = WMIConnection::new(COMLibrary::new().unwrap().into()).unwrap(); //! use serde::Deserialize; @@ -59,15 +60,17 @@ //! last_boot_up_time: WMIDateTime, //! } //! -//! let results: Vec = wmi_con.query().unwrap(); +//! let results: Vec = wmi_con.query()?; //! //! for os in results { //! println!("{:#?}", os); //! } +//! # Ok(()) +//! # } //! ``` //! //! Because the name of the struct given to `serde` matches the [WMI class] name, the SQL query -//! is inferred. +//! can be inferred. //! //! [WMI]: https://docs.microsoft.com/en-us/windows/desktop/wmisdk/about-wmi //! [Creating a WMI Application Using C++]: https://docs.microsoft.com/en-us/windows/desktop/wmisdk/creating-a-wmi-application-using-c- @@ -94,6 +97,7 @@ //! Most native objects has an equivalent wrapper struct which implements `Drop` for that data. //! //! +#![cfg(windows)] #![feature(ptr_internals, custom_attribute)] pub mod connection; diff --git a/src/query.rs b/src/query.rs index e8ccc1e..8c7d48c 100644 --- a/src/query.rs +++ b/src/query.rs @@ -484,7 +484,6 @@ mod tests { .unwrap(); for res in enumerator { - dbg!(&res); assert!(res.is_err()) } } @@ -772,7 +771,6 @@ mod tests { .get_by_path::(r#"\\.\root\cimv2:Win32_OperatingSystem=@"#) .unwrap(); - dbg!(&os); assert!(os.Caption.contains("Microsoft Windows")); } diff --git a/src/utils.rs b/src/utils.rs index 47fd81f..79b09cf 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -9,7 +9,6 @@ pub enum WMIError { pub fn check_hres(hres: HRESULT) -> Result<(), WMIError> { if hres < 0 { - dbg!(hres); return Err(WMIError::HResultError { hres }); } diff --git a/tests/skeptic.rs b/tests/skeptic.rs new file mode 100644 index 0000000..ff46c9c --- /dev/null +++ b/tests/skeptic.rs @@ -0,0 +1 @@ +include!(concat!(env!("OUT_DIR"), "/skeptic-tests.rs"));