Skip to content

Commit e544029

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 e25ce52 commit e544029

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
@@ -223,7 +223,7 @@ impl FileOffset {
223223
/// ```
224224
pub trait GuestAddressSpace: Clone {
225225
/// The type that will be used to access guest memory.
226-
type M: GuestMemory;
226+
type M: IoMemory;
227227

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

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

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

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

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

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

0 commit comments

Comments
 (0)