Skip to content

Commit 94970b0

Browse files
Option<I>
1 parent 7b26b13 commit 94970b0

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

core/src/layers/blocking.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -267,32 +267,35 @@ impl<A: Access> LayeredAccess for BlockingAccessor<A> {
267267

268268
pub struct BlockingWrapper<I> {
269269
handle: Handle,
270-
inner: I,
270+
inner: Option<I>,
271271
}
272272

273273
impl<I> BlockingWrapper<I> {
274274
fn new(handle: Handle, inner: I) -> Self {
275-
Self { handle, inner }
275+
Self {
276+
handle,
277+
inner: Some(inner),
278+
}
276279
}
277280
}
278281

279282
impl<I: oio::Read + 'static> oio::BlockingRead for BlockingWrapper<I> {
280283
fn read(&mut self) -> Result<Buffer> {
281-
self.handle.block_on(self.inner.read())
284+
self.handle.block_on(self.inner.as_mut().unwrap().read())
282285
}
283286
}
284287

285288
impl<I: oio::Write + 'static> oio::BlockingWrite for BlockingWrapper<I> {
286289
fn write(&mut self, bs: Buffer) -> Result<()> {
287-
self.handle.block_on(self.inner.write(bs))
290+
self.handle.block_on(self.inner.as_mut().unwrap().write(bs))
288291
}
289292

290293
fn close(&mut self) -> Result<Metadata> {
291-
self.handle.block_on(self.inner.close())
294+
self.handle.block_on(self.inner.as_mut().unwrap().close())
292295
}
293296
}
294297

295-
impl<I> Drop for BlockingWrapper<I> {
298+
impl<I: Send + 'static> Drop for BlockingWrapper<I> {
296299
fn drop(&mut self) {
297300
if let Some(inner) = self.inner.take() {
298301
self.handle.spawn(async move {
@@ -304,17 +307,17 @@ impl<I> Drop for BlockingWrapper<I> {
304307

305308
impl<I: oio::List> oio::BlockingList for BlockingWrapper<I> {
306309
fn next(&mut self) -> Result<Option<oio::Entry>> {
307-
self.handle.block_on(self.inner.next())
310+
self.handle.block_on(self.inner.as_mut().unwrap().next())
308311
}
309312
}
310313

311314
impl<I: oio::Delete + 'static> oio::BlockingDelete for BlockingWrapper<I> {
312315
fn delete(&mut self, path: &str, args: OpDelete) -> Result<()> {
313-
self.inner.delete(path, args)
316+
self.inner.as_mut().unwrap().delete(path, args)
314317
}
315318

316319
fn flush(&mut self) -> Result<usize> {
317-
self.handle.block_on(self.inner.flush())
320+
self.handle.block_on(self.inner.as_mut().unwrap().flush())
318321
}
319322
}
320323

0 commit comments

Comments
 (0)