use crate::ModeParser;
use std::cell::RefCell;
use std::fmt::{Display, Formatter};
use OwnersKind::*;
#[derive(Debug, Eq, PartialEq)]
pub enum OwnersKind {
User(RefCell<ModeParser>),
Group(RefCell<ModeParser>),
Other(RefCell<ModeParser>),
}
impl OwnersKind {
fn get_mode_parser(&self) -> &RefCell<ModeParser> {
match self {
User(user) => user,
Group(group) => group,
Other(other) => other,
}
}
pub fn get_read(&self) -> char {
self.get_mode_parser().borrow().get_read()
}
pub fn get_write(&mut self) -> char {
self.get_mode_parser().borrow().get_write()
}
pub fn get_execute(&mut self) -> char {
self.get_mode_parser().borrow().get_execute()
}
pub fn set_read(&self, read: char) {
self.get_mode_parser().borrow_mut().set_read(read)
}
pub fn set_write(&self, write: char) {
self.get_mode_parser().borrow_mut().set_write(write)
}
pub fn set_execute(&self, execute: char) {
self.get_mode_parser().borrow_mut().set_execute(execute)
}
pub fn get_partial_mode(&self) -> u32 {
self.get_mode_parser().borrow().get_partial_mode()
}
}
impl Display for OwnersKind {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(
f,
"{}",
match self {
User(user) => user,
Group(group) => group,
Other(other) => other,
}
.borrow()
)
}
}