irid-std 0.3.0

A replacement for std when running without a filesystem on the irid kernel
Documentation
use irid_syscall::io::{FileDescriptor, OpenFlags, close, open};

use crate::{io, path::Path};

#[derive(Debug)]
pub struct NotifyFile {
    desc: FileDescriptor
}

impl NotifyFile {
    pub fn open_read(path: impl AsRef<Path>) -> Result<Self, io::Error> {
        Ok(NotifyFile { 
            desc: open(path.as_ref().as_str(), OpenFlags::READ | OpenFlags::CHANNEL | OpenFlags::MULTI_CONSUMER | OpenFlags::DATALESS | OpenFlags::CREATE)?
        })
    }
    
    pub fn open(path: impl AsRef<Path>) -> Result<Self, io::Error> {
        Ok(NotifyFile { 
            desc: open(path.as_ref().as_str(), OpenFlags::READ | OpenFlags::WRITE | OpenFlags::CHANNEL | OpenFlags::MULTI_CONSUMER | OpenFlags::DATALESS | OpenFlags::CREATE)?
        })
    }

    pub fn wait(&self) -> Result<(), io::Error> {
        irid_syscall::io::read(self.desc, &mut [0])?;

        Ok(())
    }
    
    pub fn notify(&self) -> Result<(), io::Error> {
        irid_syscall::io::write(self.desc, &[1])?;

        Ok(())
    }
}

impl Drop for NotifyFile {
    fn drop(&mut self) {
        close(self.desc).expect("failed to close notify file")
    }
}