crossbeam::queue

Struct SegQueue

Source
pub struct SegQueue<T> { /* private fields */ }
Expand description

An unbounded multi-producer multi-consumer queue.

This queue is implemented as a linked list of segments, where each segment is a small buffer that can hold a handful of elements. There is no limit to how many elements can be in the queue at a time. However, since segments need to be dynamically allocated as elements get pushed, this queue is somewhat slower than ArrayQueue.

§Examples

use crossbeam_queue::SegQueue;

let q = SegQueue::new();

q.push('a');
q.push('b');

assert_eq!(q.pop(), Some('a'));
assert_eq!(q.pop(), Some('b'));
assert!(q.pop().is_none());

Implementations§

Source§

impl<T> SegQueue<T>

Source

pub const fn new() -> SegQueue<T>

Creates a new unbounded queue.

§Examples
use crossbeam_queue::SegQueue;

let q = SegQueue::<i32>::new();
Source

pub fn push(&self, value: T)

Pushes an element into the queue.

§Examples
use crossbeam_queue::SegQueue;

let q = SegQueue::new();

q.push(10);
q.push(20);
Source

pub fn pop(&self) -> Option<T>

Pops an element from the queue.

If the queue is empty, None is returned.

§Examples
use crossbeam_queue::SegQueue;

let q = SegQueue::new();

q.push(10);
assert_eq!(q.pop(), Some(10));
assert!(q.pop().is_none());
Source

pub fn is_empty(&self) -> bool

Returns true if the queue is empty.

§Examples
use crossbeam_queue::SegQueue;

let q = SegQueue::new();

assert!(q.is_empty());
q.push(1);
assert!(!q.is_empty());
Source

pub fn len(&self) -> usize

Returns the number of elements in the queue.

§Examples
use crossbeam_queue::SegQueue;

let q = SegQueue::new();
assert_eq!(q.len(), 0);

q.push(10);
assert_eq!(q.len(), 1);

q.push(20);
assert_eq!(q.len(), 2);

Trait Implementations§

Source§

impl<T> Debug for SegQueue<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<T> Default for SegQueue<T>

Source§

fn default() -> SegQueue<T>

Returns the “default value” for a type. Read more
Source§

impl<T> Drop for SegQueue<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T> IntoIterator for SegQueue<T>

Source§

type Item = T

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> <SegQueue<T> as IntoIterator>::IntoIter

Creates an iterator from a value. Read more
Source§

impl<T> RefUnwindSafe for SegQueue<T>

Source§

impl<T> Send for SegQueue<T>
where T: Send,

Source§

impl<T> Sync for SegQueue<T>
where T: Send,

Source§

impl<T> UnwindSafe for SegQueue<T>

Auto Trait Implementations§

§

impl<T> !Freeze for SegQueue<T>

§

impl<T> Unpin for SegQueue<T>
where T: Unpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize = _

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 256 bytes