1use std::fmt;
2use std::path::Path;
3
4use heim_common::prelude::*;
5use heim_common::units::{Information, Ratio};
6
7use crate::sys;
8
9pub struct Usage(sys::Usage);
17
18wrap!(Usage, sys::Usage);
19
20impl Usage {
21 pub fn total(&self) -> Information {
23 self.as_ref().total()
24 }
25
26 pub fn used(&self) -> Information {
28 self.as_ref().used()
29 }
30
31 pub fn free(&self) -> Information {
33 self.as_ref().free()
34 }
35
36 pub fn ratio(&self) -> Ratio {
38 self.as_ref().ratio()
39 }
40}
41
42impl fmt::Debug for Usage {
43 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
44 f.debug_struct("Usage")
45 .field("total", &self.total())
46 .field("used", &self.used())
47 .field("free", &self.free())
48 .field("ratio", &self.ratio())
49 .finish()
50 }
51}
52
53pub fn usage<T>(path: T) -> impl Future<Output = Result<Usage>>
57where
58 T: AsRef<Path>,
59{
60 sys::usage(path).map(|res| res.map(Into::into))
61}