use std::sync::Arc;
use foyer_common::error::Result;
use futures_core::future::BoxFuture;
use futures_util::FutureExt;
use crate::io::{
bytes::{IoB, IoBuf, IoBufMut},
device::Partition,
engine::{IoEngine, IoEngineBuildContext, IoEngineConfig, IoHandle},
};
#[derive(Debug, Default)]
pub struct NoopIoEngineConfig;
impl IoEngineConfig for NoopIoEngineConfig {
fn build(self: Box<Self>, _: IoEngineBuildContext) -> BoxFuture<'static, Result<Arc<dyn IoEngine>>> {
async move { Ok(Arc::new(NoopIoEngine) as Arc<dyn IoEngine>) }.boxed()
}
}
#[derive(Debug)]
pub struct NoopIoEngine;
impl IoEngine for NoopIoEngine {
fn read(&self, buf: Box<dyn IoBufMut>, _: &dyn Partition, _: u64) -> IoHandle {
async move {
let buf: Box<dyn IoB> = buf.into_iob();
(buf, Ok(()))
}
.boxed()
.into()
}
fn write(&self, buf: Box<dyn IoBuf>, _: &dyn Partition, _: u64) -> super::IoHandle {
async move {
let buf: Box<dyn IoB> = buf.into_iob();
(buf, Ok(()))
}
.boxed()
.into()
}
}