Skip to content

Commit

Permalink
Merge branch 'master' of github.com:njouanin/sysinfo
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas committed Nov 5, 2023
2 parents 78ee171 + acde12b commit cf03115
Show file tree
Hide file tree
Showing 11 changed files with 137 additions and 4 deletions.
40 changes: 40 additions & 0 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2051,6 +2051,20 @@ impl Default for Disks {
}
}

impl From<Disks> for Vec<Disk> {
fn from(disks: Disks) -> Vec<Disk> {
disks.inner.into_vec()
}
}

impl From<Vec<Disk>> for Disks {
fn from(disks: Vec<Disk>) -> Self {
Self {
inner: crate::DisksInner::from_vec(disks),
}
}
}

impl<'a> IntoIterator for &'a Disks {
type Item = &'a Disk;
type IntoIter = std::slice::Iter<'a, Disk>;
Expand Down Expand Up @@ -2245,6 +2259,18 @@ impl Default for Users {
}
}

impl From<Users> for Vec<User> {
fn from(users: Users) -> Self {
users.users
}
}

impl From<Vec<User>> for Users {
fn from(users: Vec<User>) -> Self {
Self { users }
}
}

impl std::ops::Deref for Users {
type Target = [User];

Expand Down Expand Up @@ -3043,6 +3069,20 @@ impl Default for Components {
}
}

impl From<Components> for Vec<Component> {
fn from(components: Components) -> Self {
components.inner.into_vec()
}
}

impl From<Vec<Component>> for Components {
fn from(components: Vec<Component>) -> Self {
Self {
inner: ComponentsInner::from_vec(components),
}
}
}

impl std::ops::Deref for Components {
type Target = [Component];

Expand Down
8 changes: 8 additions & 0 deletions src/unix/apple/app_store/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ impl ComponentsInner {
}
}

pub(crate) fn from_vec(components: Vec<Component>) -> Self {
Self { components }
}

pub(crate) fn into_vec(self) -> Vec<Component> {
self.components
}

pub(crate) fn list(&self) -> &[Component] {
&self.components
}
Expand Down
11 changes: 11 additions & 0 deletions src/unix/apple/macos/component/arm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ impl ComponentsInner {
}
}

pub(crate) fn from_vec(components: Vec<Component>) -> Self {
Self {
components,
client: None,
}
}

pub(crate) fn into_vec(self) -> Vec<Component> {
self.components
}

pub(crate) fn list(&self) -> &[Component] {
&self.components
}
Expand Down
11 changes: 11 additions & 0 deletions src/unix/apple/macos/component/x86.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@ impl ComponentsInner {
}
}

pub(crate) fn from_vec(components: Vec<Component>) -> Self {
Self {
components,
connection: IoService::new_connection(),
}
}

pub(crate) fn into_vec(self) -> Vec<Component> {
self.components
}

pub(crate) fn list(&self) -> &[Component] {
&self.components
}
Expand Down
11 changes: 11 additions & 0 deletions src/unix/freebsd/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,17 @@ impl ComponentsInner {
}
}

pub(crate) fn from_vec(components: Vec<Component>) -> Self {
Self {
nb_cpus: unsafe { super::cpu::get_nb_cpus() },
components,
}
}

pub(crate) fn into_vec(self) -> Vec<Component> {
self.components
}

pub(crate) fn list(&self) -> &[Component] {
&self.components
}
Expand Down
8 changes: 8 additions & 0 deletions src/unix/linux/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,14 @@ impl ComponentsInner {
}
}

pub(crate) fn from_vec(components: Vec<Component>) -> Self {
Self { components }
}

pub(crate) fn into_vec(self) -> Vec<Component> {
self.components
}

pub(crate) fn list(&self) -> &[Component] {
&self.components
}
Expand Down
10 changes: 10 additions & 0 deletions src/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,13 @@ pub(crate) mod utils;
pub(crate) struct DisksInner {
pub(crate) disks: Vec<crate::Disk>,
}

impl DisksInner {
pub(crate) fn from_vec(disks: Vec<crate::Disk>) -> Self {
Self { disks }
}

pub(crate) fn into_vec(self) -> Vec<crate::Disk> {
self.disks
}
}
8 changes: 8 additions & 0 deletions src/unknown/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ impl ComponentsInner {
}
}

pub(crate) fn from_vec(components: Vec<Component>) -> Self {
Self { components }
}

pub(crate) fn into_vec(self) -> Vec<Component> {
self.components
}

pub(crate) fn list(&self) -> &[Component] {
&self.components
}
Expand Down
18 changes: 14 additions & 4 deletions src/unknown/disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,32 @@ impl DiskInner {
}
}

pub(crate) struct DisksInner;
pub(crate) struct DisksInner {
pub(crate) disks: Vec<Disk>,
}

impl DisksInner {
pub(crate) fn new() -> Self {
Self
Self { disks: Vec::new() }
}

pub(crate) fn from_vec(disks: Vec<Disk>) -> Self {
Self { disks }
}

pub(crate) fn into_vec(self) -> Vec<Disk> {
self.disks
}

pub(crate) fn refresh_list(&mut self) {
// Does nothing.
}

pub(crate) fn list(&self) -> &[Disk] {
&[]
&self.disks
}

pub(crate) fn list_mut(&mut self) -> &mut [Disk] {
&mut []
&mut self.disks
}
}
8 changes: 8 additions & 0 deletions src/windows/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ impl ComponentsInner {
}
}

pub(crate) fn from_vec(components: Vec<Component>) -> Self {
Self { components }
}

pub(crate) fn into_vec(self) -> Vec<Component> {
self.components
}

pub(crate) fn list(&self) -> &[Component] {
&self.components
}
Expand Down
8 changes: 8 additions & 0 deletions src/windows/disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,14 @@ impl DisksInner {
}
}

pub(crate) fn from_vec(disks: Vec<Disk>) -> Self {
Self { disks }
}

pub(crate) fn into_vec(self) -> Vec<Disk> {
self.disks
}

pub(crate) fn refresh_list(&mut self) {
unsafe {
self.disks = get_list();
Expand Down

0 comments on commit cf03115

Please sign in to comment.