Skip to content

Commit 442297b

Browse files
committed
Implement GuestAddressSpace for IoMemory
We want a trait like `GuestAddressSpace` for `IoMemory`, but just duplicating it into an `IoAddressSpace` trait is not so easy: We could rename the current `GuestAddressSpace` to `IoAddressSpace` and require `M: IoMemory` (instead of `M: GuestMemory`), and then define `GuestAddressSpace` as: ```rust pub trait GuestAddressSpace: IoAddressSpace<M: GuestMemory> {} impl<AS: IoAddressSpace> GuestAddressSpace for AS where AS::M: GuestMemory, {} ``` But doing just this would break all existing `GuestAddressSpace` users, as they’d now need to import `IoAddressSpace` to use `memory()`. (Re-)Adding `GuestAddressSpace::memory()` as ```rust fn memory(&self) -> <Self as IoAddressSpace>::T { IoAddressSpace::memory(self) } ``` also doesn’t (just) work, as it gets the compiler confused which `memory()` to use (between `GuestAddressSpace` and `IoAddressSpace`), so the `IoAddressSpace::memory()` method would need to be called differently. However, I would find that a bit silly, and it would also then later require changes if the user wants to switch from `GuestMemory` to `IoMemory`. Instead just changing the `GuestAddressSpace::M: GuestMemory` requirement to `M: IoMemory` seems easier: - All callers that just use the `Bytes` interface remain completely unchanged, - It does break users that actually need the `GuestMemory` interface, but from what I have seen, that is only the case for `vhost::vhost_kern`. There, we can simply require that `<AS as GuestAddressSpace>::M: GuestMemory`. Signed-off-by: Hanna Czenczek <[email protected]>
1 parent ed47e85 commit 442297b

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/guest_memory.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ impl FileOffset {
222222
/// ```
223223
pub trait GuestAddressSpace: Clone {
224224
/// The type that will be used to access guest memory.
225-
type M: GuestMemory;
225+
type M: IoMemory;
226226

227227
/// A type that provides access to the memory.
228228
type T: Clone + Deref<Target = Self::M>;
@@ -233,7 +233,7 @@ pub trait GuestAddressSpace: Clone {
233233
fn memory(&self) -> Self::T;
234234
}
235235

236-
impl<M: GuestMemory> GuestAddressSpace for &M {
236+
impl<M: IoMemory> GuestAddressSpace for &M {
237237
type M = M;
238238
type T = Self;
239239

@@ -242,7 +242,7 @@ impl<M: GuestMemory> GuestAddressSpace for &M {
242242
}
243243
}
244244

245-
impl<M: GuestMemory> GuestAddressSpace for Rc<M> {
245+
impl<M: IoMemory> GuestAddressSpace for Rc<M> {
246246
type M = M;
247247
type T = Self;
248248

@@ -251,7 +251,7 @@ impl<M: GuestMemory> GuestAddressSpace for Rc<M> {
251251
}
252252
}
253253

254-
impl<M: GuestMemory> GuestAddressSpace for Arc<M> {
254+
impl<M: IoMemory> GuestAddressSpace for Arc<M> {
255255
type M = M;
256256
type T = Self;
257257

0 commit comments

Comments
 (0)