//! A handle is a u128 with a set of permissions //! and a resource connected to it use crate::Path; use crate::{arch::generate_process_pass, channels::Channel}; use core::fmt::Display; #[derive(Debug)] pub struct BinaryData { name: String, data: Vec, } #[derive(Debug)] pub enum HandleResource { Channel(Channel), // Device BinaryData(BinaryData), } #[derive(Debug)] pub struct Handle { inner: u128, res: HandleResource, } impl Display for Handle { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { write!(f, "Handle-{:032x}", self.inner)?; match &self.res { HandleResource::Channel(_) => write!(f, "-Channel")?, HandleResource::BinaryData(data) => write!(f, "-Binary-{}", &data.name)?, } Ok(()) } } use crate::handle::HandleResource::*; impl Handle { pub fn from_channel(channel: Channel) -> Self { Self { inner: generate_process_pass(), res: Channel(channel), } } }