Skip to content

Commit

Permalink
Rename *RefreshKind::new method into nothing
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Nov 30, 2024
1 parent 68e94d9 commit 17771c7
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 69 deletions.
10 changes: 5 additions & 5 deletions src/common/disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ impl Disk {
///
/// let mut disks = Disks::new_with_refreshed_list();
/// for disk in disks.list_mut() {
/// disk.refresh_specifics(DiskRefreshKind::new());
/// disk.refresh_specifics(DiskRefreshKind::nothing());
/// }
/// ```
pub fn refresh_specifics(&mut self, refreshes: DiskRefreshKind) -> bool {
Expand Down Expand Up @@ -283,7 +283,7 @@ impl Disks {
/// ```no_run
/// use sysinfo::{Disks, DiskRefreshKind};
///
/// let mut disks = Disks::new_with_refreshed_list_specifics(DiskRefreshKind::new());
/// let mut disks = Disks::new_with_refreshed_list_specifics(DiskRefreshKind::nothing());
/// for disk in disks.list() {
/// println!("{disk:?}");
/// }
Expand Down Expand Up @@ -380,7 +380,7 @@ impl Disks {
/// use sysinfo::{Disks, DiskRefreshKind};
///
/// let mut disks = Disks::new();
/// disks.refresh_list_specifics(true, DiskRefreshKind::new());
/// disks.refresh_list_specifics(true, DiskRefreshKind::nothing());
/// ```
pub fn refresh_list_specifics(
&mut self,
Expand Down Expand Up @@ -466,13 +466,13 @@ impl DiskRefreshKind {
/// ```
/// use sysinfo::DiskRefreshKind;
///
/// let r = DiskRefreshKind::new();
/// let r = DiskRefreshKind::nothing();
///
/// assert_eq!(r.kind(), false);
/// assert_eq!(r.storage(), false);
/// assert_eq!(r.io_usage(), false);
/// ```
pub fn new() -> Self {
pub fn nothing() -> Self {
Self::default()
}

Expand Down
12 changes: 6 additions & 6 deletions src/common/impl_get_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ macro_rules! impl_get_set {
```
use sysinfo::", stringify!($ty_name), ";
let r = ", stringify!($ty_name), "::new();
let r = ", stringify!($ty_name), "::nothing();
let r = r.with_", stringify!($name), "();
assert_eq!(r.", stringify!($name), "(), true);
Expand All @@ -27,7 +27,7 @@ assert_eq!(r.", stringify!($name), "(), false);
```
use sysinfo::", stringify!($ty_name), ";
let r = ", stringify!($ty_name), "::new();
let r = ", stringify!($ty_name), "::nothing();
let r = r.with_", stringify!($name), "();
assert_eq!(r.", stringify!($name), "(), true);
Expand Down Expand Up @@ -66,7 +66,7 @@ assert_eq!(r.", stringify!($name), "(), false);
```
use sysinfo::{", stringify!($ty_name), ", UpdateKind};
let r = ", stringify!($ty_name), "::new();
let r = ", stringify!($ty_name), "::nothing();
assert_eq!(r.", stringify!($name), "(), UpdateKind::Never);
let r = r.with_", stringify!($name), "(UpdateKind::OnlyIfNotSet);
Expand All @@ -84,7 +84,7 @@ assert_eq!(r.", stringify!($name), "(), UpdateKind::Never);
```
use sysinfo::{", stringify!($ty_name), ", UpdateKind};
let r = ", stringify!($ty_name), "::new();
let r = ", stringify!($ty_name), "::nothing();
assert_eq!(r.", stringify!($name), "(), UpdateKind::Never);
let r = r.with_", stringify!($name), "(UpdateKind::OnlyIfNotSet);
Expand Down Expand Up @@ -121,7 +121,7 @@ assert_eq!(r.", stringify!($name), "(), UpdateKind::Never);
```
use sysinfo::{", stringify!($ty_name), ", ", stringify!($typ), "};
let r = ", stringify!($ty_name), "::new();
let r = ", stringify!($ty_name), "::nothing();
assert_eq!(r.", stringify!($name), "().is_some(), false);
let r = r.with_", stringify!($name), "(", stringify!($typ), "::everything());
Expand All @@ -139,7 +139,7 @@ assert_eq!(r.", stringify!($name), "().is_some(), false);
```
use sysinfo::{", stringify!($ty_name), ", ", stringify!($typ), "};
let r = ", stringify!($ty_name), "::new();
let r = ", stringify!($ty_name), "::nothing();
assert_eq!(r.", stringify!($name), "().is_some(), false);
let r = r.with_", stringify!($name), "(", stringify!($typ), "::everything());
Expand Down
58 changes: 29 additions & 29 deletions src/common/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl System {
/// let s = System::new();
/// ```
pub fn new() -> Self {
Self::new_with_specifics(RefreshKind::new())
Self::new_with_specifics(RefreshKind::nothing())
}

/// Creates a new [`System`] instance with everything loaded.
Expand Down Expand Up @@ -73,7 +73,7 @@ impl System {
///
/// // We want to only refresh processes.
/// let mut system = System::new_with_specifics(
/// RefreshKind::new().with_processes(ProcessRefreshKind::everything()),
/// RefreshKind::nothing().with_processes(ProcessRefreshKind::everything()),
/// );
///
/// # if sysinfo::IS_SUPPORTED_SYSTEM && !cfg!(feature = "apple-sandbox") {
Expand All @@ -98,7 +98,7 @@ impl System {
///
/// // Let's just update processes:
/// s.refresh_specifics(
/// RefreshKind::new().with_processes(ProcessRefreshKind::everything()),
/// RefreshKind::nothing().with_processes(ProcessRefreshKind::everything()),
/// );
/// ```
pub fn refresh_specifics(&mut self, refreshes: RefreshKind) {
Expand Down Expand Up @@ -152,7 +152,7 @@ impl System {
/// use sysinfo::{MemoryRefreshKind, System};
///
/// let mut s = System::new();
/// s.refresh_memory_specifics(MemoryRefreshKind::new().with_ram());
/// s.refresh_memory_specifics(MemoryRefreshKind::nothing().with_ram());
/// ```
pub fn refresh_memory_specifics(&mut self, refresh_kind: MemoryRefreshKind) {
self.inner.refresh_memory_specifics(refresh_kind)
Expand All @@ -166,7 +166,7 @@ impl System {
/// to get accurate value as it uses previous results to compute the next value.
///
/// Calling this method is the same as calling
/// `system.refresh_cpu_specifics(CpuRefreshKind::new().with_cpu_usage())`.
/// `system.refresh_cpu_specifics(CpuRefreshKind::nothing().with_cpu_usage())`.
///
/// ```no_run
/// use sysinfo::System;
Expand All @@ -180,13 +180,13 @@ impl System {
///
/// [`MINIMUM_CPU_UPDATE_INTERVAL`]: crate::MINIMUM_CPU_UPDATE_INTERVAL
pub fn refresh_cpu_usage(&mut self) {
self.refresh_cpu_specifics(CpuRefreshKind::new().with_cpu_usage())
self.refresh_cpu_specifics(CpuRefreshKind::nothing().with_cpu_usage())
}

/// Refreshes CPUs frequency information.
///
/// Calling this method is the same as calling
/// `system.refresh_cpu_specifics(CpuRefreshKind::new().with_frequency())`.
/// `system.refresh_cpu_specifics(CpuRefreshKind::nothing().with_frequency())`.
///
/// ```no_run
/// use sysinfo::System;
Expand All @@ -195,7 +195,7 @@ impl System {
/// s.refresh_cpu_frequency();
/// ```
pub fn refresh_cpu_frequency(&mut self) {
self.refresh_cpu_specifics(CpuRefreshKind::new().with_frequency())
self.refresh_cpu_specifics(CpuRefreshKind::nothing().with_frequency())
}

/// Refreshes the list of CPU.
Expand Down Expand Up @@ -265,7 +265,7 @@ impl System {
/// system.refresh_processes_specifics(
/// ProcessesToUpdate::All,
/// true,
/// ProcessRefreshKind::new()
/// ProcessRefreshKind::nothing()
/// .with_memory()
/// .with_cpu()
/// .with_disk_usage()
Expand Down Expand Up @@ -296,7 +296,7 @@ impl System {
self.refresh_processes_specifics(
processes_to_update,
remove_dead_processes,
ProcessRefreshKind::new()
ProcessRefreshKind::nothing()
.with_memory()
.with_cpu()
.with_disk_usage()
Expand Down Expand Up @@ -469,7 +469,7 @@ impl System {
/// use sysinfo::{CpuRefreshKind, RefreshKind, System};
///
/// let mut s = System::new_with_specifics(
/// RefreshKind::new().with_cpu(CpuRefreshKind::everything()),
/// RefreshKind::nothing().with_cpu(CpuRefreshKind::everything()),
/// );
/// // Wait a bit because CPU usage is based on diff.
/// std::thread::sleep(sysinfo::MINIMUM_CPU_UPDATE_INTERVAL);
Expand All @@ -490,7 +490,7 @@ impl System {
/// use sysinfo::{CpuRefreshKind, RefreshKind, System};
///
/// let mut s = System::new_with_specifics(
/// RefreshKind::new().with_cpu(CpuRefreshKind::everything()),
/// RefreshKind::nothing().with_cpu(CpuRefreshKind::everything()),
/// );
/// // Wait a bit because CPU usage is based on diff.
/// std::thread::sleep(sysinfo::MINIMUM_CPU_UPDATE_INTERVAL);
Expand Down Expand Up @@ -1393,7 +1393,7 @@ impl Process {
/// s.refresh_processes_specifics(
/// ProcessesToUpdate::All,
/// true,
/// ProcessRefreshKind::new().with_cpu()
/// ProcessRefreshKind::nothing().with_cpu()
/// );
/// if let Some(process) = s.process(Pid::from(1337)) {
/// println!("{}%", process.cpu_usage());
Expand Down Expand Up @@ -1699,7 +1699,7 @@ cfg_if! {
/// system.refresh_processes_specifics(
/// ProcessesToUpdate::All,
/// true,
/// ProcessRefreshKind::new().with_exe(UpdateKind::OnlyIfNotSet),
/// ProcessRefreshKind::nothing().with_exe(UpdateKind::OnlyIfNotSet),
/// );
/// ```
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
Expand Down Expand Up @@ -1803,12 +1803,12 @@ impl ProcessRefreshKind {
/// ```
/// use sysinfo::{ProcessRefreshKind, UpdateKind};
///
/// let r = ProcessRefreshKind::new();
/// let r = ProcessRefreshKind::nothing();
///
/// assert_eq!(r.cpu(), false);
/// assert_eq!(r.user(), UpdateKind::Never);
/// ```
pub fn new() -> Self {
pub fn nothing() -> Self {
Self::default()
}

Expand Down Expand Up @@ -1910,12 +1910,12 @@ impl CpuRefreshKind {
/// ```
/// use sysinfo::CpuRefreshKind;
///
/// let r = CpuRefreshKind::new();
/// let r = CpuRefreshKind::nothing();
///
/// assert_eq!(r.frequency(), false);
/// assert_eq!(r.cpu_usage(), false);
/// ```
pub fn new() -> Self {
pub fn nothing() -> Self {
Self::default()
}

Expand Down Expand Up @@ -1952,7 +1952,7 @@ impl CpuRefreshKind {
/// let mut system = System::new();
///
/// // We don't want to update all memories information.
/// system.refresh_memory_specifics(MemoryRefreshKind::new().with_ram());
/// system.refresh_memory_specifics(MemoryRefreshKind::nothing().with_ram());
///
/// println!("total RAM: {}", system.total_memory());
/// println!("free RAM: {}", system.free_memory());
Expand All @@ -1969,12 +1969,12 @@ impl MemoryRefreshKind {
/// ```
/// use sysinfo::MemoryRefreshKind;
///
/// let r = MemoryRefreshKind::new();
/// let r = MemoryRefreshKind::nothing();
///
/// assert_eq!(r.ram(), false);
/// assert_eq!(r.swap(), false);
/// ```
pub fn new() -> Self {
pub fn nothing() -> Self {
Self::default()
}

Expand Down Expand Up @@ -2029,13 +2029,13 @@ impl RefreshKind {
/// ```
/// use sysinfo::RefreshKind;
///
/// let r = RefreshKind::new();
/// let r = RefreshKind::nothing();
///
/// assert_eq!(r.processes().is_some(), false);
/// assert_eq!(r.memory().is_some(), false);
/// assert_eq!(r.cpu().is_some(), false);
/// ```
pub fn new() -> Self {
pub fn nothing() -> Self {
Self::default()
}

Expand Down Expand Up @@ -2129,7 +2129,7 @@ pub fn get_current_pid() -> Result<Pid, &'static str> {
/// use sysinfo::{System, RefreshKind, CpuRefreshKind};
///
/// let mut s = System::new_with_specifics(
/// RefreshKind::new().with_cpu(CpuRefreshKind::everything()),
/// RefreshKind::nothing().with_cpu(CpuRefreshKind::everything()),
/// );
///
/// // Wait a bit because CPU usage is based on diff.
Expand All @@ -2155,7 +2155,7 @@ impl Cpu {
/// use sysinfo::{System, RefreshKind, CpuRefreshKind};
///
/// let mut s = System::new_with_specifics(
/// RefreshKind::new().with_cpu(CpuRefreshKind::everything()),
/// RefreshKind::nothing().with_cpu(CpuRefreshKind::everything()),
/// );
///
/// // Wait a bit because CPU usage is based on diff.
Expand All @@ -2177,7 +2177,7 @@ impl Cpu {
/// use sysinfo::{System, RefreshKind, CpuRefreshKind};
///
/// let s = System::new_with_specifics(
/// RefreshKind::new().with_cpu(CpuRefreshKind::everything()),
/// RefreshKind::nothing().with_cpu(CpuRefreshKind::everything()),
/// );
/// for cpu in s.cpus() {
/// println!("{}", cpu.name());
Expand All @@ -2193,7 +2193,7 @@ impl Cpu {
/// use sysinfo::{System, RefreshKind, CpuRefreshKind};
///
/// let s = System::new_with_specifics(
/// RefreshKind::new().with_cpu(CpuRefreshKind::everything()),
/// RefreshKind::nothing().with_cpu(CpuRefreshKind::everything()),
/// );
/// for cpu in s.cpus() {
/// println!("{}", cpu.vendor_id());
Expand All @@ -2209,7 +2209,7 @@ impl Cpu {
/// use sysinfo::{System, RefreshKind, CpuRefreshKind};
///
/// let s = System::new_with_specifics(
/// RefreshKind::new().with_cpu(CpuRefreshKind::everything()),
/// RefreshKind::nothing().with_cpu(CpuRefreshKind::everything()),
/// );
/// for cpu in s.cpus() {
/// println!("{}", cpu.brand());
Expand All @@ -2225,7 +2225,7 @@ impl Cpu {
/// use sysinfo::{System, RefreshKind, CpuRefreshKind};
///
/// let s = System::new_with_specifics(
/// RefreshKind::new().with_cpu(CpuRefreshKind::everything()),
/// RefreshKind::nothing().with_cpu(CpuRefreshKind::everything()),
/// );
/// for cpu in s.cpus() {
/// println!("{}", cpu.frequency());
Expand Down
12 changes: 6 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,10 +305,10 @@ mod test {
#[cfg(feature = "system")]
{
// And now check that our `get_user_by_id` method works.
let s = System::new_with_specifics(
RefreshKind::new()
.with_processes(ProcessRefreshKind::new().with_user(UpdateKind::Always)),
);
let s =
System::new_with_specifics(RefreshKind::nothing().with_processes(
ProcessRefreshKind::nothing().with_user(UpdateKind::Always),
));
assert!(s
.processes()
.iter()
Expand All @@ -325,8 +325,8 @@ mod test {
// If `getent` doesn't find them, we can assume it's a dark secret from the linux land.
if IS_SUPPORTED_SYSTEM && cfg!(not(target_os = "linux")) {
let s = System::new_with_specifics(
RefreshKind::new()
.with_processes(ProcessRefreshKind::new().with_user(UpdateKind::Always)),
RefreshKind::nothing()
.with_processes(ProcessRefreshKind::nothing().with_user(UpdateKind::Always)),
);
let users = Users::new_with_refreshed_list();

Expand Down
2 changes: 1 addition & 1 deletion src/unix/apple/cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ mod test {
let stdout = String::from_utf8(child.stdout).expect("Not valid UTF8");

let sys = System::new_with_specifics(
crate::RefreshKind::new().with_cpu(CpuRefreshKind::new().with_cpu_usage()),
crate::RefreshKind::nothing().with_cpu(CpuRefreshKind::nothing().with_cpu_usage()),
);
let cpus = sys.cpus();
assert!(!cpus.is_empty(), "no CPU found");
Expand Down
2 changes: 1 addition & 1 deletion src/unix/linux/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ impl SystemInner {
return;
}
self.cpus
.refresh_if_needed(true, CpuRefreshKind::new().with_cpu_usage());
.refresh_if_needed(true, CpuRefreshKind::nothing().with_cpu_usage());

if self.cpus.is_empty() {
sysinfo_debug!("cannot compute processes CPU usage: no CPU found...");
Expand Down
2 changes: 1 addition & 1 deletion src/windows/cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ impl CpusWrapper {
}

pub fn len(&mut self) -> usize {
self.init_if_needed(CpuRefreshKind::new());
self.init_if_needed(CpuRefreshKind::nothing());
self.cpus.len()
}

Expand Down
Loading

0 comments on commit 17771c7

Please sign in to comment.