@@ -19,7 +19,7 @@ use core::fmt::Debug;
1919use embedded_io:: ErrorKind ;
2020use filesystem:: Handle ;
2121
22- use super :: { bisync, only_sync} ;
22+ use super :: { bisync, only_sync, only_async } ;
2323
2424#[ doc( inline) ]
2525pub use blockdevice:: { Block , BlockCache , BlockCount , BlockDevice , BlockIdx } ;
@@ -210,8 +210,10 @@ impl RawVolume {
210210/// any error that may occur will be ignored. To handle potential errors, use
211211/// the [`Volume::close`] method.
212212///
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.
215217pub struct Volume < ' a , D , T , const MAX_DIRS : usize , const MAX_FILES : usize , const MAX_VOLUMES : usize >
216218where
217219 D : BlockDevice ,
@@ -268,7 +270,6 @@ where
268270 }
269271}
270272
271- // async drop does not yet exist :(
272273#[ only_sync]
273274impl < ' a , D , T , const MAX_DIRS : usize , const MAX_FILES : usize , const MAX_VOLUMES : usize > Drop
274275 for Volume < ' a , D , T , MAX_DIRS , MAX_FILES , MAX_VOLUMES >
@@ -281,6 +282,18 @@ where
281282 }
282283}
283284
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+
284297impl < ' a , D , T , const MAX_DIRS : usize , const MAX_FILES : usize , const MAX_VOLUMES : usize >
285298 core:: fmt:: Debug for Volume < ' a , D , T , MAX_DIRS , MAX_FILES , MAX_VOLUMES >
286299where
0 commit comments