Skip to content

Commit

Permalink
Starting examples rewriting
Browse files Browse the repository at this point in the history
  • Loading branch information
svartalf committed Feb 25, 2020
1 parent 4a5359c commit 027356f
Show file tree
Hide file tree
Showing 25 changed files with 66 additions and 358 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Expand Up @@ -33,4 +33,5 @@ members = [

# Internal
"benchmarks",
"examples",
]
27 changes: 27 additions & 0 deletions examples/Cargo.toml
@@ -0,0 +1,27 @@
[package]
name = "examples"
version = "0.0.0"
authors = ["svartalf <self@svartalf.info>"]
edition = "2018"
publish = false

[dev-dependencies]
heim = { path = "../heim", features = ["full", "runtime-tokio"] }
tokio = { version = "~0.2", features = ["full", "macros"] }
futures-timer = "~3.0"

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

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

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

[[example]]
name = "top"
path = "top.rs"
18 changes: 9 additions & 9 deletions heim-disk/examples/disk_usage.rs → examples/disk_usage.rs
@@ -1,23 +1,23 @@
//! Command similar to `df -BM`
//! Unix `du -h` command implementation.

use std::ffi::OsStr;

use heim_common::prelude::*;
use heim_common::units::information;
use heim_disk as disk;
use heim::units::information;
use tokio::stream::StreamExt;

#[heim_derive::main]
async fn main() -> Result<()> {
#[tokio::main]
async fn main() -> heim::Result<()> {
println!(
"{:<17} {:<10} {:<10} {:<10} {:<10} Mount",
"Device", "Total, Mb", "Used, Mb", "Free, Mb", "Type"
);

let partitions = disk::partitions_physical();
pin_utils::pin_mut!(partitions);
let partitions = heim::disk::partitions_physical();
tokio::pin!(partitions);

while let Some(part) = partitions.next().await {
let part = part?;
let usage = disk::usage(part.mount_point().to_path_buf()).await?;
let usage = heim::disk::usage(part.mount_point().to_path_buf()).await?;

println!(
"{:<17} {:<10} {:<10} {:<10} {:<10} {}",
Expand Down
8 changes: 4 additions & 4 deletions heim-memory/examples/free.rs → examples/free.rs
@@ -1,8 +1,8 @@
use heim_common::prelude::*;
use heim_common::units::information;
use heim_memory as memory;
//! Naive clone of the `free` utility

#[heim_derive::main]
use heim::{memory, units::information, Result};

#[tokio::main]
async fn main() -> Result<()> {
let memory = memory::memory().await?;
let swap = memory::swap().await?;
Expand Down
10 changes: 6 additions & 4 deletions heim-process/examples/top.rs → examples/top.rs
@@ -1,9 +1,11 @@
use std::time::{Duration, Instant};
use std::usize;

use heim_common::prelude::{StreamExt, TryStreamExt};
use heim_common::units::{ratio, Ratio};
use heim_process::{self as process, Process, ProcessResult};
use futures::stream::{StreamExt, TryStreamExt};
use heim::{
process::{self, Process, ProcessResult},
units::{ratio, Ratio},
};

async fn usage(process: Process) -> ProcessResult<(process::Process, Ratio)> {
let usage_1 = process.cpu_usage().await?;
Expand All @@ -13,7 +15,7 @@ async fn usage(process: Process) -> ProcessResult<(process::Process, Ratio)> {
Ok((process, usage_2 - usage_1))
}

#[heim_derive::main]
#[tokio::main]
async fn main() -> ProcessResult<()> {
let start = Instant::now();

Expand Down
19 changes: 19 additions & 0 deletions examples/uname.rs
@@ -0,0 +1,19 @@
//! `uname -a` implementation

use heim::{host, Result};

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

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

Ok(())
}
10 changes: 0 additions & 10 deletions heim-cpu/examples/cpu_count.rs

This file was deleted.

24 changes: 0 additions & 24 deletions heim-cpu/examples/cpu_frequencies.rs

This file was deleted.

9 changes: 0 additions & 9 deletions heim-cpu/examples/cpu_stats.rs

This file was deleted.

15 changes: 0 additions & 15 deletions heim-cpu/examples/cpu_times.rs

This file was deleted.

21 changes: 0 additions & 21 deletions heim-disk/examples/io_counters.rs

This file was deleted.

22 changes: 0 additions & 22 deletions heim-disk/examples/partitions.rs

This file was deleted.

22 changes: 0 additions & 22 deletions heim-disk/examples/usage.rs

This file was deleted.

11 changes: 0 additions & 11 deletions heim-host/examples/boot_time.rs

This file was deleted.

11 changes: 0 additions & 11 deletions heim-host/examples/platform.rs

This file was deleted.

11 changes: 0 additions & 11 deletions heim-host/examples/uptime.rs

This file was deleted.

14 changes: 0 additions & 14 deletions heim-host/examples/users.rs

This file was deleted.

13 changes: 0 additions & 13 deletions heim-net/examples/counters.rs

This file was deleted.

13 changes: 0 additions & 13 deletions heim-net/examples/nic.rs

This file was deleted.

15 changes: 0 additions & 15 deletions heim-process/examples/pids.rs

This file was deleted.

46 changes: 0 additions & 46 deletions heim-process/examples/process_current.rs

This file was deleted.

0 comments on commit 027356f

Please sign in to comment.