refactor(fd): replace dyn ObjectInterface with enum Fd
#2096
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.
We currently define
ObjectInterface::readandObjectInterface::writeourselves:kernel/src/fd/mod.rs
Lines 205 to 215 in 4712cd2
It would be useful to migrate to
embedded_io_async::Readandembedded_io_async::Writeinstead:ObjectInterface: Read + Write.#1891 has already migrated non-
asyncI/O toembedded-io.#1900 has prepared migrating to
ObjectInterfacetoReadandWritetraits by moving socket-internal synchronization to the outside.This was required since
ReadandWritetakeselfmutably, while our methods takeselfsharedly.Additionally, moving the synchronization to the outside allowed us to get rid of a lot of boilerplate code and enabled performing multiple operations while avoiding frequent relocking.
This PR further prepares migrating
ObjectInterfacetoReadandWrite.This is done by replacing
dyn ObjectInterfaceviaasync-traitwith anenum Fd, enumerating all possible file descriptors.Continuing to use
dyn ObjectInterfacewould require the respective macros (dynosaurorasync-trait) to also be applied to the respective traits, since dyn async traits in Rust are not there yet (Dyn Async Traits · baby steps, In-place initialization - Rust Project Goals).I am not sure if
embedded-io-asyncwould be open to this optional additional dependency.This would also require us to do the same thing with every new async trait that we would want to depend on in the future.
Using
static-dispatchto avoid writing macros ourselves for forwarding is also not possible, because the respective trait needs to be registered with the macro too.TODO: Maybe use
delegate?