Skip to content

Commit

Permalink
Fix docs.rs build, added skeptic
Browse files Browse the repository at this point in the history
  • Loading branch information
ohadravid committed Jun 5, 2019
1 parent 40ac0ef commit 80201ac
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 35 deletions.
11 changes: 9 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[package]
name = "wmi"
version = "0.4.2"
version = "0.4.3"
authors = ["Ohad Ravid <[email protected]>"]
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 = """
Expand All @@ -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"]

Expand All @@ -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"
Expand Down
59 changes: 31 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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<HashMap<String, Variant>> = 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<Win32_OperatingSystem> = wmi_con.query().unwrap();

for os in results {
println!("{:#?}", os);
fn main() -> Result<(), Box<dyn std::error::Error>> {
let com_con = COMLibrary::new()?;
let wmi_con = WMIConnection::new(com_con.into())?;

let results: Vec<HashMap<String, Variant>> = 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<Win32_OperatingSystem> = wmi_con.query()?;

for os in results {
println!("{:#?}", os);
}

Ok(())
}
```

Expand Down
4 changes: 4 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fn main() {
// generates doc tests for `README.md`.
little_skeptic::generate_doc_tests(&["README.md"]);
}
8 changes: 6 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -59,15 +60,17 @@
//! last_boot_up_time: WMIDateTime,
//! }
//!
//! let results: Vec<OperatingSystem> = wmi_con.query().unwrap();
//! let results: Vec<OperatingSystem> = 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-
Expand All @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,6 @@ mod tests {
.unwrap();

for res in enumerator {
dbg!(&res);
assert!(res.is_err())
}
}
Expand Down Expand Up @@ -772,7 +771,6 @@ mod tests {
.get_by_path::<Win32_OperatingSystem>(r#"\\.\root\cimv2:Win32_OperatingSystem=@"#)
.unwrap();

dbg!(&os);
assert!(os.Caption.contains("Microsoft Windows"));
}

Expand Down
1 change: 0 additions & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}

Expand Down
1 change: 1 addition & 0 deletions tests/skeptic.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include!(concat!(env!("OUT_DIR"), "/skeptic-tests.rs"));

0 comments on commit 80201ac

Please sign in to comment.