Enum Steal

enum Steal<T>

Possible outcomes of a steal operation.

Examples

There are lots of ways to chain results of steal operations together:

use crossbeam_deque::Steal::{self, Empty, Retry, Success};

let collect = |v: Vec<Steal<i32>>| v.into_iter().collect::<Steal<i32>>();

assert_eq!(collect(vec![Empty, Empty, Empty]), Empty);
assert_eq!(collect(vec![Empty, Retry, Empty]), Retry);
assert_eq!(collect(vec![Retry, Success(1), Empty]), Success(1));

assert_eq!(collect(vec![Empty, Empty]).or_else(|| Retry), Retry);
assert_eq!(collect(vec![Retry, Empty]).or_else(|| Success(1)), Success(1));

Variants

Empty

The queue was empty at the time of stealing.

Success(T)

At least one task was successfully stolen.

Retry

The steal operation needs to be retried.

Implementations

impl<T> Steal<T>

fn is_empty(self: &Self) -> bool

Returns true if the queue was empty at the time of stealing.

Examples

use crossbeam_deque::Steal::{Empty, Retry, Success};

assert!(!Success(7).is_empty());
assert!(!Retry::<i32>.is_empty());

assert!(Empty::<i32>.is_empty());
fn is_success(self: &Self) -> bool

Returns true if at least one task was stolen.

Examples

use crossbeam_deque::Steal::{Empty, Retry, Success};

assert!(!Empty::<i32>.is_success());
assert!(!Retry::<i32>.is_success());

assert!(Success(7).is_success());
fn is_retry(self: &Self) -> bool

Returns true if the steal operation needs to be retried.

Examples

use crossbeam_deque::Steal::{Empty, Retry, Success};

assert!(!Empty::<i32>.is_retry());
assert!(!Success(7).is_retry());

assert!(Retry::<i32>.is_retry());
fn success(self: Self) -> Option<T>

Returns the result of the operation, if successful.

Examples

use crossbeam_deque::Steal::{Empty, Retry, Success};

assert_eq!(Empty::<i32>.success(), None);
assert_eq!(Retry::<i32>.success(), None);

assert_eq!(Success(7).success(), Some(7));
fn or_else<F>(self: Self, f: F) -> Steal<T>
where
    F: FnOnce() -> Steal<T>

If no task was stolen, attempts another steal operation.

Returns this steal result if it is Success. Otherwise, closure f is invoked and then:

  • If the second steal resulted in Success, it is returned.
  • If both steals were unsuccessful but any resulted in Retry, then Retry is returned.
  • If both resulted in None, then None is returned.

Examples

use crossbeam_deque::Steal::{Empty, Retry, Success};

assert_eq!(Success(1).or_else(|| Success(2)), Success(1));
assert_eq!(Retry.or_else(|| Success(2)), Success(2));

assert_eq!(Retry.or_else(|| Empty), Retry::<i32>);
assert_eq!(Empty.or_else(|| Retry), Retry::<i32>);

assert_eq!(Empty.or_else(|| Empty), Empty::<i32>);

impl<T> Any for Steal<T>

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for Steal<T>

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for Steal<T>

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

impl<T> CloneToUninit for Steal<T>

unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)

impl<T> Debug for Steal<T>

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

impl<T> Freeze for Steal<T>

impl<T> From for Steal<T>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> FromIterator for Steal<T>

fn from_iter<I>(iter: I) -> Steal<T>
where
    I: IntoIterator<Item = Steal<T>>

Consumes items until a Success is found and returns it.

If no Success was found, but there was at least one Retry, then returns Retry. Otherwise, Empty is returned.

impl<T> Pointable for Steal<T>

unsafe fn init(init: <T as Pointable>::Init) -> usize
unsafe fn deref<'a>(ptr: usize) -> &'a T
unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T
unsafe fn drop(ptr: usize)

impl<T> RefUnwindSafe for Steal<T>

impl<T> Send for Steal<T>

impl<T> StructuralPartialEq for Steal<T>

impl<T> Sync for Steal<T>

impl<T> ToOwned for Steal<T>

fn to_owned(self: &Self) -> T
fn clone_into(self: &Self, target: &mut T)

impl<T> Unpin for Steal<T>

impl<T> UnsafeUnpin for Steal<T>

impl<T> UnwindSafe for Steal<T>

impl<T, U> Into for Steal<T>

fn into(self: Self) -> U

Calls U::from(self).

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

impl<T, U> TryFrom for Steal<T>

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

impl<T, U> TryInto for Steal<T>

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

impl<T: $crate::clone::Clone> Clone for Steal<T>

fn clone(self: &Self) -> Steal<T>

impl<T: $crate::cmp::Eq> Eq for Steal<T>

impl<T: $crate::cmp::PartialEq> PartialEq for Steal<T>

fn eq(self: &Self, other: &Steal<T>) -> bool

impl<T: $crate::marker::Copy> Copy for Steal<T>