Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core/types): change oio::BlockingReader to Arc<dyn oio::BlockingReader> #4577

Merged
merged 1 commit into from
May 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/src/layers/type_eraser.rs
Original file line number Diff line number Diff line change
@@ -88,7 +88,7 @@ impl<A: Access> LayeredAccess for TypeEraseAccessor<A> {
fn blocking_read(&self, path: &str, args: OpRead) -> Result<(RpRead, Self::BlockingReader)> {
self.inner
.blocking_read(path, args)
.map(|(rp, r)| (rp, Box::new(r) as oio::BlockingReader))
.map(|(rp, r)| (rp, Arc::new(r) as oio::BlockingReader))
}

fn blocking_write(&self, path: &str, args: OpWrite) -> Result<(RpWrite, Self::BlockingWriter)> {
8 changes: 4 additions & 4 deletions core/src/raw/oio/read/api.rs
Original file line number Diff line number Diff line change
@@ -155,8 +155,8 @@ impl<T: ReadDyn + ?Sized> Read for Arc<T> {
}
}

/// BlockingReader is a boxed dyn `BlockingRead`.
pub type BlockingReader = Box<dyn BlockingRead>;
/// BlockingReader is a arc dyn `BlockingRead`.
pub type BlockingReader = Arc<dyn BlockingRead>;

/// Read is the trait that OpenDAL returns to callers.
pub trait BlockingRead: Send + Sync {
@@ -199,9 +199,9 @@ impl BlockingRead for Buffer {
}
}

/// `Box<dyn BlockingRead>` won't implement `BlockingRead` automatically.
/// `Arc<dyn BlockingRead>` won't implement `BlockingRead` automatically.
/// To make BlockingReader work as expected, we must add this impl.
impl<T: BlockingRead + ?Sized> BlockingRead for Box<T> {
impl<T: BlockingRead + ?Sized> BlockingRead for Arc<T> {
fn read_at(&self, offset: u64, limit: usize) -> Result<Buffer> {
(**self).read_at(offset, limit)
}
1 change: 0 additions & 1 deletion core/src/types/blocking_read/blocking_reader.rs
Original file line number Diff line number Diff line change
@@ -22,7 +22,6 @@ use std::ops::RangeBounds;
use bytes::Buf;
use bytes::BufMut;

use crate::raw::oio::BlockingRead;
use crate::raw::*;
use crate::*;