akern-gkgoat-fork/kernel/src/handle.rs

47 lines
932 B
Rust
Raw Normal View History

2023-04-07 16:44:33 -05:00
use core::fmt::{self, Formatter};
use crate::arch::hardware_random_u64;
#[derive(Debug, Eq, Hash, PartialEq)]
pub struct Handle {
pub handle_data: i64,
perms: Permissions,
}
impl Handle {
pub fn new() -> Handle {
Handle {
handle_data: hardware_random_u64() as i64,
perms: Permissions::new(),
}
}
}
impl fmt::Display for Handle {
fn fmt(&self, w: &mut Formatter<'_>) -> Result<(), core::fmt::Error> {
write!(w, "{}", self.handle_data);
Ok(())
}
}
impl Into<i64> for Handle {
fn into(self) -> i64 {
self.handle_data
// (abc[0..3] as i64, abc[4..8] as i64)
}
}
#[derive(PartialEq, Hash, Eq, Debug)]
pub struct Permissions {
edit_children: bool,
edit_attributes: bool,
}
impl Permissions {
pub fn new() -> Self {
Self {
edit_children: true,
edit_attributes: true,
}
}
}