heim_disk/
partitions.rs

1use std::ffi::OsStr;
2use std::fmt;
3use std::path::Path;
4
5use heim_common::prelude::*;
6
7use crate::{sys, FileSystem};
8
9/// Mounted disk partition.
10///
11/// ## Compatibility
12///
13/// See [os]-specific extension traits also.
14///
15/// [os]: ./os/index.html
16pub struct Partition(sys::Partition);
17
18wrap!(Partition, sys::Partition);
19
20impl Partition {
21    /// Returns partition device name if available.
22    pub fn device(&self) -> Option<&OsStr> {
23        self.as_ref().device()
24    }
25
26    /// Returns partition mount point path.
27    pub fn mount_point(&self) -> &Path {
28        self.as_ref().mount_point()
29    }
30
31    /// Returns partition file system.
32    pub fn file_system(&self) -> &FileSystem {
33        self.as_ref().file_system()
34    }
35}
36
37impl fmt::Debug for Partition {
38    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
39        f.debug_struct("Partition")
40            .field("device", &self.device())
41            .field("mount_point", &self.mount_point())
42            .field("file_system", &self.file_system())
43            .finish()
44    }
45}
46
47/// Returns stream which yields mounted disk [Partitions].
48///
49/// This includes all virtual partitions, such as `tmpfs`.
50/// See [partitions_physical] for physical partitions stream.
51///
52/// [Partitions]: struct.Partition.html
53pub fn partitions() -> impl Stream<Item = Result<Partition>> {
54    sys::partitions().map_ok(Into::into)
55}
56
57/// Returns stream which yields physical only mounted disk [Partitions].
58///
59/// [Partitions]: struct.Partition.html
60pub fn partitions_physical() -> impl Stream<Item = Result<Partition>> {
61    sys::partitions_physical().map_ok(Into::into)
62}