@@ -147,8 +147,8 @@ unsafe impl ByteValued for Descriptor {}
147147
148148/// A virtio descriptor chain.
149149#[ derive( Clone , Debug ) ]
150- pub struct DescriptorChain < M : GuestAddressSpace > {
151- mem : M :: T ,
150+ pub struct DescriptorChain < M > {
151+ mem : M ,
152152 desc_table : GuestAddress ,
153153 queue_size : u16 ,
154154 head_index : u16 ,
@@ -157,9 +157,13 @@ pub struct DescriptorChain<M: GuestAddressSpace> {
157157 is_indirect : bool ,
158158}
159159
160- impl < M : GuestAddressSpace > DescriptorChain < M > {
160+ impl < M > DescriptorChain < M >
161+ where
162+ M : Deref ,
163+ M :: Target : GuestMemory ,
164+ {
161165 fn with_ttl (
162- mem : M :: T ,
166+ mem : M ,
163167 desc_table : GuestAddress ,
164168 queue_size : u16 ,
165169 ttl : u16 ,
@@ -177,7 +181,7 @@ impl<M: GuestAddressSpace> DescriptorChain<M> {
177181 }
178182
179183 /// Create a new `DescriptorChain` instance.
180- fn new ( mem : M :: T , desc_table : GuestAddress , queue_size : u16 , head_index : u16 ) -> Self {
184+ fn new ( mem : M , desc_table : GuestAddress , queue_size : u16 , head_index : u16 ) -> Self {
181185 Self :: with_ttl ( mem, desc_table, queue_size, queue_size, head_index)
182186 }
183187
@@ -188,8 +192,8 @@ impl<M: GuestAddressSpace> DescriptorChain<M> {
188192
189193 /// Return a `GuestMemory` object that can be used to access the buffers
190194 /// pointed to by the descriptor chain.
191- pub fn memory ( & self ) -> & M :: M {
192- & * self . mem
195+ pub fn memory ( & self ) -> & M :: Target {
196+ self . mem . deref ( )
193197 }
194198
195199 /// Returns an iterator that only yields the readable descriptors in the chain.
@@ -234,7 +238,11 @@ impl<M: GuestAddressSpace> DescriptorChain<M> {
234238 }
235239}
236240
237- impl < M : GuestAddressSpace > Iterator for DescriptorChain < M > {
241+ impl < M > Iterator for DescriptorChain < M >
242+ where
243+ M : Deref ,
244+ M :: Target : GuestMemory + Sized ,
245+ {
238246 type Item = Descriptor ;
239247
240248 /// Returns the next descriptor in this descriptor chain, if there is one.
@@ -279,12 +287,16 @@ impl<M: GuestAddressSpace> Iterator for DescriptorChain<M> {
279287
280288/// An iterator for readable or writable descriptors.
281289#[ derive( Clone ) ]
282- pub struct DescriptorChainRwIter < M : GuestAddressSpace > {
290+ pub struct DescriptorChainRwIter < M > {
283291 chain : DescriptorChain < M > ,
284292 writable : bool ,
285293}
286294
287- impl < M : GuestAddressSpace > Iterator for DescriptorChainRwIter < M > {
295+ impl < M > Iterator for DescriptorChainRwIter < M >
296+ where
297+ M : Deref ,
298+ M :: Target : GuestMemory + Sized ,
299+ {
288300 type Item = Descriptor ;
289301
290302 /// Returns the next descriptor in this descriptor chain, if there is one.
@@ -308,9 +320,9 @@ impl<M: GuestAddressSpace> Iterator for DescriptorChainRwIter<M> {
308320
309321// We can't derive Debug, because rustc doesn't generate the M::T: Debug
310322// constraint
311- impl < M : Debug + GuestAddressSpace > Debug for DescriptorChainRwIter < M >
323+ impl < M > Debug for DescriptorChainRwIter < M >
312324where
313- M :: T : Debug ,
325+ M : Debug ,
314326{
315327 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
316328 f. debug_struct ( "DescriptorChainRwIter" )
@@ -322,16 +334,16 @@ where
322334
323335/// Consuming iterator over all available descriptor chain heads in the queue.
324336#[ derive( Debug ) ]
325- pub struct AvailIter < ' b , M : GuestAddressSpace > {
326- mem : M :: T ,
337+ pub struct AvailIter < ' b , M > {
338+ mem : M ,
327339 desc_table : GuestAddress ,
328340 avail_ring : GuestAddress ,
329341 last_index : Wrapping < u16 > ,
330342 queue_size : u16 ,
331343 next_avail : & ' b mut Wrapping < u16 > ,
332344}
333345
334- impl < ' b , M : GuestAddressSpace > AvailIter < ' b , M > {
346+ impl < ' b , M > AvailIter < ' b , M > {
335347 /// Goes back one position in the available descriptor chain offered by the driver.
336348 ///
337349 /// Rust does not support bidirectional iterators. This is the only way to revert the effect
@@ -344,7 +356,11 @@ impl<'b, M: GuestAddressSpace> AvailIter<'b, M> {
344356 }
345357}
346358
347- impl < ' b , M : GuestAddressSpace > Iterator for AvailIter < ' b , M > {
359+ impl < ' b , M > Iterator for AvailIter < ' b , M >
360+ where
361+ M : Clone + Deref ,
362+ M :: Target : GuestMemory + Sized ,
363+ {
348364 type Item = DescriptorChain < M > ;
349365
350366 fn next ( & mut self ) -> Option < Self :: Item > {
@@ -559,7 +575,7 @@ pub struct QueueState<M: GuestAddressSpace> {
559575
560576impl < M : GuestAddressSpace > QueueState < M > {
561577 /// Get a consuming iterator over all available descriptor chain heads offered by the driver.
562- pub fn iter ( & mut self , mem : M :: T ) -> Result < AvailIter < ' _ , M > , Error > {
578+ pub fn iter ( & mut self , mem : M :: T ) -> Result < AvailIter < ' _ , M :: T > , Error > {
563579 self . avail_idx ( & mem, Ordering :: Acquire )
564580 . map ( move |idx| AvailIter {
565581 mem,
@@ -1106,7 +1122,7 @@ impl<M: GuestAddressSpace, S: QueueStateT<M>> Queue<M, S> {
11061122
11071123impl < M : GuestAddressSpace > Queue < M , QueueState < M > > {
11081124 /// A consuming iterator over all available descriptor chain heads offered by the driver.
1109- pub fn iter ( & mut self ) -> Result < AvailIter < ' _ , M > , Error > {
1125+ pub fn iter ( & mut self ) -> Result < AvailIter < ' _ , M :: T > , Error > {
11101126 self . state . iter ( self . mem . memory ( ) )
11111127 }
11121128}
0 commit comments