@@ -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,11 @@ 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 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.
215218pub struct Volume < ' a , D , T , const MAX_DIRS : usize , const MAX_FILES : usize , const MAX_VOLUMES : usize >
216219where
217220 D : BlockDevice ,
@@ -268,7 +271,6 @@ where
268271 }
269272}
270273
271- // async drop does not yet exist :(
272274#[ only_sync]
273275impl < ' a , D , T , const MAX_DIRS : usize , const MAX_FILES : usize , const MAX_VOLUMES : usize > Drop
274276 for Volume < ' a , D , T , MAX_DIRS , MAX_FILES , MAX_VOLUMES >
@@ -281,6 +283,19 @@ where
281283 }
282284}
283285
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+
284299impl < ' a , D , T , const MAX_DIRS : usize , const MAX_FILES : usize , const MAX_VOLUMES : usize >
285300 core:: fmt:: Debug for Volume < ' a , D , T , MAX_DIRS , MAX_FILES , MAX_VOLUMES >
286301where
0 commit comments