Skip to content

Add DynStorageAlloc using FnOnce and release v0.6.1#98

Merged
robin-nitrokey merged 2 commits intomainfrom
callback-once
Mar 4, 2025
Merged

Add DynStorageAlloc using FnOnce and release v0.6.1#98
robin-nitrokey merged 2 commits intomainfrom
callback-once

Conversation

@robin-nitrokey
Copy link
Member

Our DynStorage trait uses a &mut dyn FnMut as a callback for
implementing mount_and_then (instead of a FnOnce like Filesystem). This
is because there is no no-std way to pass a FnOnce in an dyn compatible
trait method.

If alloc is available, this limitation can be avoided by using a
Box. This patch adds an alloc feature to the crate and a
DynStorageAlloc trait behind that feature that provides mount_and_then
functions using a boxed FnOnce instead of a reference to an FnMut.


Use case:

This change makes it possible to only store a Box<dyn DynStorageAlloc> in trussed::virt, getting rid of the three type parameters for the internal/external/volatile storage and making it easy to pick the storage implementation at runtime (e. g. for the usbip runner).

Our DynStorage trait uses a &mut dyn FnMut as a callback for
implementing mount_and_then (instead of a FnOnce like Filesystem).  This
is because there is no no-std way to pass a FnOnce in an dyn compatible
trait method.

If alloc is available, this limitation can be avoided by using a
Box<dyn FnOnce>.  This patch adds an alloc feature to the crate and a
DynStorageAlloc trait behind that feature that provides mount_and_then
functions using a boxed FnOnce instead of a reference to an FnMut.
@robin-nitrokey robin-nitrokey merged commit 53bbcd4 into main Mar 4, 2025
10 checks passed
@robin-nitrokey robin-nitrokey deleted the callback-once branch March 4, 2025 19:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants