diff --git a/README.md b/README.md index 815a88b79..24bcc608e 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ println!("=> disks:"); let mut disks = Disks::new(); // We refresh the disk list. disks.refresh_list(); -for disk in disks.iter() { +for disk in &disks { println!("{disk:?}"); } @@ -90,7 +90,7 @@ let mut components = Components::new(); // We refresh the component list. components.refresh_list(); println!("=> components:"); -for component in components.iter() { +for component in &components { println!("{component:?}"); } ``` diff --git a/benches/basic.rs b/benches/basic.rs index 784aebe77..e2dba98d5 100644 --- a/benches/basic.rs +++ b/benches/basic.rs @@ -72,7 +72,7 @@ fn bench_refresh_disk(b: &mut test::Bencher) { let mut disks = sysinfo::Disks::new(); disks.refresh_list(); - let disks = disks.disks_mut(); + let disks = disks.list_mut(); let disk = &mut disks[0]; b.iter(move || { disk.refresh(); diff --git a/examples/simple.rs b/examples/simple.rs index d60edbd2c..e79324e14 100644 --- a/examples/simple.rs +++ b/examples/simple.rs @@ -362,12 +362,12 @@ fn interpret_input( } } "disks" => { - for disk in disks.disks() { + for disk in disks { writeln!(&mut io::stdout(), "{disk:?}"); } } "users" => { - for user in users.users() { + for user in users { writeln!( &mut io::stdout(), "{:?} => {:?}", diff --git a/src/common.rs b/src/common.rs index e5e492426..f3485271e 100644 --- a/src/common.rs +++ b/src/common.rs @@ -1872,7 +1872,7 @@ impl NetworkData { /// /// let mut disks = Disks::new(); /// disks.refresh_list(); -/// for disk in disks.disks() { +/// for disk in disks.list() { /// println!("{:?}: {:?}", disk.name(), disk.kind()); /// } /// ``` @@ -1888,7 +1888,7 @@ impl Disk { /// /// let mut disks = Disks::new(); /// disks.refresh_list(); - /// for disk in disks.disks() { + /// for disk in disks.list() { /// println!("[{:?}] {:?}", disk.name(), disk.kind()); /// } /// ``` @@ -1903,7 +1903,7 @@ impl Disk { /// /// let mut disks = Disks::new(); /// disks.refresh_list(); - /// for disk in disks.disks() { + /// for disk in disks.list() { /// println!("{:?}", disk.name()); /// } /// ``` @@ -1918,7 +1918,7 @@ impl Disk { /// /// let mut disks = Disks::new(); /// disks.refresh_list(); - /// for disk in disks.disks() { + /// for disk in disks.list() { /// println!("[{:?}] {:?}", disk.name(), disk.file_system()); /// } /// ``` @@ -1933,7 +1933,7 @@ impl Disk { /// /// let mut disks = Disks::new(); /// disks.refresh_list(); - /// for disk in disks.disks() { + /// for disk in disks.list() { /// println!("[{:?}] {:?}", disk.name(), disk.mount_point()); /// } /// ``` @@ -1948,7 +1948,7 @@ impl Disk { /// /// let mut disks = Disks::new(); /// disks.refresh_list(); - /// for disk in disks.disks() { + /// for disk in disks.list() { /// println!("[{:?}] {}B", disk.name(), disk.total_space()); /// } /// ``` @@ -1963,7 +1963,7 @@ impl Disk { /// /// let mut disks = Disks::new(); /// disks.refresh_list(); - /// for disk in disks.disks() { + /// for disk in disks.list() { /// println!("[{:?}] {}B", disk.name(), disk.available_space()); /// } /// ``` @@ -1978,7 +1978,7 @@ impl Disk { /// /// let mut disks = Disks::new(); /// disks.refresh_list(); - /// for disk in disks.disks() { + /// for disk in disks.list() { /// println!("[{:?}] {}", disk.name(), disk.is_removable()); /// } /// ``` @@ -1993,7 +1993,7 @@ impl Disk { /// /// let mut disks = Disks::new(); /// disks.refresh_list(); - /// for disk in disks.disks_mut() { + /// for disk in disks.list_mut() { /// disk.refresh(); /// } /// ``` @@ -2009,7 +2009,7 @@ impl Disk { /// /// let mut disks = Disks::new(); /// disks.refresh_list(); -/// for disk in disks.disks() { +/// for disk in disks.list() { /// println!("{disk:?}"); /// } /// ``` @@ -2028,7 +2028,7 @@ impl<'a> IntoIterator for &'a Disks { type IntoIter = std::slice::Iter<'a, Disk>; fn into_iter(self) -> Self::IntoIter { - self.disks().iter() + self.list().iter() } } @@ -2037,7 +2037,7 @@ impl<'a> IntoIterator for &'a mut Disks { type IntoIter = std::slice::IterMut<'a, Disk>; fn into_iter(self) -> Self::IntoIter { - self.disks_mut().iter_mut() + self.list_mut().iter_mut() } } @@ -2049,7 +2049,7 @@ impl Disks { /// /// let mut disks = Disks::new(); /// disks.refresh_list(); - /// for disk in disks.disks() { + /// for disk in disks.list() { /// eprintln!("{disk:?}"); /// } /// ``` @@ -2066,12 +2066,12 @@ impl Disks { /// /// let mut disks = Disks::new(); /// disks.refresh_list(); - /// for disk in disks.disks() { + /// for disk in disks.list() { /// eprintln!("{disk:?}"); /// } /// ``` - pub fn disks(&self) -> &[Disk] { - self.inner.disks() + pub fn list(&self) -> &[Disk] { + self.inner.list() } /// Returns the disks list. @@ -2081,13 +2081,13 @@ impl Disks { /// /// let mut disks = Disks::new(); /// disks.refresh_list(); - /// for disk in disks.disks_mut() { + /// for disk in disks.list_mut() { /// disk.refresh(); /// eprintln!("{disk:?}"); /// } /// ``` - pub fn disks_mut(&mut self) -> &mut [Disk] { - self.inner.disks_mut() + pub fn list_mut(&mut self) -> &mut [Disk] { + self.inner.list_mut() } /// Refreshes the listed disks' information. @@ -2108,7 +2108,7 @@ impl Disks { /// disks.refresh(); /// ``` pub fn refresh(&mut self) { - for disk in self.disks_mut() { + for disk in self.list_mut() { disk.refresh(); } } @@ -2140,13 +2140,13 @@ impl std::ops::Deref for Disks { type Target = [Disk]; fn deref(&self) -> &Self::Target { - self.disks() + self.list() } } impl std::ops::DerefMut for Disks { fn deref_mut(&mut self) -> &mut Self::Target { - self.disks_mut() + self.list_mut() } } @@ -2159,7 +2159,7 @@ impl std::ops::DerefMut for Disks { /// /// let mut disks = Disks::new(); /// disks.refresh_list(); -/// for disk in disks.disks() { +/// for disk in disks.list() { /// println!("{:?}: {:?}", disk.name(), disk.kind()); /// } /// ``` @@ -2179,7 +2179,7 @@ pub enum DiskKind { /// use sysinfo::Users; /// /// let mut users = Users::new(); -/// for user in users.users() { +/// for user in users.list() { /// println!("{} is in {} groups", user.name(), user.groups().len()); /// } /// ``` @@ -2197,13 +2197,13 @@ impl std::ops::Deref for Users { type Target = [User]; fn deref(&self) -> &Self::Target { - self.users() + self.list() } } impl std::ops::DerefMut for Users { fn deref_mut(&mut self) -> &mut Self::Target { - self.users_mut() + self.list_mut() } } @@ -2212,7 +2212,7 @@ impl<'a> IntoIterator for &'a Users { type IntoIter = std::slice::Iter<'a, User>; fn into_iter(self) -> Self::IntoIter { - self.users().iter() + self.list().iter() } } @@ -2221,7 +2221,7 @@ impl<'a> IntoIterator for &'a mut Users { type IntoIter = std::slice::IterMut<'a, User>; fn into_iter(self) -> Self::IntoIter { - self.users_mut().iter_mut() + self.list_mut().iter_mut() } } @@ -2233,7 +2233,7 @@ impl Users { /// /// let mut users = Users::new(); /// users.refresh_list(); - /// for user in users.users() { + /// for user in users.list() { /// eprintln!("{user:?}"); /// } /// ``` @@ -2248,11 +2248,11 @@ impl Users { /// /// let mut users = Users::new(); /// users.refresh_list(); - /// for user in users.users() { + /// for user in users.list() { /// eprintln!("{user:?}"); /// } /// ``` - pub fn users(&self) -> &[User] { + pub fn list(&self) -> &[User] { &self.users } @@ -2263,11 +2263,11 @@ impl Users { /// /// let mut users = Users::new(); /// users.refresh_list(); - /// users.users_mut().sort_by(|user1, user2| { + /// users.list_mut().sort_by(|user1, user2| { /// user1.name().partial_cmp(user2.name()).unwrap() /// }); /// ``` - pub fn users_mut(&mut self) -> &mut [User] { + pub fn list_mut(&mut self) -> &mut [User] { &mut self.users } @@ -2294,7 +2294,7 @@ impl Users { /// # use sysinfo::Users; /// let mut users = Users::new(); /// users.refresh_list(); - /// users.users().find(|user| user.id() == user_id); + /// users.list().find(|user| user.id() == user_id); /// ``` /// /// Full example: @@ -2559,7 +2559,7 @@ cfg_if::cfg_if! { /// /// let mut users = Users::new(); /// users.refresh_list(); -/// for user in users.users() { +/// for user in users.list() { /// println!("{:?}", user); /// } /// ``` @@ -2597,7 +2597,7 @@ impl User { /// /// let mut users = Users::new(); /// users.refresh_list(); - /// for user in users.users() { + /// for user in users.list() { /// println!("{:?}", *user.id()); /// } /// ``` @@ -2619,7 +2619,7 @@ impl User { /// /// let mut users = Users::new(); /// users.refresh_list(); - /// for user in users.users() { + /// for user in users.list() { /// println!("{}", *user.group_id()); /// } /// ``` @@ -2634,7 +2634,7 @@ impl User { /// /// let mut users = Users::new(); /// users.refresh_list(); - /// for user in users.users() { + /// for user in users.list() { /// println!("{}", user.name()); /// } /// ``` @@ -2651,7 +2651,7 @@ impl User { /// /// let mut users = Users::new(); /// users.refresh_list(); - /// for user in users.users() { + /// for user in users.list() { /// println!("{} is in {:?}", user.name(), user.groups()); /// } /// ``` @@ -2669,7 +2669,7 @@ impl User { /// /// let mut users = Users::new(); /// -/// for user in users.users() { +/// for user in users.list() { /// println!( /// "user: (ID: {:?}, group ID: {:?}, name: {:?})", /// user.id(), @@ -2697,7 +2697,7 @@ impl Group { /// /// let mut users = Users::new(); /// - /// for user in users.users() { + /// for user in users.list() { /// for group in user.groups() { /// println!("{:?}", group.id()); /// } @@ -2714,7 +2714,7 @@ impl Group { /// /// let mut users = Users::new(); /// - /// for user in users.users() { + /// for user in users.list() { /// for group in user.groups() { /// println!("{}", group.name()); /// } @@ -2976,13 +2976,13 @@ impl std::ops::Deref for Components { type Target = [Component]; fn deref(&self) -> &Self::Target { - self.components() + self.list() } } impl std::ops::DerefMut for Components { fn deref_mut(&mut self) -> &mut Self::Target { - self.components_mut() + self.list_mut() } } @@ -2991,7 +2991,7 @@ impl<'a> IntoIterator for &'a Components { type IntoIter = std::slice::Iter<'a, Component>; fn into_iter(self) -> Self::IntoIter { - self.components().iter() + self.list().iter() } } @@ -3000,7 +3000,7 @@ impl<'a> IntoIterator for &'a mut Components { type IntoIter = std::slice::IterMut<'a, Component>; fn into_iter(self) -> Self::IntoIter { - self.components_mut().iter_mut() + self.list_mut().iter_mut() } } @@ -3029,12 +3029,12 @@ impl Components { /// /// let mut components = Components::new(); /// components.refresh_list(); - /// for component in components.components() { + /// for component in components.list() { /// eprintln!("{component:?}"); /// } /// ``` - pub fn components(&self) -> &[Component] { - self.inner.components() + pub fn list(&self) -> &[Component] { + self.inner.list() } /// Returns the components list. @@ -3044,13 +3044,13 @@ impl Components { /// /// let mut components = Components::new(); /// components.refresh_list(); - /// for component in components.components_mut() { + /// for component in components.list_mut() { /// component.refresh(); /// eprintln!("{component:?}"); /// } /// ``` - pub fn components_mut(&mut self) -> &mut [Component] { - self.inner.components_mut() + pub fn list_mut(&mut self) -> &mut [Component] { + self.inner.list_mut() } /// Refreshes the listed components' information. @@ -3071,7 +3071,7 @@ impl Components { /// components.refresh(); /// ``` pub fn refresh(&mut self) { - for component in self.components_mut() { + for component in self.list_mut() { component.refresh(); } } diff --git a/src/lib.rs b/src/lib.rs index 5cf209b04..9a87eee57 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -293,19 +293,19 @@ mod test { } #[test] - fn check_users() { + fn check_list() { let mut users = Users::new(); - assert!(users.users().is_empty()); + assert!(users.list().is_empty()); users.refresh_list(); - assert!(users.users().len() >= MIN_USERS); + assert!(users.list().len() >= MIN_USERS); } #[test] fn check_uid_gid() { let mut users = Users::new(); - assert!(users.users().is_empty()); + assert!(users.list().is_empty()); users.refresh_list(); - let user_list = users.users(); + let user_list = users.list(); assert!(user_list.len() >= MIN_USERS); if IS_SUPPORTED { diff --git a/src/unix/apple/app_store/component.rs b/src/unix/apple/app_store/component.rs index 5be927629..25320e17b 100644 --- a/src/unix/apple/app_store/component.rs +++ b/src/unix/apple/app_store/component.rs @@ -35,11 +35,11 @@ impl ComponentsInner { } } - pub(crate) fn components(&self) -> &[Component] { + pub(crate) fn list(&self) -> &[Component] { &self.components } - pub(crate) fn components_mut(&mut self) -> &mut [Component] { + pub(crate) fn list_mut(&mut self) -> &mut [Component] { &mut self.components } diff --git a/src/unix/apple/disk.rs b/src/unix/apple/disk.rs index 309d93517..2722a15b9 100644 --- a/src/unix/apple/disk.rs +++ b/src/unix/apple/disk.rs @@ -89,20 +89,20 @@ impl crate::DisksInner { pub(crate) fn refresh_list(&mut self) { unsafe { - get_disks(&mut self.disks); + get_list(&mut self.disks); } } - pub(crate) fn disks(&self) -> &[Disk] { + pub(crate) fn list(&self) -> &[Disk] { &self.disks } - pub(crate) fn disks_mut(&mut self) -> &mut [Disk] { + pub(crate) fn list_mut(&mut self) -> &mut [Disk] { &mut self.disks } } -unsafe fn get_disks(container: &mut Vec) { +unsafe fn get_list(container: &mut Vec) { container.clear(); let raw_disks = { diff --git a/src/unix/apple/macos/component/arm.rs b/src/unix/apple/macos/component/arm.rs index e6634b446..b34f8dce5 100644 --- a/src/unix/apple/macos/component/arm.rs +++ b/src/unix/apple/macos/component/arm.rs @@ -31,11 +31,11 @@ impl ComponentsInner { } } - pub(crate) fn components(&self) -> &[Component] { + pub(crate) fn list(&self) -> &[Component] { &self.components } - pub(crate) fn components_mut(&mut self) -> &mut [Component] { + pub(crate) fn list_mut(&mut self) -> &mut [Component] { &mut self.components } diff --git a/src/unix/apple/macos/component/x86.rs b/src/unix/apple/macos/component/x86.rs index a6dd97d63..c94763ceb 100644 --- a/src/unix/apple/macos/component/x86.rs +++ b/src/unix/apple/macos/component/x86.rs @@ -58,11 +58,11 @@ impl ComponentsInner { } } - pub(crate) fn components(&self) -> &[Component] { + pub(crate) fn list(&self) -> &[Component] { &self.components } - pub(crate) fn components_mut(&mut self) -> &mut [Component] { + pub(crate) fn list_mut(&mut self) -> &mut [Component] { &mut self.components } diff --git a/src/unix/freebsd/component.rs b/src/unix/freebsd/component.rs index fb4722c67..62e632321 100644 --- a/src/unix/freebsd/component.rs +++ b/src/unix/freebsd/component.rs @@ -63,11 +63,11 @@ impl ComponentsInner { } } - pub(crate) fn components(&self) -> &[Component] { + pub(crate) fn list(&self) -> &[Component] { &self.components } - pub(crate) fn components_mut(&mut self) -> &mut [Component] { + pub(crate) fn list_mut(&mut self) -> &mut [Component] { &mut self.components } diff --git a/src/unix/freebsd/disk.rs b/src/unix/freebsd/disk.rs index b570417f1..cacba4c74 100644 --- a/src/unix/freebsd/disk.rs +++ b/src/unix/freebsd/disk.rs @@ -62,14 +62,14 @@ impl crate::DisksInner { } pub(crate) fn refresh_list(&mut self) { - unsafe { get_all_disks(&mut self.disks) } + unsafe { get_all_list(&mut self.disks) } } - pub(crate) fn disks(&self) -> &[Disk] { + pub(crate) fn list(&self) -> &[Disk] { &self.disks } - pub(crate) fn disks_mut(&mut self) -> &mut [Disk] { + pub(crate) fn list_mut(&mut self) -> &mut [Disk] { &mut self.disks } } @@ -88,7 +88,7 @@ unsafe fn refresh_disk(disk: &mut DiskInner, vfs: &mut libc::statvfs) -> bool { true } -pub unsafe fn get_all_disks(container: &mut Vec) { +pub unsafe fn get_all_list(container: &mut Vec) { container.clear(); let mut fs_infos: *mut libc::statfs = std::ptr::null_mut(); diff --git a/src/unix/linux/component.rs b/src/unix/linux/component.rs index 91dca27a0..938ea59df 100644 --- a/src/unix/linux/component.rs +++ b/src/unix/linux/component.rs @@ -342,11 +342,11 @@ impl ComponentsInner { } } - pub(crate) fn components(&self) -> &[Component] { + pub(crate) fn list(&self) -> &[Component] { &self.components } - pub(crate) fn components_mut(&mut self) -> &mut [Component] { + pub(crate) fn list_mut(&mut self) -> &mut [Component] { &mut self.components } diff --git a/src/unix/linux/disk.rs b/src/unix/linux/disk.rs index 463245f88..f2f0f9ab0 100644 --- a/src/unix/linux/disk.rs +++ b/src/unix/linux/disk.rs @@ -78,17 +78,17 @@ impl crate::DisksInner { } pub(crate) fn refresh_list(&mut self) { - get_all_disks( + get_all_list( &mut self.disks, &get_all_data("/proc/mounts", 16_385).unwrap_or_default(), ) } - pub(crate) fn disks(&self) -> &[Disk] { + pub(crate) fn list(&self) -> &[Disk] { &self.disks } - pub(crate) fn disks_mut(&mut self) -> &mut [Disk] { + pub(crate) fn list_mut(&mut self) -> &mut [Disk] { &mut self.disks } } @@ -204,7 +204,7 @@ fn find_type_for_device_name(device_name: &OsStr) -> DiskKind { } } -fn get_all_disks(container: &mut Vec, content: &str) { +fn get_all_list(container: &mut Vec, content: &str) { container.clear(); // The goal of this array is to list all removable devices (the ones whose name starts with // "usb-"). @@ -283,7 +283,7 @@ fn get_all_disks(container: &mut Vec, content: &str) { } // #[test] -// fn check_all_disks() { +// fn check_all_list() { // let disks = get_all_disks_inner( // r#"tmpfs /proc tmpfs rw,seclabel,relatime 0 0 // proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0 diff --git a/src/unknown/component.rs b/src/unknown/component.rs index 5be927629..25320e17b 100644 --- a/src/unknown/component.rs +++ b/src/unknown/component.rs @@ -35,11 +35,11 @@ impl ComponentsInner { } } - pub(crate) fn components(&self) -> &[Component] { + pub(crate) fn list(&self) -> &[Component] { &self.components } - pub(crate) fn components_mut(&mut self) -> &mut [Component] { + pub(crate) fn list_mut(&mut self) -> &mut [Component] { &mut self.components } diff --git a/src/unknown/disk.rs b/src/unknown/disk.rs index 2015519bf..f4cec7c17 100644 --- a/src/unknown/disk.rs +++ b/src/unknown/disk.rs @@ -51,11 +51,11 @@ impl DisksInner { // Does nothing. } - pub(crate) fn disks(&self) -> &[Disk] { + pub(crate) fn list(&self) -> &[Disk] { &[] } - pub(crate) fn disks_mut(&mut self) -> &mut [Disk] { + pub(crate) fn list_mut(&mut self) -> &mut [Disk] { &mut [] } } diff --git a/src/windows/component.rs b/src/windows/component.rs index aa3297313..d1f392b36 100644 --- a/src/windows/component.rs +++ b/src/windows/component.rs @@ -96,11 +96,11 @@ impl ComponentsInner { } } - pub(crate) fn components(&self) -> &[Component] { + pub(crate) fn list(&self) -> &[Component] { &self.components } - pub(crate) fn components_mut(&mut self) -> &mut [Component] { + pub(crate) fn list_mut(&mut self) -> &mut [Component] { &mut self.components } diff --git a/src/windows/disk.rs b/src/windows/disk.rs index 697b2b6fc..e7e5b18a5 100644 --- a/src/windows/disk.rs +++ b/src/windows/disk.rs @@ -87,15 +87,15 @@ impl DisksInner { pub(crate) fn refresh_list(&mut self) { unsafe { - self.disks = get_disks(); + self.disks = get_list(); } } - pub(crate) fn disks(&self) -> &[Disk] { + pub(crate) fn list(&self) -> &[Disk] { &self.disks } - pub(crate) fn disks_mut(&mut self) -> &mut [Disk] { + pub(crate) fn list_mut(&mut self) -> &mut [Disk] { &mut self.disks } } @@ -143,7 +143,7 @@ unsafe fn get_drive_size(mount_point: &[u16]) -> Option<(u64, u64)> { } } -pub(crate) unsafe fn get_disks() -> Vec { +pub(crate) unsafe fn get_list() -> Vec { let drives = GetLogicalDrives(); if drives == 0 { return Vec::new(); diff --git a/tests/disk_list.rs b/tests/disk_list.rs index bae256e8a..6a98f4f23 100644 --- a/tests/disk_list.rs +++ b/tests/disk_list.rs @@ -8,7 +8,7 @@ fn test_disks() { if s.physical_core_count().unwrap_or_default() > 0 { let mut disks = sysinfo::Disks::new(); disks.refresh_list(); - assert!(!disks.disks().is_empty()); + assert!(!disks.list().is_empty()); } } }