pub fn enqueue(&mut self, item: T) -> Result<(), BufferFullError> {
        let rb = unsafe { self.rb.as_mut() };

        let n = rb.capacity() + 1;
        let buffer: &mut [T] = unsafe { rb.buffer.as_mut() };

        let tail = rb.tail.load_relaxed();
        // NOTE we could replace this `load_acquire` with a `load_relaxed` and this method would be
        // sound on most architectures but that change would result in UB according to the C++
        // memory model, which is what Rust currently uses, so we err on the side of caution and
        // stick to `load_acquire`. Check issue google#sanitizers#882 for more details.
        let head = rb.head.load_acquire();
        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) }
            rb.tail.store_release(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 rb = unsafe { self.rb.as_mut() };
        let n = rb.capacity() + 1;
        let buffer: &mut [T] = unsafe { rb.buffer.as_mut() };
        let tail = rb.tail.load_relaxed();
        // NOTE we could replace this `load_acquire` with a `load_relaxed` and this method would be
        // sound on most architectures but that change would result in UB according to the C++
        // memory model, which is what Rust currently uses, so we err on the side of caution and
        // stick to `load_acquire`. Check issue google#sanitizers#882 for more details.
        let head = rb.head.load_acquire();
        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) }
            rb.tail.store_release(next_tail);
            Ok(())
        } else {
            Err(BufferFullError)
        }
    }
pub fn enqueue ( & mut self , item : T ) -> Result < ( ) , BufferFullError > { let rb = unsafe { self . rb . as_mut ( ) } ; let n = rb . capacity ( ) + 1 ; let buffer : & mut [ T ] = unsafe { rb . buffer . as_mut ( ) } ; let tail = rb . tail . load_relaxed ( ) ; // NOTE we could replace this `load_acquire` with a `load_relaxed` and this method would be // sound on most architectures but that change would result in UB according to the C++ // memory model, which is what Rust currently uses, so we err on the side of caution and // stick to `load_acquire`. Check issue google#sanitizers#882 for more details. let head = rb . head . load_acquire ( ) ; 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 ) } rb . tail . store_release ( 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