foyer_storage/io/engine/
noop.rs1use std::sync::Arc;
16
17use foyer_common::error::Result;
18use futures_core::future::BoxFuture;
19use futures_util::FutureExt;
20
21use crate::io::{
22 bytes::{IoB, IoBuf, IoBufMut},
23 device::Partition,
24 engine::{IoEngine, IoEngineBuildContext, IoEngineConfig, IoHandle},
25};
26#[derive(Debug, Default)]
28pub struct NoopIoEngineConfig;
29
30impl IoEngineConfig for NoopIoEngineConfig {
31 fn build(self: Box<Self>, _: IoEngineBuildContext) -> BoxFuture<'static, Result<Arc<dyn IoEngine>>> {
32 async move { Ok(Arc::new(NoopIoEngine) as Arc<dyn IoEngine>) }.boxed()
33 }
34}
35
36#[derive(Debug)]
38pub struct NoopIoEngine;
39
40impl IoEngine for NoopIoEngine {
41 fn read(&self, buf: Box<dyn IoBufMut>, _: &dyn Partition, _: u64) -> IoHandle {
42 async move {
43 let buf: Box<dyn IoB> = buf.into_iob();
44 (buf, Ok(()))
45 }
46 .boxed()
47 .into()
48 }
49
50 fn write(&self, buf: Box<dyn IoBuf>, _: &dyn Partition, _: u64) -> super::IoHandle {
51 async move {
52 let buf: Box<dyn IoB> = buf.into_iob();
53 (buf, Ok(()))
54 }
55 .boxed()
56 .into()
57 }
58}