Skip to content

Commit c58fd7c

Browse files
fixup! Add DynStorageAlloc using FnOnce
1 parent 0cda1ec commit c58fd7c

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![cfg_attr(not(test), no_std)]
2+
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
23
// FIXME
34
#![allow(clippy::missing_safety_doc)]
45

src/object_safe.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,9 @@ impl dyn DynStorage + '_ {
243243
}
244244

245245
#[cfg(feature = "alloc")]
246+
/// Extension trait for [`DynStorage`][] that requires `alloc`.
247+
///
248+
/// This extension trait uses owned `FnOnce` callbacks instead of references to `FnMut`.
246249
pub trait DynStorageAlloc: DynStorage {
247250
fn mount_and_then_unit_boxed(&mut self, f: BoxedFilesystemCallback<'_>) -> Result<()>;
248251
}
@@ -256,7 +259,10 @@ impl<T: Storage> DynStorageAlloc for T {
256259

257260
#[cfg(feature = "alloc")]
258261
impl dyn DynStorageAlloc + '_ {
259-
pub fn mount_and_then_boxed<R>(&mut self, f: BoxedFilesystemCallback<'_, R>) -> Result<R> {
262+
pub fn mount_and_then_once<F, R>(&mut self, f: F) -> Result<R>
263+
where
264+
F: FnOnce(&dyn DynFilesystem) -> Result<R>,
265+
{
260266
let mut result = Err(Error::IO);
261267
self.mount_and_then_unit_boxed(alloc::boxed::Box::new(|fs| {
262268
result = Ok(f(fs)?);

0 commit comments

Comments
 (0)