1
0
Fork 0
forked from AbleOS/ableos
ableOS_v1Change/ableos/src/channels.rs
TheOddGarlic 34a701bd5c unused import: git::commit_message
`#[warn(unused_imports)]` on by default
2022-08-01 14:09:05 +03:00

41 lines
794 B
Rust

use alloc::collections::VecDeque;
#[derive(Debug)]
pub struct ChannelPermission {
pub owner: bool,
pub producer: bool,
pub consumer: bool,
/// Whether or not the process can be destructive about reading
pub distructive_consumer: bool,
}
#[derive(Debug)]
pub struct Channel {
inner: VecDeque<u8>,
}
impl Channel {
pub fn new() -> Self {
let deq = VecDeque::from([]);
Self { inner: deq }
}
pub fn read(&mut self) -> Result<u8, ChannelError> {
if let Some(abc) = self.inner.pop_front() {
return Ok(abc);
}
return Err(ChannelError::EmptyBuffer);
}
pub fn send(&mut self, data: u8) {
self.inner.push_back(data);
}
}
pub enum ChannelError {
EmptyBuffer,
InvalidPermissions,
}