@@ -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,10 @@ 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 rely on the async executor you are already using, call [`Volume::close`]
216
+ /// manually instead of letting the `Volume` drop.
215
217
pub struct Volume < ' a , D , T , const MAX_DIRS : usize , const MAX_FILES : usize , const MAX_VOLUMES : usize >
216
218
where
217
219
D : BlockDevice ,
@@ -268,7 +270,6 @@ where
268
270
}
269
271
}
270
272
271
- // async drop does not yet exist :(
272
273
#[ only_sync]
273
274
impl < ' a , D , T , const MAX_DIRS : usize , const MAX_FILES : usize , const MAX_VOLUMES : usize > Drop
274
275
for Volume < ' a , D , T , MAX_DIRS , MAX_FILES , MAX_VOLUMES >
@@ -281,6 +282,18 @@ where
281
282
}
282
283
}
283
284
285
+ #[ only_async]
286
+ impl < ' a , D , T , const MAX_DIRS : usize , const MAX_FILES : usize , const MAX_VOLUMES : usize > Drop
287
+ for Volume < ' a , D , T , MAX_DIRS , MAX_FILES , MAX_VOLUMES >
288
+ where
289
+ D : BlockDevice ,
290
+ T : TimeSource ,
291
+ {
292
+ fn drop ( & mut self ) {
293
+ _ = embassy_futures:: block_on ( self . volume_mgr . close_volume ( self . raw_volume ) ) ;
294
+ }
295
+ }
296
+
284
297
impl < ' a , D , T , const MAX_DIRS : usize , const MAX_FILES : usize , const MAX_VOLUMES : usize >
285
298
core:: fmt:: Debug for Volume < ' a , D , T , MAX_DIRS , MAX_FILES , MAX_VOLUMES >
286
299
where
0 commit comments