#![no_std]
extern crate alloc;
use alloc::boxed::Box;
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub enum DeviceType {
Block,
Char,
Net,
Display,
Input,
Vsock,
}
#[derive(Debug)]
pub enum DevError {
AlreadyExists,
Again,
BadState,
InvalidParam,
Io,
NoMemory,
ResourceBusy,
Unsupported,
}
impl core::fmt::Display for DevError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
DevError::AlreadyExists => write!(f, "Entity already exists"),
DevError::Again => write!(f, "Try again"),
DevError::BadState => write!(f, "Bad state"),
DevError::InvalidParam => write!(f, "Invalid parameter"),
DevError::Io => write!(f, "Input/output error"),
DevError::NoMemory => write!(f, "Not enough memory"),
DevError::ResourceBusy => write!(f, "Resource is busy"),
DevError::Unsupported => write!(f, "Unsupported operation"),
}
}
}
pub type DevResult<T = ()> = Result<T, DevError>;
pub trait BaseDriverOps: Send + Sync {
fn device_name(&self) -> &str;
fn device_type(&self) -> DeviceType;
fn irq_num(&self) -> Option<usize> {
None
}
}
impl<T: BaseDriverOps + ?Sized> BaseDriverOps for Box<T> {
fn device_name(&self) -> &str {
(**self).device_name()
}
fn device_type(&self) -> DeviceType {
(**self).device_type()
}
fn irq_num(&self) -> Option<usize> {
(**self).irq_num()
}
}