@@ -19,7 +19,7 @@ use core::fmt::Debug;
19
19
use embedded_io:: ErrorKind ;
20
20
use filesystem:: Handle ;
21
21
22
- use super :: { bisync, only_sync} ;
22
+ use super :: { bisync, only_sync, only_async } ;
23
23
24
24
#[ doc( inline) ]
25
25
pub use blockdevice:: { Block , BlockCache , BlockCount , BlockDevice , BlockIdx } ;
@@ -210,8 +210,11 @@ impl RawVolume {
210
210
/// any error that may occur will be ignored. To handle potential errors, use
211
211
/// the [`Volume::close`] method.
212
212
///
213
- /// For async Volumes, async drop does not exist in Rust, so you *must* call
214
- /// [`Volume::close`] when you are done with a Volume.
213
+ /// For async Volumes, the implementation of [`Drop`] blocks with [`embassy_futures::block_on`]
214
+ /// because there is no way to `.await` inside [`Drop::drop`]. If you would prefer
215
+ /// to call [`File::close`] manually instead and rely on the async executor you are already
216
+ /// using, you can do that by disabling the `async-drop` Cargo feature, which is enabled by
217
+ /// default.
215
218
pub struct Volume < ' a , D , T , const MAX_DIRS : usize , const MAX_FILES : usize , const MAX_VOLUMES : usize >
216
219
where
217
220
D : BlockDevice ,
@@ -268,7 +271,6 @@ where
268
271
}
269
272
}
270
273
271
- // async drop does not yet exist :(
272
274
#[ only_sync]
273
275
impl < ' a , D , T , const MAX_DIRS : usize , const MAX_FILES : usize , const MAX_VOLUMES : usize > Drop
274
276
for Volume < ' a , D , T , MAX_DIRS , MAX_FILES , MAX_VOLUMES >
@@ -281,6 +283,19 @@ where
281
283
}
282
284
}
283
285
286
+ #[ cfg( feature = "async-drop" ) ]
287
+ #[ only_async]
288
+ impl < ' a , D , T , const MAX_DIRS : usize , const MAX_FILES : usize , const MAX_VOLUMES : usize > Drop
289
+ for Volume < ' a , D , T , MAX_DIRS , MAX_FILES , MAX_VOLUMES >
290
+ where
291
+ D : BlockDevice ,
292
+ T : TimeSource ,
293
+ {
294
+ fn drop ( & mut self ) {
295
+ _ = embassy_futures:: block_on ( self . volume_mgr . close_volume ( self . raw_volume ) ) ;
296
+ }
297
+ }
298
+
284
299
impl < ' a , D , T , const MAX_DIRS : usize , const MAX_FILES : usize , const MAX_VOLUMES : usize >
285
300
core:: fmt:: Debug for Volume < ' a , D , T , MAX_DIRS , MAX_FILES , MAX_VOLUMES >
286
301
where
0 commit comments