irid-std 0.3.1

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::{self, convert_error}, 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)
                .map_err(convert_error)?
        })
    }
    
    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)
                .map_err(convert_error)?
        })
    }

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

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

        Ok(())
    }
}

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