From 15f06a6c5f4210d2462e9d0b28fe4e5212568ce9 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 7 Oct 2023 15:54:01 +0200 Subject: [PATCH] Remove DiskExt trait --- benches/basic.rs | 2 +- md_doc/disk.md | 1 - src/common.rs | 153 +++++++++++++++++++++++++++++++++++++-- src/debug.rs | 5 +- src/lib.rs | 14 ++-- src/serde.rs | 2 +- src/traits.rs | 120 +----------------------------- src/unix/apple/disk.rs | 41 ++++++----- src/unix/apple/mod.rs | 2 +- src/unix/freebsd/disk.rs | 41 ++++++----- src/unix/freebsd/mod.rs | 2 +- src/unix/linux/disk.rs | 40 +++++----- src/unix/linux/mod.rs | 2 +- src/unknown/disk.rs | 23 +++--- src/unknown/mod.rs | 3 +- src/windows/disk.rs | 41 ++++++----- src/windows/mod.rs | 3 +- 17 files changed, 257 insertions(+), 238 deletions(-) delete mode 100644 md_doc/disk.md diff --git a/benches/basic.rs b/benches/basic.rs index d1b4ba436..ef28e367f 100644 --- a/benches/basic.rs +++ b/benches/basic.rs @@ -3,7 +3,7 @@ extern crate test; use sysinfo::get_current_pid; -use sysinfo::{ComponentsExt, DiskExt, NetworksExt, SystemExt, UsersExt}; +use sysinfo::{ComponentsExt, NetworksExt, SystemExt, UsersExt}; #[bench] fn bench_new(b: &mut test::Bencher) { diff --git a/md_doc/disk.md b/md_doc/disk.md deleted file mode 100644 index f94b7c1b8..000000000 --- a/md_doc/disk.md +++ /dev/null @@ -1 +0,0 @@ -Struct containing a disk information. diff --git a/src/common.rs b/src/common.rs index a3a68b16c..62a89b892 100644 --- a/src/common.rs +++ b/src/common.rs @@ -1,14 +1,16 @@ // Take a look at the license at the top of the repository in the LICENSE file. use crate::{ - Component, Components, ComponentsExt, Disk, DiskExt, GroupExt, NetworkData, NetworksExt, User, - UserExt, UsersExt, + Component, Components, ComponentsExt, GroupExt, NetworkData, NetworksExt, User, UserExt, + UsersExt, }; use std::cmp::Ordering; use std::collections::HashMap; use std::convert::{From, TryFrom}; +use std::ffi::OsStr; use std::fmt; +use std::path::Path; use std::str::FromStr; /// Trait to have a common conversions for the [`Pid`][crate::Pid] type. @@ -473,6 +475,143 @@ impl<'a> Iterator for NetworksIter<'a> { } } +/// Struct containing a disk information. +/// +/// ```no_run +/// use sysinfo::Disks; +/// +/// let mut disks = Disks::new(); +/// disks.refresh_list(); +/// for disk in disks.disks() { +/// println!("{:?}: {:?}", disk.name(), disk.kind()); +/// } +/// ``` +pub struct Disk { + pub(crate) inner: crate::DiskInner, +} + +impl Disk { + /// Returns the kind of disk. + /// + /// ```no_run + /// use sysinfo::Disks; + /// + /// let mut disks = Disks::new(); + /// disks.refresh_list(); + /// for disk in disks.disks() { + /// println!("[{:?}] {:?}", disk.name(), disk.kind()); + /// } + /// ``` + pub fn kind(&self) -> DiskKind { + self.inner.kind() + } + + /// Returns the disk name. + /// + /// ```no_run + /// use sysinfo::Disks; + /// + /// let mut disks = Disks::new(); + /// disks.refresh_list(); + /// for disk in disks.disks() { + /// println!("{:?}", disk.name()); + /// } + /// ``` + pub fn name(&self) -> &OsStr { + self.inner.name() + } + + /// Returns the file system used on this disk (so for example: `EXT4`, `NTFS`, etc...). + /// + /// ```no_run + /// use sysinfo::Disks; + /// + /// let mut disks = Disks::new(); + /// disks.refresh_list(); + /// for disk in disks.disks() { + /// println!("[{:?}] {:?}", disk.name(), disk.file_system()); + /// } + /// ``` + pub fn file_system(&self) -> &[u8] { + self.inner.file_system() + } + + /// Returns the mount point of the disk (`/` for example). + /// + /// ```no_run + /// use sysinfo::Disks; + /// + /// let mut disks = Disks::new(); + /// disks.refresh_list(); + /// for disk in disks.disks() { + /// println!("[{:?}] {:?}", disk.name(), disk.mount_point()); + /// } + /// ``` + pub fn mount_point(&self) -> &Path { + self.inner.mount_point() + } + + /// Returns the total disk size, in bytes. + /// + /// ```no_run + /// use sysinfo::Disks; + /// + /// let mut disks = Disks::new(); + /// disks.refresh_list(); + /// for disk in disks.disks() { + /// println!("[{:?}] {}B", disk.name(), disk.total_space()); + /// } + /// ``` + pub fn total_space(&self) -> u64 { + self.inner.total_space() + } + + /// Returns the available disk size, in bytes. + /// + /// ```no_run + /// use sysinfo::Disks; + /// + /// let mut disks = Disks::new(); + /// disks.refresh_list(); + /// for disk in disks.disks() { + /// println!("[{:?}] {}B", disk.name(), disk.available_space()); + /// } + /// ``` + pub fn available_space(&self) -> u64 { + self.inner.available_space() + } + + /// Returns `true` if the disk is removable. + /// + /// ```no_run + /// use sysinfo::Disks; + /// + /// let mut disks = Disks::new(); + /// disks.refresh_list(); + /// for disk in disks.disks() { + /// println!("[{:?}] {}", disk.name(), disk.is_removable()); + /// } + /// ``` + pub fn is_removable(&self) -> bool { + self.inner.is_removable() + } + + /// Updates the disk' information. + /// + /// ```no_run + /// use sysinfo::Disks; + /// + /// let mut disks = Disks::new(); + /// disks.refresh_list(); + /// for disk in disks.disks_mut() { + /// disk.refresh(); + /// } + /// ``` + pub fn refresh(&mut self) -> bool { + self.inner.refresh() + } +} + /// Disks interface. /// /// ```no_run @@ -485,7 +624,7 @@ impl<'a> Iterator for NetworksIter<'a> { /// } /// ``` pub struct Disks { - pub(crate) inner: crate::DisksInner, + inner: crate::DisksInner, } impl Default for Disks { @@ -530,7 +669,7 @@ impl Disks { /// Returns the disks list. /// /// ```no_run - /// use sysinfo::{DiskExt, Disks}; + /// use sysinfo::Disks; /// /// let mut disks = Disks::new(); /// disks.refresh_list(); @@ -551,7 +690,7 @@ impl Disks { /// You can do the same without this method by calling: /// /// ```no_run - /// use sysinfo::{DiskExt, Disks}; + /// use sysinfo::Disks; /// /// let mut disks = Disks::new(); /// disks.refresh_list(); @@ -631,10 +770,10 @@ impl std::ops::DerefMut for Disks { /// Enum containing the different supported kinds of disks. /// -/// This type is returned by [`DiskExt::kind`](`crate::DiskExt::kind`). +/// This type is returned by [`Disk::kind`](`crate::Disk::kind`). /// /// ```no_run -/// use sysinfo::{DiskExt, Disks}; +/// use sysinfo::Disks; /// /// let mut disks = Disks::new(); /// disks.refresh_list(); diff --git a/src/debug.rs b/src/debug.rs index bc566d277..e710147c1 100644 --- a/src/debug.rs +++ b/src/debug.rs @@ -1,9 +1,8 @@ // Take a look at the license at the top of the repository in the LICENSE file. use crate::{ - Component, ComponentExt, Components, Cpu, CpuExt, Disk, DiskExt, Disks, NetworkData, - NetworkExt, Networks, NetworksExt, Process, ProcessExt, System, SystemExt, User, UserExt, - Users, + Component, ComponentExt, Components, Cpu, CpuExt, Disk, Disks, NetworkData, NetworkExt, + Networks, NetworksExt, Process, ProcessExt, System, SystemExt, User, UserExt, Users, }; use std::fmt; diff --git a/src/lib.rs b/src/lib.rs index 2e8f0a057..e4de7d3cd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -52,15 +52,15 @@ cfg_if::cfg_if! { } pub use crate::common::{ - get_current_pid, CpuRefreshKind, DiskKind, DiskUsage, Disks, Gid, Group, LoadAvg, MacAddr, - Networks, NetworksIter, Pid, PidExt, ProcessRefreshKind, ProcessStatus, RefreshKind, Signal, - Uid, Users, + get_current_pid, CpuRefreshKind, Disk, DiskKind, DiskUsage, Disks, Gid, Group, LoadAvg, + MacAddr, Networks, NetworksIter, Pid, PidExt, ProcessRefreshKind, ProcessStatus, RefreshKind, + Signal, Uid, Users, }; -pub(crate) use crate::sys::DisksInner; -pub use crate::sys::{Component, Components, Cpu, Disk, NetworkData, Process, System, User}; +pub use crate::sys::{Component, Components, Cpu, NetworkData, Process, System, User}; +pub(crate) use crate::sys::{DiskInner, DisksInner}; pub use crate::traits::{ - ComponentExt, ComponentsExt, CpuExt, DiskExt, GroupExt, NetworkExt, NetworksExt, ProcessExt, - SystemExt, UserExt, UsersExt, + ComponentExt, ComponentsExt, CpuExt, GroupExt, NetworkExt, NetworksExt, ProcessExt, SystemExt, + UserExt, UsersExt, }; #[cfg(feature = "c-interface")] diff --git a/src/serde.rs b/src/serde.rs index c9dc5f603..3ef6b8a7e 100644 --- a/src/serde.rs +++ b/src/serde.rs @@ -2,7 +2,7 @@ use crate::common::PidExt; use crate::{ - ComponentExt, CpuExt, DiskExt, DiskKind, DiskUsage, GroupExt, MacAddr, NetworkExt, NetworksExt, + ComponentExt, CpuExt, DiskKind, DiskUsage, GroupExt, MacAddr, NetworkExt, NetworksExt, ProcessExt, ProcessStatus, Signal, SystemExt, UserExt, }; use serde::{ser::SerializeStruct, Serialize, Serializer}; diff --git a/src/traits.rs b/src/traits.rs index 1218b8e21..f00696ca5 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -5,133 +5,15 @@ use crate::{ sys::{Component, Cpu, Process}, }; use crate::{ - CpuRefreshKind, DiskKind, DiskUsage, Group, LoadAvg, NetworksIter, Pid, ProcessRefreshKind, + CpuRefreshKind, DiskUsage, Group, LoadAvg, NetworksIter, Pid, ProcessRefreshKind, ProcessStatus, RefreshKind, Signal, User, }; use std::collections::HashMap; -use std::ffi::OsStr; use std::fmt::Debug; use std::path::Path; use std::time::Duration; -/// Contains all the methods of the [`Disk`][crate::Disk] struct. -/// -/// ```no_run -/// use sysinfo::{DiskExt, Disks}; -/// -/// let mut disks = Disks::new(); -/// disks.refresh_list(); -/// for disk in disks.disks() { -/// println!("{:?}: {:?}", disk.name(), disk.kind()); -/// } -/// ``` -pub trait DiskExt: Debug { - /// Returns the kind of disk. - /// - /// ```no_run - /// use sysinfo::{DiskExt, Disks}; - /// - /// let mut disks = Disks::new(); - /// disks.refresh_list(); - /// for disk in disks.disks() { - /// println!("[{:?}] {:?}", disk.name(), disk.kind()); - /// } - /// ``` - fn kind(&self) -> DiskKind; - - /// Returns the disk name. - /// - /// ```no_run - /// use sysinfo::{DiskExt, Disks}; - /// - /// let mut disks = Disks::new(); - /// disks.refresh_list(); - /// for disk in disks.disks() { - /// println!("{:?}", disk.name()); - /// } - /// ``` - fn name(&self) -> &OsStr; - - /// Returns the file system used on this disk (so for example: `EXT4`, `NTFS`, etc...). - /// - /// ```no_run - /// use sysinfo::{DiskExt, Disks}; - /// - /// let mut disks = Disks::new(); - /// disks.refresh_list(); - /// for disk in disks.disks() { - /// println!("[{:?}] {:?}", disk.name(), disk.file_system()); - /// } - /// ``` - fn file_system(&self) -> &[u8]; - - /// Returns the mount point of the disk (`/` for example). - /// - /// ```no_run - /// use sysinfo::{DiskExt, Disks}; - /// - /// let mut disks = Disks::new(); - /// disks.refresh_list(); - /// for disk in disks.disks() { - /// println!("[{:?}] {:?}", disk.name(), disk.mount_point()); - /// } - /// ``` - fn mount_point(&self) -> &Path; - - /// Returns the total disk size, in bytes. - /// - /// ```no_run - /// use sysinfo::{DiskExt, Disks}; - /// - /// let mut disks = Disks::new(); - /// disks.refresh_list(); - /// for disk in disks.disks() { - /// println!("[{:?}] {}B", disk.name(), disk.total_space()); - /// } - /// ``` - fn total_space(&self) -> u64; - - /// Returns the available disk size, in bytes. - /// - /// ```no_run - /// use sysinfo::{DiskExt, Disks}; - /// - /// let mut disks = Disks::new(); - /// disks.refresh_list(); - /// for disk in disks.disks() { - /// println!("[{:?}] {}B", disk.name(), disk.available_space()); - /// } - /// ``` - fn available_space(&self) -> u64; - - /// Returns `true` if the disk is removable. - /// - /// ```no_run - /// use sysinfo::{DiskExt, Disks}; - /// - /// let mut disks = Disks::new(); - /// disks.refresh_list(); - /// for disk in disks.disks() { - /// println!("[{:?}] {}", disk.name(), disk.is_removable()); - /// } - /// ``` - fn is_removable(&self) -> bool; - - /// Updates the disk' information. - /// - /// ```no_run - /// use sysinfo::{DiskExt, Disks}; - /// - /// let mut disks = Disks::new(); - /// disks.refresh_list(); - /// for disk in disks.disks_mut() { - /// disk.refresh(); - /// } - /// ``` - fn refresh(&mut self) -> bool; -} - /// Contains all the methods of the [`Process`][crate::Process] struct. /// /// ```no_run diff --git a/src/unix/apple/disk.rs b/src/unix/apple/disk.rs index 9ebc9c48b..309d93517 100644 --- a/src/unix/apple/disk.rs +++ b/src/unix/apple/disk.rs @@ -4,7 +4,7 @@ use crate::sys::{ ffi, utils::{self, CFReleaser}, }; -use crate::{DiskExt, DiskKind}; +use crate::{Disk, DiskKind}; use core_foundation_sys::array::CFArrayCreate; use core_foundation_sys::base::kCFAllocatorDefault; @@ -19,8 +19,7 @@ use std::os::unix::ffi::OsStrExt; use std::path::{Path, PathBuf}; use std::ptr; -#[doc = include_str!("../../../md_doc/disk.md")] -pub struct Disk { +pub(crate) struct DiskInner { pub(crate) type_: DiskKind, pub(crate) name: OsString, pub(crate) file_system: Vec, @@ -31,36 +30,36 @@ pub struct Disk { pub(crate) is_removable: bool, } -impl DiskExt for Disk { - fn kind(&self) -> DiskKind { +impl DiskInner { + pub(crate) fn kind(&self) -> DiskKind { self.type_ } - fn name(&self) -> &OsStr { + pub(crate) fn name(&self) -> &OsStr { &self.name } - fn file_system(&self) -> &[u8] { + pub(crate) fn file_system(&self) -> &[u8] { &self.file_system } - fn mount_point(&self) -> &Path { + pub(crate) fn mount_point(&self) -> &Path { &self.mount_point } - fn total_space(&self) -> u64 { + pub(crate) fn total_space(&self) -> u64 { self.total_space } - fn available_space(&self) -> u64 { + pub(crate) fn available_space(&self) -> u64 { self.available_space } - fn is_removable(&self) -> bool { + pub(crate) fn is_removable(&self) -> bool { self.is_removable } - fn refresh(&mut self) -> bool { + pub(crate) fn refresh(&mut self) -> bool { unsafe { if let Some(requested_properties) = build_requested_properties(&[ ffi::kCFURLVolumeAvailableCapacityKey, @@ -406,13 +405,15 @@ unsafe fn new_disk( .collect(); Some(Disk { - type_, - name, - file_system, - mount_point, - volume_url, - total_space, - available_space, - is_removable, + inner: DiskInner { + type_, + name, + file_system, + mount_point, + volume_url, + total_space, + available_space, + is_removable, + }, }) } diff --git a/src/unix/apple/mod.rs b/src/unix/apple/mod.rs index 6c825b5cc..92630067d 100644 --- a/src/unix/apple/mod.rs +++ b/src/unix/apple/mod.rs @@ -26,7 +26,7 @@ mod utils; pub use self::component::{Component, Components}; pub use self::cpu::Cpu; -pub use self::disk::Disk; +pub(crate) use self::disk::DiskInner; pub use self::network::NetworkData; pub use self::process::Process; pub use self::system::System; diff --git a/src/unix/freebsd/disk.rs b/src/unix/freebsd/disk.rs index 8db6f8d03..b570417f1 100644 --- a/src/unix/freebsd/disk.rs +++ b/src/unix/freebsd/disk.rs @@ -1,14 +1,13 @@ // Take a look at the license at the top of the repository in the LICENSE file. -use crate::{DiskExt, DiskKind}; +use crate::{Disk, DiskKind}; use std::ffi::{OsStr, OsString}; use std::path::{Path, PathBuf}; use super::utils::c_buf_to_str; -#[doc = include_str!("../../../md_doc/disk.md")] -pub struct Disk { +pub(crate) struct DiskInner { name: OsString, c_mount_point: Vec, mount_point: PathBuf, @@ -18,36 +17,36 @@ pub struct Disk { is_removable: bool, } -impl DiskExt for Disk { - fn kind(&self) -> DiskKind { +impl DiskInner { + pub(crate) fn kind(&self) -> DiskKind { DiskKind::Unknown(-1) } - fn name(&self) -> &OsStr { + pub(crate) fn name(&self) -> &OsStr { &self.name } - fn file_system(&self) -> &[u8] { + pub(crate) fn file_system(&self) -> &[u8] { &self.file_system } - fn mount_point(&self) -> &Path { + pub(crate) fn mount_point(&self) -> &Path { &self.mount_point } - fn total_space(&self) -> u64 { + pub(crate) fn total_space(&self) -> u64 { self.total_space } - fn available_space(&self) -> u64 { + pub(crate) fn available_space(&self) -> u64 { self.available_space } - fn is_removable(&self) -> bool { + pub(crate) fn is_removable(&self) -> bool { self.is_removable } - fn refresh(&mut self) -> bool { + pub(crate) fn refresh(&mut self) -> bool { unsafe { let mut vfs: libc::statvfs = std::mem::zeroed(); refresh_disk(self, &mut vfs) @@ -78,7 +77,7 @@ impl crate::DisksInner { // FIXME: if you want to get disk I/O usage: // statfs.[f_syncwrites, f_asyncwrites, f_syncreads, f_asyncreads] -unsafe fn refresh_disk(disk: &mut Disk, vfs: &mut libc::statvfs) -> bool { +unsafe fn refresh_disk(disk: &mut DiskInner, vfs: &mut libc::statvfs) -> bool { if libc::statvfs(disk.c_mount_point.as_ptr() as *const _, vfs) < 0 { return false; } @@ -151,13 +150,15 @@ pub unsafe fn get_all_disks(container: &mut Vec) { let f_frsize: u64 = vfs.f_frsize as _; container.push(Disk { - name, - c_mount_point: fs_info.f_mntonname.to_vec(), - mount_point: PathBuf::from(mount_point), - total_space: vfs.f_blocks.saturating_mul(f_frsize), - available_space: vfs.f_favail.saturating_mul(f_frsize), - file_system: fs_type.to_vec(), - is_removable, + inner: DiskInner { + name, + c_mount_point: fs_info.f_mntonname.to_vec(), + mount_point: PathBuf::from(mount_point), + total_space: vfs.f_blocks.saturating_mul(f_frsize), + available_space: vfs.f_favail.saturating_mul(f_frsize), + file_system: fs_type.to_vec(), + is_removable, + }, }); } } diff --git a/src/unix/freebsd/mod.rs b/src/unix/freebsd/mod.rs index d53ed3974..d6f61d088 100644 --- a/src/unix/freebsd/mod.rs +++ b/src/unix/freebsd/mod.rs @@ -10,7 +10,7 @@ mod utils; pub use self::component::{Component, Components}; pub use self::cpu::Cpu; -pub use self::disk::Disk; +pub(crate) use self::disk::DiskInner; pub use self::network::NetworkData; pub use self::process::Process; pub use self::system::System; diff --git a/src/unix/linux/disk.rs b/src/unix/linux/disk.rs index 03faf3382..463245f88 100644 --- a/src/unix/linux/disk.rs +++ b/src/unix/linux/disk.rs @@ -1,7 +1,7 @@ // Take a look at the license at the top of the repository in the LICENSE file. use crate::sys::utils::{get_all_data, to_cpath}; -use crate::{DiskExt, DiskKind}; +use crate::{Disk, DiskKind}; use libc::statvfs; use std::ffi::{OsStr, OsString}; @@ -16,9 +16,7 @@ macro_rules! cast { }; } -#[doc = include_str!("../../../md_doc/disk.md")] -#[derive(PartialEq, Eq)] -pub struct Disk { +pub(crate) struct DiskInner { type_: DiskKind, device_name: OsString, file_system: Vec, @@ -28,36 +26,36 @@ pub struct Disk { is_removable: bool, } -impl DiskExt for Disk { - fn kind(&self) -> DiskKind { +impl DiskInner { + pub(crate) fn kind(&self) -> DiskKind { self.type_ } - fn name(&self) -> &OsStr { + pub(crate) fn name(&self) -> &OsStr { &self.device_name } - fn file_system(&self) -> &[u8] { + pub(crate) fn file_system(&self) -> &[u8] { &self.file_system } - fn mount_point(&self) -> &Path { + pub(crate) fn mount_point(&self) -> &Path { &self.mount_point } - fn total_space(&self) -> u64 { + pub(crate) fn total_space(&self) -> u64 { self.total_space } - fn available_space(&self) -> u64 { + pub(crate) fn available_space(&self) -> u64 { self.available_space } - fn is_removable(&self) -> bool { + pub(crate) fn is_removable(&self) -> bool { self.is_removable } - fn refresh(&mut self) -> bool { + pub(crate) fn refresh(&mut self) -> bool { unsafe { let mut stat: statvfs = mem::zeroed(); let mount_point_cpath = to_cpath(&self.mount_point); @@ -122,13 +120,15 @@ fn new_disk( .iter() .any(|e| e.as_os_str() == device_name); Some(Disk { - type_, - device_name: device_name.to_owned(), - file_system: file_system.to_owned(), - mount_point, - total_space: cast!(total), - available_space: cast!(available), - is_removable, + inner: DiskInner { + type_, + device_name: device_name.to_owned(), + file_system: file_system.to_owned(), + mount_point, + total_space: cast!(total), + available_space: cast!(available), + is_removable, + }, }) } } diff --git a/src/unix/linux/mod.rs b/src/unix/linux/mod.rs index 9d0cf45c6..abefdfd68 100644 --- a/src/unix/linux/mod.rs +++ b/src/unix/linux/mod.rs @@ -10,7 +10,7 @@ pub(crate) mod utils; pub use self::component::{Component, Components}; pub use self::cpu::Cpu; -pub use self::disk::Disk; +pub(crate) use self::disk::DiskInner; pub use self::network::NetworkData; pub use self::process::Process; pub use self::system::System; diff --git a/src/unknown/disk.rs b/src/unknown/disk.rs index ef854c419..2015519bf 100644 --- a/src/unknown/disk.rs +++ b/src/unknown/disk.rs @@ -1,42 +1,41 @@ // Take a look at the license at the top of the repository in the LICENSE file. -use crate::{DiskExt, DiskKind}; +use crate::{Disk, DiskKind}; use std::{ffi::OsStr, path::Path}; -#[doc = include_str!("../../md_doc/disk.md")] -pub struct Disk {} +pub(crate) struct DiskInner; -impl DiskExt for Disk { - fn kind(&self) -> DiskKind { +impl DiskInner { + pub(crate) fn kind(&self) -> DiskKind { unreachable!() } - fn name(&self) -> &OsStr { + pub(crate) fn name(&self) -> &OsStr { unreachable!() } - fn file_system(&self) -> &[u8] { + pub(crate) fn file_system(&self) -> &[u8] { &[] } - fn mount_point(&self) -> &Path { + pub(crate) fn mount_point(&self) -> &Path { Path::new("") } - fn total_space(&self) -> u64 { + pub(crate) fn total_space(&self) -> u64 { 0 } - fn available_space(&self) -> u64 { + pub(crate) fn available_space(&self) -> u64 { 0 } - fn is_removable(&self) -> bool { + pub(crate) fn is_removable(&self) -> bool { false } - fn refresh(&mut self) -> bool { + pub(crate) fn refresh(&mut self) -> bool { true } } diff --git a/src/unknown/mod.rs b/src/unknown/mod.rs index f6a442d02..ccbad4448 100644 --- a/src/unknown/mod.rs +++ b/src/unknown/mod.rs @@ -10,8 +10,7 @@ pub mod users; pub use self::component::{Component, Components}; pub use self::cpu::Cpu; -pub use self::disk::Disk; -pub(crate) use self::disk::DisksInner; +pub(crate) use self::disk::{DiskInner, DisksInner}; pub use self::network::NetworkData; pub use self::process::Process; pub use self::system::System; diff --git a/src/windows/disk.rs b/src/windows/disk.rs index 45cb965d6..697b2b6fc 100644 --- a/src/windows/disk.rs +++ b/src/windows/disk.rs @@ -1,6 +1,6 @@ // Take a look at the license at the top of the repository in the LICENSE file. -use crate::{DiskExt, DiskKind}; +use crate::{Disk, DiskKind}; use std::ffi::{c_void, OsStr, OsString}; use std::mem::size_of; @@ -19,8 +19,7 @@ use windows::Win32::System::Ioctl::{ use windows::Win32::System::WindowsProgramming::{DRIVE_FIXED, DRIVE_REMOVABLE}; use windows::Win32::System::IO::DeviceIoControl; -#[doc = include_str!("../../md_doc/disk.md")] -pub struct Disk { +pub(crate) struct DiskInner { type_: DiskKind, name: OsString, file_system: Vec, @@ -31,36 +30,36 @@ pub struct Disk { is_removable: bool, } -impl DiskExt for Disk { - fn kind(&self) -> DiskKind { +impl DiskInner { + pub(crate) fn kind(&self) -> DiskKind { self.type_ } - fn name(&self) -> &OsStr { + pub(crate) fn name(&self) -> &OsStr { &self.name } - fn file_system(&self) -> &[u8] { + pub(crate) fn file_system(&self) -> &[u8] { &self.file_system } - fn mount_point(&self) -> &Path { + pub(crate) fn mount_point(&self) -> &Path { Path::new(&self.s_mount_point) } - fn total_space(&self) -> u64 { + pub(crate) fn total_space(&self) -> u64 { self.total_space } - fn available_space(&self) -> u64 { + pub(crate) fn available_space(&self) -> u64 { self.available_space } - fn is_removable(&self) -> bool { + pub(crate) fn is_removable(&self) -> bool { self.is_removable } - fn refresh(&mut self) -> bool { + pub(crate) fn refresh(&mut self) -> bool { if self.total_space != 0 { unsafe { let mut tmp = 0; @@ -247,14 +246,16 @@ pub(crate) unsafe fn get_disks() -> Vec { } }; Some(Disk { - type_, - name: name.to_owned(), - file_system: file_system.to_vec(), - mount_point: mount_point.to_vec(), - s_mount_point: String::from_utf16_lossy(&mount_point[..mount_point.len() - 1]), - total_space, - available_space, - is_removable, + inner: DiskInner { + type_, + name: name.to_owned(), + file_system: file_system.to_vec(), + mount_point: mount_point.to_vec(), + s_mount_point: String::from_utf16_lossy(&mount_point[..mount_point.len() - 1]), + total_space, + available_space, + is_removable, + }, }) }) .collect::>() diff --git a/src/windows/mod.rs b/src/windows/mod.rs index c9da72615..a7445a3d0 100644 --- a/src/windows/mod.rs +++ b/src/windows/mod.rs @@ -14,8 +14,7 @@ mod utils; pub use self::component::{Component, Components}; pub use self::cpu::Cpu; -pub use self::disk::Disk; -pub(crate) use self::disk::DisksInner; +pub(crate) use self::disk::{DiskInner, DisksInner}; pub use self::network::NetworkData; pub use self::process::Process; pub use self::sid::Sid;