@@ -105,7 +105,7 @@ pub unsafe trait WriteBuffer {
105
105
106
106
unsafe impl < B , T > ReadBuffer for B
107
107
where
108
- B : Deref < Target = T > + StableDeref ,
108
+ B : Deref < Target = T > + StableDeref + ' static ,
109
109
T : ReadTarget + ?Sized ,
110
110
{
111
111
type Word = T :: Word ;
@@ -117,7 +117,7 @@ where
117
117
118
118
unsafe impl < B , T > WriteBuffer for B
119
119
where
120
- B : DerefMut < Target = T > + StableDeref ,
120
+ B : DerefMut < Target = T > + StableDeref + ' static ,
121
121
T : WriteTarget + ?Sized ,
122
122
{
123
123
type Word = T :: Word ;
@@ -153,7 +153,7 @@ unsafe impl Word for i64 {}
153
153
/// # Safety
154
154
///
155
155
/// - `as_read_buffer` must adhere to the safety requirements
156
- /// documented for `DmaReadBuffer::dma_read_buffer `.
156
+ /// documented for `ReadBuffer::read_buffer `.
157
157
pub unsafe trait ReadTarget {
158
158
type Word : Word ;
159
159
@@ -172,7 +172,7 @@ pub unsafe trait ReadTarget {
172
172
/// # Safety
173
173
///
174
174
/// - `as_write_buffer` must adhere to the safety requirements
175
- /// documented for `DmaWriteBuffer::dma_write_buffer `.
175
+ /// documented for `WriteBuffer::write_buffer `.
176
176
pub unsafe trait WriteTarget {
177
177
type Word : Word ;
178
178
@@ -256,75 +256,6 @@ unsafe impl<T: WriteTarget> WriteTarget for MaybeUninit<T> {
256
256
type Word = T :: Word ;
257
257
}
258
258
259
- /// Trait for buffers that can be given to DMA for reading. This is a more strict version of
260
- /// [ReadBuffer](trait.ReadBuffer.html), if you are not sure about which one to use on your safe
261
- /// API, prefer this one. This trait also allows end users to __unsafely__ bypass the `'static`
262
- /// invariant.
263
- ///
264
- /// # Safety
265
- ///
266
- /// This has the same invariants as [ReadBuffer](trait.ReadBuffer.html) with the additional
267
- /// requirement that the buffer should have a `'static` lifetime.
268
- pub unsafe trait StaticReadBuffer : ReadBuffer {
269
- type Word ;
270
-
271
- /// Provide a buffer usable for DMA reads.
272
- ///
273
- /// The return value is:
274
- ///
275
- /// - pointer to the start of the buffer
276
- /// - buffer size in words
277
- ///
278
- /// # Safety
279
- ///
280
- /// Once this method has been called, it is unsafe to call any `&mut self`
281
- /// methods on this object as long as the returned value is in use (by DMA).
282
- unsafe fn static_read_buffer ( & self ) -> ( * const <Self as StaticReadBuffer >:: Word , usize ) ;
283
- }
284
-
285
- /// Trait for buffers that can be given to DMA for writing. This is a more strict version of
286
- /// [WriteBuffer](trait.WriteBuffer.html), if you are not sure about which one to use on your safe
287
- /// API, prefer this one. This trait also allows end users to __unsafely__ bypass the `'static`
288
- /// invariant.
289
- ///
290
- /// # Safety
291
- ///
292
- /// This has the same invariants as [WriteBuffer](trait.WriteBuffer.html) with the additional
293
- /// requirement that the buffer should have a `'static` lifetime.
294
- pub unsafe trait StaticWriteBuffer : WriteBuffer {
295
- type Word ;
296
-
297
- /// Provide a buffer usable for DMA writes.
298
- ///
299
- /// The return value is:
300
- ///
301
- /// - pointer to the start of the buffer
302
- /// - buffer size in words
303
- ///
304
- /// # Safety
305
- ///
306
- /// Once this method has been called, it is unsafe to call any `&mut self`
307
- /// methods, except for `write_buffer`, on this object as long as the
308
- /// returned value is in use (by DMA).
309
- unsafe fn static_write_buffer ( & mut self ) -> ( * mut <Self as StaticWriteBuffer >:: Word , usize ) ;
310
- }
311
-
312
- unsafe impl < B : ReadBuffer + ' static > StaticReadBuffer for B {
313
- type Word = <Self as ReadBuffer >:: Word ;
314
-
315
- unsafe fn static_read_buffer ( & self ) -> ( * const <Self as StaticReadBuffer >:: Word , usize ) {
316
- self . read_buffer ( )
317
- }
318
- }
319
-
320
- unsafe impl < B : WriteBuffer + ' static > StaticWriteBuffer for B {
321
- type Word = <Self as WriteBuffer >:: Word ;
322
-
323
- unsafe fn static_write_buffer ( & mut self ) -> ( * mut <Self as StaticWriteBuffer >:: Word , usize ) {
324
- self . write_buffer ( )
325
- }
326
- }
327
-
328
259
#[ cfg( test) ]
329
260
mod tests {
330
261
use super :: * ;
@@ -337,40 +268,23 @@ mod tests {
337
268
unsafe { buffer. read_buffer ( ) }
338
269
}
339
270
340
- fn static_api_read < W , B > ( buffer : B ) -> ( * const W , usize )
341
- where
342
- B : StaticReadBuffer < Word = W > ,
343
- {
344
- unsafe { buffer. static_read_buffer ( ) }
345
- }
346
-
347
271
fn api_write < W , B > ( mut buffer : B ) -> ( * mut W , usize )
348
272
where
349
273
B : WriteBuffer < Word = W > ,
350
274
{
351
275
unsafe { buffer. write_buffer ( ) }
352
276
}
353
277
354
- fn static_api_write < W , B > ( mut buffer : B ) -> ( * mut W , usize )
355
- where
356
- B : StaticWriteBuffer < Word = W > ,
357
- {
358
- unsafe { buffer. static_write_buffer ( ) }
359
- }
360
-
361
278
#[ test]
362
279
fn read_api ( ) {
363
280
const SIZE : usize = 128 ;
364
281
static BUF : [ u8 ; SIZE ] = [ 0u8 ; SIZE ] ;
365
282
let local_buf = [ 0u8 ; SIZE ] ;
366
283
367
- let ( ptr, size_local) = api_read ( & local_buf ) ;
284
+ let ( ptr, size_local) = api_read ( & BUF ) ;
368
285
assert ! ( unsafe { ( & * ptr as & dyn Any ) . is:: <u8 >( ) } ) ;
369
286
assert ! ( size_local == SIZE ) ;
370
287
371
- let ( ptr, size_static) = static_api_read ( & BUF ) ;
372
- assert ! ( unsafe { ( & * ptr as & dyn Any ) . is:: <u8 >( ) } ) ;
373
- assert ! ( size_static == SIZE ) ;
374
288
}
375
289
376
290
#[ test]
@@ -379,12 +293,8 @@ mod tests {
379
293
static mut BUF : [ u8 ; SIZE ] = [ 0u8 ; SIZE ] ;
380
294
let mut local_buf = [ 0u8 ; SIZE ] ;
381
295
382
- let ( ptr, size_local) = api_write ( & mut local_buf ) ;
296
+ let ( ptr, size_local) = api_write ( unsafe { & mut BUF } ) ;
383
297
assert ! ( unsafe { ( & * ptr as & dyn Any ) . is:: <u8 >( ) } ) ;
384
298
assert ! ( size_local == SIZE ) ;
385
-
386
- let ( ptr, size_static) = static_api_write ( unsafe { & mut BUF } ) ;
387
- assert ! ( unsafe { ( & * ptr as & dyn Any ) . is:: <u8 >( ) } ) ;
388
- assert ! ( size_static == SIZE ) ;
389
299
}
390
300
}
0 commit comments