heim_memory/
swap.rs

1use std::fmt;
2
3use heim_common::prelude::*;
4use heim_common::units::Information;
5
6use crate::sys;
7
8/// Swap memory statistics.
9///
10/// Only three metrics are guaranteed to be cross-platform,
11/// for other metrics see [OS]-specific extensions.
12///
13/// [OS]: ./os/index.html
14pub struct Swap(sys::Swap);
15
16wrap!(Swap, sys::Swap);
17
18impl Swap {
19    /// The total amount of swap memory
20    pub fn total(&self) -> Information {
21        self.0.total()
22    }
23
24    /// The used amount of swap memory
25    pub fn used(&self) -> Information {
26        self.0.used()
27    }
28
29    /// The free amount of swap memory
30    pub fn free(&self) -> Information {
31        self.0.free()
32    }
33}
34
35impl fmt::Debug for Swap {
36    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
37        f.debug_struct("Swap")
38            .field("total", &self.total())
39            .field("used", &self.used())
40            .field("free", &self.free())
41            .finish()
42    }
43}
44
45/// Returns future which will resolve into [Swap] struct.
46///
47/// [Swap]: ./struct.Swap.html
48pub fn swap() -> impl Future<Output = Result<Swap>> {
49    sys::swap().map(|res| res.map(Into::into))
50}