Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rename public DiskExt method type_ to kind #966

Merged
merged 2 commits into from
Apr 3, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,20 +497,20 @@ impl<'a> IntoIterator for &'a Networks {
}
}

/// Enum containing the different supported disks types.
/// Enum containing the different supported kinds of disks.
///
/// This type is returned by [`Disk::get_type`][crate::Disk#method.type].
/// This type is returned by [`crate::DiskExt::kind`].
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'll be displayed as crate::DiskExt::kind, which isn't great. Can you use the old format please?

///
/// ```no_run
/// use sysinfo::{System, SystemExt, DiskExt};
///
/// let system = System::new_all();
/// for disk in system.disks() {
/// println!("{:?}: {:?}", disk.name(), disk.type_());
/// println!("{:?}: {:?}", disk.name(), disk.kind());
/// }
/// ```
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum DiskType {
pub enum DiskKind {
/// HDD type.
HDD,
/// SSD type.
Expand Down
2 changes: 1 addition & 1 deletion src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl fmt::Debug for Disk {
.iter()
.map(|c| *c as char)
.collect::<Vec<_>>(),
self.type_(),
self.kind(),
if self.is_removable() { "yes" } else { "no" },
self.mount_point(),
self.available_space(),
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ cfg_if::cfg_if! {
}

pub use common::{
get_current_pid, CpuRefreshKind, DiskType, DiskUsage, Gid, LoadAvg, MacAddr, NetworksIter, Pid,
get_current_pid, CpuRefreshKind, DiskKind, DiskUsage, Gid, LoadAvg, MacAddr, NetworksIter, Pid,
PidExt, ProcessRefreshKind, ProcessStatus, RefreshKind, Signal, Uid, User,
};
pub use sys::{Component, Cpu, Disk, NetworkData, Networks, Process, System};
Expand Down
16 changes: 8 additions & 8 deletions src/linux/disk.rs
Original file line number Diff line number Diff line change
@@ -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, DiskType};
use crate::{DiskExt, DiskKind};

use libc::statvfs;
use std::ffi::{OsStr, OsString};
Expand All @@ -19,7 +19,7 @@ macro_rules! cast {
#[doc = include_str!("../../md_doc/disk.md")]
#[derive(PartialEq, Eq)]
pub struct Disk {
type_: DiskType,
type_: DiskKind,
device_name: OsString,
file_system: Vec<u8>,
mount_point: PathBuf,
Expand All @@ -29,7 +29,7 @@ pub struct Disk {
}

impl DiskExt for Disk {
fn type_(&self) -> DiskType {
fn kind(&self) -> DiskKind {
self.type_
}

Expand Down Expand Up @@ -111,7 +111,7 @@ fn new_disk(
}

#[allow(clippy::manual_range_contains)]
fn find_type_for_device_name(device_name: &OsStr) -> DiskType {
fn find_type_for_device_name(device_name: &OsStr) -> DiskKind {
// The format of devices are as follows:
// - device_name is symbolic link in the case of /dev/mapper/
// and /dev/root, and the target is corresponding device under
Expand Down Expand Up @@ -171,13 +171,13 @@ fn find_type_for_device_name(device_name: &OsStr) -> DiskType {
.ok()
{
// The disk is marked as rotational so it's a HDD.
Some(1) => DiskType::HDD,
Some(1) => DiskKind::HDD,
// The disk is marked as non-rotational so it's very likely a SSD.
Some(0) => DiskType::SSD,
Some(0) => DiskKind::SSD,
// Normally it shouldn't happen but welcome to the wonderful world of IT! :D
Some(x) => DiskType::Unknown(x),
Some(x) => DiskKind::Unknown(x),
// The information isn't available...
None => DiskType::Unknown(-1),
None => DiskKind::Unknown(-1),
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
sys::{Component, Cpu, Disk, Networks, Process},
};
use crate::{
CpuRefreshKind, DiskType, DiskUsage, LoadAvg, NetworksIter, Pid, ProcessRefreshKind,
CpuRefreshKind, DiskKind, DiskUsage, LoadAvg, NetworksIter, Pid, ProcessRefreshKind,
ProcessStatus, RefreshKind, Signal, User,
};

Expand All @@ -22,21 +22,21 @@ use std::time::Duration;
///
/// let s = System::new();
/// for disk in s.disks() {
/// println!("{:?}: {:?}", disk.name(), disk.type_());
/// println!("{:?}: {:?}", disk.name(), disk.kind());
/// }
/// ```
pub trait DiskExt: Debug {
/// Returns the disk type.
/// Returns the kind of disk.
///
/// ```no_run
/// use sysinfo::{DiskExt, System, SystemExt};
///
/// let s = System::new();
/// for disk in s.disks() {
/// println!("{:?}", disk.type_());
/// println!("{:?}", disk.kind());
/// }
/// ```
fn type_(&self) -> DiskType;
fn kind(&self) -> DiskKind;

/// Returns the disk name.
///
Expand Down