1use std::fmt;
2
3use heim_common::prelude::*;
4use heim_common::units::Information;
5
6use crate::sys;
7
8pub struct Memory(sys::Memory);
15
16wrap!(Memory, sys::Memory);
17
18impl Memory {
19 pub fn total(&self) -> Information {
21 self.as_ref().total()
22 }
23
24 pub fn available(&self) -> Information {
27 self.as_ref().available()
28 }
29
30 pub fn free(&self) -> Information {
33 self.as_ref().free()
34 }
35}
36
37impl fmt::Debug for Memory {
38 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
39 f.debug_struct("Memory")
40 .field("total", &self.total())
41 .field("available", &self.available())
42 .field("free", &self.free())
43 .finish()
44 }
45}
46
47pub fn memory() -> impl future::Future<Output = Result<Memory>> {
51 sys::memory().map(|res| res.map(Into::into))
52}