@@ -367,27 +367,15 @@ impl<T, S: Storage> QueueInner<T, S> {
367367/// 
368368/// # Examples 
369369/// 
370+ /// Create a queue and split it at runtime 
371+ /// 
370372/// ``` 
371373/// # use heapless::spsc::Queue; 
372374/// let mut queue: Queue<(), 4> = Queue::new(); 
373375/// let (mut producer, mut consumer) = queue.split(); 
374376/// producer.enqueue(()).unwrap(); 
375377/// assert_eq!(consumer.dequeue(), Some(())); 
376378/// ``` 
377- pub  fn  split ( & mut  self )  -> ( Producer < ' _ ,  T > ,  Consumer < ' _ ,  T > )  { 
378-         ( 
379-             Producer  {  rb :  self . as_view ( )  } , 
380-             Consumer  {  rb :  self . as_view ( )  } , 
381-         ) 
382-     } 
383- } 
384- 
385- impl < T ,  const  N :  usize >  Queue < T ,  N >  { 
386-     /// Splits a queue into producer and consumer endpoints. 
387- /// 
388- /// Unlike [`Queue::split`](), this method can be used in a `const` context 
389- /// 
390- /// # Examples 
391379/// 
392380/// Create a queue at compile time, split it at runtime, 
393381/// and pass it to an interrupt handler via a mutex. 
@@ -439,6 +427,20 @@ impl<T, const N: usize> Queue<T, N> {
439427///     consumer.dequeue().unwrap(); 
440428/// } 
441429/// ``` 
430+ pub  fn  split ( & mut  self )  -> ( Producer < ' _ ,  T > ,  Consumer < ' _ ,  T > )  { 
431+         ( 
432+             Producer  {  rb :  self . as_view ( )  } , 
433+             Consumer  {  rb :  self . as_view ( )  } , 
434+         ) 
435+     } 
436+ } 
437+ 
438+ impl < T ,  const  N :  usize >  Queue < T ,  N >  { 
439+     /// Splits a queue into producer and consumer endpoints. 
440+ /// 
441+ /// Unlike [`Queue::split`](), this method can be used in a `const` context 
442+ /// 
443+ /// # Example 
442444/// 
443445/// Create and split a queue at compile time, and pass it to the main 
444446/// function and an interrupt handler via a mutex at runtime. 
@@ -497,58 +499,7 @@ impl<T> QueueView<T> {
497499/// 
498500/// Unlike [`Queue::split`](), this method can be used in a `const` context 
499501/// 
500- /// # Examples 
501- /// 
502- /// Create a queue at compile time, split it at runtime, 
503- /// and pass it to an interrupt handler via a mutex. 
504- /// 
505- /// ``` 
506- /// use core::cell::RefCell; 
507- /// use critical_section::Mutex; 
508- /// use heapless::spsc::{Producer, Queue}; 
509- /// 
510- /// static PRODUCER: Mutex<RefCell<Option<Producer<'static, ()>>>> = Mutex::new(RefCell::new(None)); 
511- /// 
512- /// fn interrupt() { 
513- ///     let mut producer = { 
514- ///         static mut P: Option<Producer<'static, ()>> = None; 
515- ///         // SAFETY: Mutable access to `P` is allowed exclusively in this scope 
516- ///         // and `interrupt` cannot be called directly or preempt itself. 
517- ///         unsafe { &mut P } 
518- ///     } 
519- ///     .get_or_insert_with(|| { 
520- ///         critical_section::with(|cs| PRODUCER.borrow_ref_mut(cs).take().unwrap()) 
521- ///     }); 
522- /// 
523- ///     producer.enqueue(()).unwrap(); 
524- /// } 
525- /// 
526- /// fn main() { 
527- ///     let mut consumer = { 
528- ///         let (p, c) = { 
529- ///             static mut Q: Queue<(), 4> = Queue::new(); 
530- ///             // SAFETY: `Q` is only accessible in this scope 
531- ///             // and `main` is only called once. 
532- ///             #[allow(static_mut_refs)] 
533- ///             unsafe { 
534- ///                 Q.split() 
535- ///             } 
536- ///         }; 
537- /// 
538- ///         critical_section::with(move |cs| { 
539- ///             let mut producer = PRODUCER.borrow_ref_mut(cs); 
540- ///             *producer = Some(p); 
541- ///         }); 
542- /// 
543- ///         c 
544- ///     }; 
545- /// 
546- ///     // Interrupt occurs. 
547- /// #   interrupt(); 
548- /// 
549- ///     consumer.dequeue().unwrap(); 
550- /// } 
551- /// ``` 
502+ /// # Example 
552503/// 
553504/// Create and split a queue at compile time, and pass it to the main 
554505/// function and an interrupt handler via a mutex at runtime. 
@@ -557,13 +508,13 @@ impl<T> QueueView<T> {
557508/// use core::cell::RefCell; 
558509/// 
559510/// use critical_section::Mutex; 
560- /// use heapless::spsc::{Consumer, Producer, Queue}; 
511+ /// use heapless::spsc::{Consumer, Producer, Queue, QueueView }; 
561512/// 
562513/// static PC: ( 
563514///     Mutex<RefCell<Option<Producer<'_, ()>>>>, 
564515///     Mutex<RefCell<Option<Consumer<'_, ()>>>>, 
565516/// ) = { 
566- ///     static mut Q: Queue <(), 4 > = Queue::new(); 
517+ ///     static mut Q: &mut QueueView <()> = &mut  Queue::<(), 4> ::new(); 
567518///     // SAFETY: `Q` is only accessible in this scope. 
568519///     #[allow(static_mut_refs)] 
569520///     let (p, c) = unsafe { Q.split_const() }; 
0 commit comments