vmsilo fork of vhost rust libraries
Find a file
Erik Schilling e117afb739 vhost-user-backend: simplify the use of generics
In order to allow zero-cost exchanging of the concrete bitmap and vring
types, a lot of the generic code required using a tuple of
`<VringType, BitmapType>` for parameterizing the impl's. Once code is
also oblivious of the concrete backend (and a lot of code is), this
tuple turns into a triplet. Juggling these three single letter generic
parameters while making sure that all the type constraints (that are
also changing depending on the abstraction layer) does not feel very
ergonomic.

While one can argue that within this crate, this would be fine since
people probably know the internals, the design choice is leaking out
into every consumer of vhost-user-backend. Instead of just being able
to reference "some backend" one needs to copy a lot of boilerplate code
for also passing the other type parameters (again, while making sure
that all the constraints are met).

Instead, this commit changes things to utilize associated types [1].
This makes the Bitmap and Vring types part of the backend trait and
requires the implementations to spell them out. Code that just wants to
use the backend without needing to know the details can now just use
the trait without needing to specify the Bitmap and Vring types again.
Where needed, restricting Bitmap and Vring further is still possible
(though one no longer needs to copy all the existing restrictions and
can keep the code more maintainable by only listing new ones).

Overall, my main target was to improve the ergonomics of the consumers
of the crate. But I think the change also improves the readability and
maintainability within this crate. Combined, this hopefully justifies
the small code breakage in consumers.

No functional changes intended.
No change in type flexibility intended.

BREAKING CHANGE, consumers of the lib will need to adjust their code
(but it should improve the general readability).

Signed-off-by: Erik Schilling <erik.schilling@linaro.org>

[1] https://doc.rust-lang.org/book/ch19-03-advanced-traits.html#specifying-placeholder-types-in-trait-definitions-with-associated-types
2023-10-02 09:52:53 +02:00
.buildkite vhost: Adopt new backend naming 2023-09-13 13:00:10 +02:00
.cargo Fix build on aarch64+musl 2021-03-14 09:59:41 +05:30
.github update dependabot formatting 2021-09-10 17:24:49 +03:00
crates vhost-user-backend: simplify the use of generics 2023-10-02 09:52:53 +02:00
rust-vmm-ci@665f31f4b4 build(deps): bump rust-vmm-ci from 9dfe5b2 to 665f31f 2023-09-14 16:40:26 +08:00
.gitignore Add gitignore 2021-05-19 19:36:43 -07:00
.gitmodules Initial commit 2020-09-17 13:51:21 +03:00
Cargo.toml Merge remote-tracking branch 'vhost-user-backend/main' into workspace 2022-10-11 12:27:44 +05:30
CODEOWNERS fix CODEOWNERS file 2022-02-16 15:55:50 +01:00
coverage_config_aarch64.json vhost: Adopt new backend naming 2023-09-13 13:00:10 +02:00
coverage_config_x86_64.json coverage: update the score 2023-09-14 16:40:26 +08:00
LICENSE Rename LICENSE-APACHE to LICENSE 2020-11-25 17:01:17 +01:00
LICENSE-BSD-3-Clause Refine BSD-3-Clause license file 2021-11-26 21:19:40 +08:00
README.md vhost: Add README for the workspace 2022-10-11 12:28:33 +05:30

vhost

The vhost workspace hosts libraries related to the vhost and vhost-user protocols. It currently consists of the following crates:

  • vhost -> A pure rust library for vDPA, vhost and vhost-user.
  • vhost-user-backend -> It provides a framework to implement vhost-user backend services.