Skip to content

Commit

Permalink
feat(core/types): change oio::BlockingReader to Arc<dyn oio::Blocking…
Browse files Browse the repository at this point in the history
…Read>
  • Loading branch information
hoslo committed May 7, 2024
1 parent 63e061a commit ad0eed2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
6 changes: 3 additions & 3 deletions core/src/types/blocking_read/blocking_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@
use std::collections::Bound;
use std::ops::Range;
use std::ops::RangeBounds;
use std::sync::Arc;

use bytes::Buf;
use bytes::BufMut;

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

/// BlockingReader is designed to read data from given path in an blocking
/// manner.
pub struct BlockingReader {
pub(crate) inner: oio::BlockingReader,
pub(crate) inner: Arc<dyn oio::BlockingRead>,
}

impl BlockingReader {
Expand All @@ -43,7 +43,7 @@ impl BlockingReader {
pub(crate) fn create(acc: Accessor, path: &str, op: OpRead) -> crate::Result<Self> {
let (_, r) = acc.blocking_read(path, op)?;

Ok(BlockingReader { inner: r })
Ok(BlockingReader { inner: Arc::new(r) })
}

/// Read give range from reader into [`Buffer`].
Expand Down
5 changes: 3 additions & 2 deletions core/src/types/blocking_read/std_bytes_iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// under the License.

use std::io;
use std::sync::Arc;

use bytes::Buf;
use bytes::Bytes;
Expand All @@ -28,7 +29,7 @@ use crate::raw::*;
///
/// StdIterator also implements [`Send`] and [`Sync`].
pub struct StdBytesIterator {
inner: oio::BlockingReader,
inner: Arc<dyn oio::BlockingRead>,
offset: u64,
size: u64,
cap: usize,
Expand All @@ -39,7 +40,7 @@ pub struct StdBytesIterator {
impl StdBytesIterator {
/// NOTE: don't allow users to create StdIterator directly.
#[inline]
pub(crate) fn new(r: oio::BlockingReader, range: std::ops::Range<u64>) -> Self {
pub(crate) fn new(r: Arc<dyn oio::BlockingRead>, range: std::ops::Range<u64>) -> Self {
StdBytesIterator {
inner: r,
offset: range.start,
Expand Down
5 changes: 3 additions & 2 deletions core/src/types/blocking_read/std_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use std::io::Read;
use std::io::Seek;
use std::io::SeekFrom;
use std::ops::Range;
use std::sync::Arc;

use bytes::Buf;

Expand All @@ -33,7 +34,7 @@ use crate::*;
///
/// StdReader also implements [`Send`] and [`Sync`].
pub struct StdReader {
inner: oio::BlockingReader,
inner: Arc<dyn oio::BlockingRead>,
offset: u64,
size: u64,
cap: usize,
Expand All @@ -45,7 +46,7 @@ pub struct StdReader {
impl StdReader {
/// NOTE: don't allow users to create StdReader directly.
#[inline]
pub(super) fn new(r: oio::BlockingReader, range: Range<u64>) -> Self {
pub(super) fn new(r: Arc<dyn oio::BlockingRead>, range: Range<u64>) -> Self {
StdReader {
inner: r,
offset: range.start,
Expand Down

0 comments on commit ad0eed2

Please sign in to comment.