use std::cmp::Ordering;
use crate::{Gid, Uid, UserInner};
use super::Group;
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 {
pub fn id(&self) -> &Uid {
self.inner.id()
}
pub fn group_id(&self) -> Option<Gid> {
self.inner.group_id()
}
pub fn name(&self) -> &str {
self.inner.name()
}
pub fn groups(&self) -> Vec<Group> {
self.inner.groups()
}
}