Skip to content

Commit

Permalink
Add disk::Partition::usage method (closes #288)
Browse files Browse the repository at this point in the history
  • Loading branch information
svartalf committed Nov 7, 2020
1 parent 8240de5 commit 658cbde
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 17 deletions.
15 changes: 2 additions & 13 deletions .github/workflows/ci.yml
Expand Up @@ -12,7 +12,7 @@ jobs:
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: 1.45.0
toolchain: stable
override: true
components: rustfmt
- run: cargo fmt --all -- --check
Expand All @@ -36,7 +36,7 @@ jobs:
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: beta
toolchain: stable
override: true
components: clippy
- run: cargo clippy --all-targets --workspace -- -D warnings
Expand Down Expand Up @@ -77,17 +77,6 @@ jobs:
- uses: actions/checkout@v2

# Cache
- name: Cache rustup toolchain
uses: actions/cache@v1
with:
path: ~/.rustup/toolchains
key: rustup-toolchain-${{ matrix.toolchain }}
- name: Cache cargo build target
if: matrix.toolchain != 'nightly'
uses: actions/cache@v1
with:
path: target
key: compile-${{ runner.os }}-${{ matrix.toolchain }}-${{ matrix.triple.target }}-${{ hashFiles('**/Cargo.toml') }}

- name: Install toolchain
uses: actions-rs/toolchain@v1
Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG.md
Expand Up @@ -20,10 +20,11 @@ for information about previous releases.
* `process::Process::environment` method for Linux and macOS (#208, #209)
* `cpu::os::unix::loadavg` function for load average values fetching
* `net::Nic::is_running` method for checking network interface running state (#223)
* `disk::Partition::usage` method to fetch disk usage information (#288)

### Changed

* MSRV bumped to Rust 1.40.0+
* MSRV bumped to Rust 1.45.0+
* Examples moved to the separate workspace crate
* Benchmarks moved to the separate workspace crate
* `process::Process::cwd` for Windows panics instead of returning blank error, as this method is not implemented yet
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -41,7 +41,7 @@ Examples can be found [here](https://github.com/heim-rs/heim/tree/master/example

## Technical notes

`heim` requires Rust 1.40 or higher; this version is explicitly tested in CI
`heim` requires Rust 1.45 or higher; this version is explicitly tested in CI
and may be bumped in any major or minor release as needed.\
Any changes to the supported minimum version will be called out in the
[release notes](https://github.com/heim-rs/heim/blob/master/CHANGELOG.md).
Expand Down
2 changes: 1 addition & 1 deletion examples/disk_usage.rs
Expand Up @@ -18,7 +18,7 @@ fn main() -> Result<(), Box<dyn Error>> {

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

println!(
"{:<17} {:<10} {:<10} {:<10} {:<10} {}",
Expand Down
13 changes: 12 additions & 1 deletion heim-disk/src/partitions.rs
Expand Up @@ -4,7 +4,7 @@ use std::path::Path;

use heim_common::prelude::*;

use crate::{sys, FileSystem};
use crate::{sys, usage, FileSystem, Usage};

/// Mounted disk partition.
///
Expand Down Expand Up @@ -32,6 +32,17 @@ impl Partition {
pub fn file_system(&self) -> &FileSystem {
self.as_ref().file_system()
}

/// Returns disk [Usage] statistics about this particular partition.
///
/// Internally it is the same as calling [usage] with [`mount_point`] call as an argument,
/// but more convenient to use.
///
/// [Usage]: ./struct.Usage.html
/// [usage]: ./fn.usage.html
pub async fn usage(&self) -> Result<Usage> {
usage(self.mount_point()).await
}
}

impl fmt::Debug for Partition {
Expand Down

0 comments on commit 658cbde

Please sign in to comment.