Add DynStorageAlloc using FnOnce and release v0.6.1#98
Merged
robin-nitrokey merged 2 commits intomainfrom Mar 4, 2025
Merged
Conversation
sosthene-nitrokey
approved these changes
Mar 4, 2025
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.
d766bb2 to
53bbcd4
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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>intrussed::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).