@@ -276,10 +276,10 @@ where
276
276
}
277
277
278
278
macro_rules! impl_ {
279
- ( $uxx: ident) => {
279
+ ( $uxx: ident, $doc : tt $ ( , $unsf : ident ) ? ) => {
280
280
impl <T , const N : usize > Queue <T , $uxx, N > {
281
- /// Creates an empty queue with a fixed capacity of `N`
282
- pub const fn $uxx( ) -> Self {
281
+ # [ doc = $doc ]
282
+ pub const $ ( $unsf ) * fn $uxx( ) -> Self {
283
283
Self {
284
284
head: Atomic :: new( 0 ) ,
285
285
tail: Atomic :: new( 0 ) ,
@@ -296,7 +296,7 @@ macro_rules! impl_ {
296
296
/// ```
297
297
/// use heapless::spsc::Queue;
298
298
///
299
- /// let mut queue: Queue<u8, _, 235> = Queue::u8 ();
299
+ /// let mut queue: Queue<u8, _, 235> = Queue::new ();
300
300
/// let (mut producer, mut consumer) = queue.split();
301
301
/// assert_eq!(None, consumer.peek());
302
302
/// producer.enqueue(1);
@@ -414,9 +414,17 @@ impl<T, const N: usize> Queue<T, usize, N> {
414
414
}
415
415
}
416
416
417
- impl_ ! ( u8 ) ;
418
- impl_ ! ( u16 ) ;
419
- impl_ ! ( usize ) ;
417
+ impl_ ! (
418
+ u8 ,
419
+ "Creates an empty queue with a fixed capacity of `N`. **Safety**: Assumes `N <= u8::MAX`." ,
420
+ unsafe
421
+ ) ;
422
+ impl_ ! (
423
+ u16 ,
424
+ "Creates an empty queue with a fixed capacity of `N`. **Safety**: Assumes `N <= u16::MAX`." ,
425
+ unsafe
426
+ ) ;
427
+ impl_ ! ( usize , "Creates an empty queue with a fixed capacity of `N`" ) ;
420
428
421
429
impl < T , U , U2 , const N : usize , const N2 : usize > PartialEq < Queue < T , U2 , N2 > > for Queue < T , U , N >
422
430
where
@@ -633,7 +641,7 @@ mod tests {
633
641
634
642
#[ test]
635
643
fn iter_overflow ( ) {
636
- let mut rb: Queue < i32 , u8 , 4 > = Queue :: u8 ( ) ;
644
+ let mut rb: Queue < i32 , u8 , 4 > = unsafe { Queue :: u8 ( ) } ;
637
645
638
646
rb. enqueue ( 0 ) . unwrap ( ) ;
639
647
for _ in 0 ..300 {
0 commit comments