#![allow(unused_imports)]
use crate::prelude::*;
use alloc::{boxed::Box, vec, vec::Vec};
#[cfg(feature = "net")]
pub type AxNetDevice = Box<dyn NetDriverOps>;
#[cfg(feature = "block")]
pub type AxBlockDevice = Box<dyn BlockDriverOps>;
#[cfg(feature = "display")]
pub type AxDisplayDevice = Box<dyn DisplayDriverOps>;
impl super::AxDeviceEnum {
#[cfg(feature = "net")]
pub fn from_net(dev: impl NetDriverOps + 'static) -> Self {
Self::Net(Box::new(dev))
}
#[cfg(feature = "block")]
pub fn from_block(dev: impl BlockDriverOps + 'static) -> Self {
Self::Block(Box::new(dev))
}
#[cfg(feature = "display")]
pub fn from_display(dev: impl DisplayDriverOps + 'static) -> Self {
Self::Display(Box::new(dev))
}
}
pub struct AxDeviceContainer<D>(Vec<D>);
impl<D> AxDeviceContainer<D> {
pub fn len(&self) -> usize {
self.0.len()
}
pub fn is_empty(&self) -> bool {
self.len() == 0
}
pub fn take_one(&mut self) -> Option<D> {
if self.is_empty() {
None
} else {
Some(self.0.remove(0))
}
}
pub fn from_one(dev: D) -> Self {
Self(vec![dev])
}
#[allow(dead_code)]
pub(crate) fn push(&mut self, dev: D) {
self.0.push(dev);
}
}
impl<D> core::ops::Deref for AxDeviceContainer<D> {
type Target = Vec<D>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl<D> Default for AxDeviceContainer<D> {
fn default() -> Self {
Self(Default::default())
}
}