use { crate::arch::hardware_random_u64, alloc::vec::Vec, core::fmt::{self, Formatter}, }; #[derive(Debug, Eq, Hash, PartialEq, Clone, Copy)] pub struct OSHandle { pub id: u64, } impl OSHandle { pub fn new_from_u64(id: u64) -> Self { Self { id } } pub fn random_new() -> Self { Self { id: hardware_random_u64(), } } } #[derive(Debug, Eq, Hash, PartialEq, Clone, Copy)] pub struct Handle { id: OSHandle, perms: Permissions, } impl Handle { pub fn new() -> Handle { Handle { id: OSHandle::random_new(), perms: Permissions::new(), } } pub fn as_u64(&self) -> u64 { self.id.id } } impl fmt::Display for Handle { fn fmt(&self, w: &mut Formatter<'_>) -> Result<(), core::fmt::Error> { write!(w, "{:?}", self.id); Ok(()) } } #[derive(PartialEq, Hash, Eq, Debug, Clone, Copy)] pub struct Permissions { edit_children: bool, edit_attributes: bool, } impl Permissions { pub fn new() -> Self { Self { edit_children: true, edit_attributes: true, } } }