Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add object-safe traits for File, Filesystem, Storage #49

Merged
merged 1 commit into from
Dec 15, 2023

Conversation

robin-nitrokey
Copy link
Member

@robin-nitrokey robin-nitrokey commented Dec 15, 2023

The Storage trait is not object safe, and the File and Filesystem struct have the Storage implementation as a type parameter. This can make it hard to write code that works with multiple storage implementations, and it can also lead to increased binary size as the filesystem operations are monomorphized for all storage implementations.

This patch introduces three new traits, DynFile, DynFilesystem and DynStorage, that are object-safe wrappers for the File, Filesystem and Storage types. Some functionality cannot be expressed directly in these traits and is moved into helper functions instead, e. g. callbacks with arbitrary return types or methods using const generics.


Let me know if you have better ideas for the module name …

The Storage trait is not object safe, and the File and Filesystem struct
have the Storage implementation as a type parameter.  This can make it
hard to write code that works with multiple storage implementations, and
it can also lead to increased binary size as the filesystem operations
are monomorphized for all storage implementations.

This patch introduces three new traits, DynFile, DynFilesystem and
DynStorage, that are object-safe wrappers for the File, Filesystem and
Storage types.  Some functionality cannot be expressed directly in these
traits and is moved into helper functions instead, e. g. callbacks with
arbitrary return types or methods using const generics.
@robin-nitrokey robin-nitrokey merged commit ebd27e4 into trussed-dev:main Dec 15, 2023
4 checks passed
@robin-nitrokey robin-nitrokey deleted the dyn branch December 15, 2023 15:48
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