Skip to content

Commit

Permalink
Examples with tokio and async_std
Browse files Browse the repository at this point in the history
  • Loading branch information
svartalf committed May 24, 2020
1 parent bb93298 commit 88a589a
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 25 deletions.
17 changes: 14 additions & 3 deletions examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ autoexamples = false
autobins = false

[dev-dependencies]
cfg-if = "~0.1"
heim = { path = "../heim", features = ["full"] }
smol = "~0.1"
smol-potat = "~0.2"
futures = "~0.3"
futures-timer = "~3.0"
cfg-if = "~0.1"

futures = "~0.3"
smol = "~0.1"
tokio = { version = "~0.2", features = ["full"] }
async-std = { version = "~1.6", features = ["attributes"] }

ptree = { version = "0.2.1", default-features = false, features = ["ansi"] }
prettytable-rs = "0.8.0"
Expand Down Expand Up @@ -50,3 +53,11 @@ path = "wait.rs"
[[example]]
name = "uptime"
path = "uptime.rs"

[[example]]
name = "tokio"
path = "tokio.rs"

[[example]]
name = "async_std"
path = "async_std.rs"
17 changes: 17 additions & 0 deletions examples/async_std.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//! Tiny example of using `heim` with `async_std` runtime.

#[async_std::main]
async fn main() -> heim::Result<()> {
let platform = heim::host::platform().await?;

println!(
"{} {} {} {} {}",
platform.system(),
platform.release(),
platform.hostname(),
platform.version(),
platform.architecture().as_str(),
);

Ok(())
}
17 changes: 17 additions & 0 deletions examples/tokio.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//! Tiny example of using `heim` with `tokio` runtime.

#[tokio::main]
async fn main() -> heim::Result<()> {
let platform = heim::host::platform().await?;

println!(
"{} {} {} {} {}",
platform.system(),
platform.release(),
platform.hostname(),
platform.version(),
platform.architecture().as_str(),
);

Ok(())
}
28 changes: 6 additions & 22 deletions heim/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,34 +26,18 @@
//! ## Feature flags
//!
//! Heim uses a set of [feature flags](https://doc.rust-lang.org/cargo/reference/manifest.html#the-features-section)
//! to reduce the amount of compiled code. In general, these feature flags can be split
//! into two groups:
//! to reduce the amount of compiled code by selecting only the system components
//! you are planning to use.\
//! All these features are *disabled* by default, see modules list below for available features.
//!
//! 1. System components: each one of these enables functionality for fetching information
//! about some specific system part (ex. CPU or memory information).\
//! All these features are *disabled* by default.
//! See modules list below for available features.
//!
//! Alternatively you can use `full` feature to enable all components at once.
//!
//! 2. Async runtimes support. Heim can integrate with popular async runtimes
//! and also provides a fallback implementation for other use cases.
//!
//! * `runtime-tokio`: Enables integration with [`tokio`](https://tokio.rs)
//! * `runtime-async-std`: Enables integration with [`async-std`](https://async.rs)
//! * `runtime-polyfill`: Enables bundled polyfill implementation for async routines,
//! with all potentially blocking operations executed on the current thread.
//! Other runtime integrations should be used preferably.
//!
//! None of these runtime features are enabled by default and you are required to
//! explicitly opt-in to use one of them.
//! Enabling multiple runtimes at once is also forbidden and will lead to the compilation error.
//! Alternatively you can use `full` feature to enable all components at once.
//!
//! ## Documentation
//!
//! Note that `heim` also provides platform-specific APIs.
//! If you are browsing this documentation via [docs.rs](https://docs.rs/heim),
//! do not forget to use the platform selector at the page header.
//! do not forget to use the platform selector at the page header.\
//! For a local copy, use `--target` argument to choose your platform.
//!
//! Also, due to Rust [bug #15823](https://github.com/rust-lang/rust/issues/15823),
//! type aliases are not rendered properly across the sub-crates bounds,
Expand Down

0 comments on commit 88a589a

Please sign in to comment.