sinf 0.1.0

Library for obtaining in-depth system information at both the hardware and software levels
Documentation
use std::cmp::Ordering;

use crate::{Gid, Uid, UserInner};

use super::Group;

/// Information about a user.
pub struct User {
    pub(crate) inner: UserInner,
}

impl PartialEq for User {
    fn eq(&self, other: &Self) -> bool {
        self.name() == other.name()
            && self.id() == other.id()
            && self.group_id() == other.group_id()
    }
}

impl Eq for User {}

impl PartialOrd for User {
    fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
        Some(self.cmp(other))
    }
}

impl Ord for User {
    fn cmp(&self, other: &Self) -> Ordering {
        self.name()
            .cmp(other.name())
            .then_with(|| self.id().cmp(other.id()))
            .then_with(|| self.group_id().cmp(&other.group_id()))
    }
}

impl User {
    /// Returns the user ID.
    pub fn id(&self) -> &Uid {
        self.inner.id()
    }

    /// Returns the primary group ID of the user, or `None` when it is unavailable.
    ///
    /// On Windows this is a security identifier (SID) when it can be resolved;
    /// use [`User::groups`] to list all groups the user belongs to.
    pub fn group_id(&self) -> Option<Gid> {
        self.inner.group_id()
    }

    /// Returns the user name.
    pub fn name(&self) -> &str {
        self.inner.name()
    }

    /// Returns the groups the user belongs to.
    pub fn groups(&self) -> Vec<Group> {
        self.inner.groups()
    }
}