pub fn enqueue(&mut self, item: T) -> Result<(), BufferFullError> {
        let n = self.capacity() + 1;

        let head = self.head.get_mut();
        let tail = self.tail.get_mut();

        let buffer: &mut [T] = unsafe { self.buffer.as_mut() };

        let next_tail = (*tail + 1) % n;
        if next_tail != *head {
            // NOTE(ptr::write) the memory slot that we are about to write to is uninitialized. We
            // use `ptr::write` to avoid running `T`'s destructor on the uninitialized memory
            unsafe { ptr::write(buffer.get_unchecked_mut(*tail), item) }
            *tail = next_tail;
            Ok(())
        } else {
            Err(BufferFullError)
        }
    }
/// Adds an `item` to the end of the queue
///
/// Returns `BufferFullError` if the queue is full
Adds an `item` to the end of the queue
Returns `BufferFullError` if the queue is full
Adds an ` item ` to the end of the queue Returns ` BufferFullError ` if the queue is full
pub fn enqueue(&mut self, item: T) -> Result<(), BufferFullError> {
        let n = self.capacity() + 1;
        let head = self.head.get_mut();
        let tail = self.tail.get_mut();
        let buffer: &mut [T] = unsafe { self.buffer.as_mut() };
        let next_tail = (*tail + 1) % n;
        if next_tail != *head {
            // NOTE(ptr::write) the memory slot that we are about to write to is uninitialized. We
            // use `ptr::write` to avoid running `T`'s destructor on the uninitialized memory
            unsafe { ptr::write(buffer.get_unchecked_mut(*tail), item) }
            *tail = next_tail;
            Ok(())
        } else {
            Err(BufferFullError)
        }
    }
pub fn enqueue ( & mut self , item : T ) -> Result < ( ) , BufferFullError > { let n = self . capacity ( ) + 1 ; let head = self . head . get_mut ( ) ; let tail = self . tail . get_mut ( ) ; let buffer : & mut [ T ] = unsafe { self . buffer . as_mut ( ) } ; let next_tail = ( * tail + 1 ) % n ; if next_tail != * head { // NOTE(ptr::write) the memory slot that we are about to write to is uninitialized. We // use `ptr::write` to avoid running `T`'s destructor on the uninitialized memory unsafe { ptr :: write ( buffer . get_unchecked_mut ( * tail ) , item ) } * tail = next_tail ; Ok ( ( ) ) } else { Err ( BufferFullError ) } }
Adds an `item` to the end of the queue
Returns `BufferFullError` if the queue is full
Adds an ` item ` to the end of the queue Returns ` BufferFullError ` if the queue is full
&mut self
item
T
&mut self
item
T