QueueSingle

Struct QueueSingle 

Source
pub struct QueueSingle<Front> { /* private fields */ }
Expand description

A statically-typed queue containing exactly one element of type Front.

See also the other StQueue implementation Queue which can be created by pushing a second element to this queue.

Implementations§

Source§

impl<X1> QueueSingle<X1>

Source

pub fn into_tuple(self) -> X1

Converts the queue into its flat tuple representation.

§Examples
use orx_meta::queue::*;

let queue = Queue::new(42);
assert_eq!(queue.into_tuple(), 42);

let queue = Queue::new(42).push(true);
assert_eq!(queue.into_tuple(), (42, true));

let queue = Queue::new(42).push(true).push('x').push("foo");
assert_eq!(queue.into_tuple(), (42, true, 'x', "foo"));
Source

pub fn as_tuple(&self) -> &X1

Returns a flat tuple representation of references to elements in the queue.

§Examples
use orx_meta::queue::*;

let queue = Queue::new(42);
assert_eq!(queue.as_tuple(), &42);

let queue = Queue::new(42).push(true);
assert_eq!(queue.as_tuple(), (&42, &true));

let queue = Queue::new(42).push(true).push('x').push("foo");
assert_eq!(queue.as_tuple(), (&42, &true, &'x', &"foo"));
Source

pub fn as_tuple_mut(&mut self) -> &mut X1

Returns a flat tuple representation of mutable references to elements in the queue.

§Examples
use orx_meta::queue::*;

let mut queue = Queue::new(42);
let a = queue.as_tuple_mut();
*a *= 2;
assert_eq!(queue.as_tuple(), &84);

let mut queue = Queue::new(42).push(true);
let (a, b) = queue.as_tuple_mut();
*a *= 2;
*b = false;
assert_eq!(queue.as_tuple(), (&84, &false));

let mut queue = Queue::new(42).push(true).push('x').push("foo");
let (a, b, c, d) = queue.as_tuple_mut();
*a *= 2;
*b = false;
*c = 'y';
*d = "bar";
assert_eq!(queue.as_tuple(), (&84, &false, &'y', &"bar"));
Source§

impl<F> QueueSingle<F>

Source

pub fn new(element: F) -> Self

Creates a new statically-typed queue StQueue containing exactly one element.

Alternatively, we can use multiple element queue’s new. This is for convenience to allows to work with a single queue type while coding.

§Examples
use orx_meta::queue::*;

let queue: QueueSingle<u32> = QueueSingle::new(42);
assert_eq!(queue.len(), 1);
assert_eq!(queue.front(), &42);

// alternatively, we can use `Queue::new`:
let queue: QueueSingle<u32> = Queue::new(42);
assert_eq!(queue.len(), 1);
assert_eq!(queue.front(), &42);
Source

pub fn pop(self) -> F

Pops and returns the element in the front of this queue.

Since this element contains only one element, there is no remaining queue once the front is popped. Therefore, the return type is only the element rather than a tuple.

§Examples
use orx_meta::queue::*;

let queue: QueueSingle<u32> = QueueSingle::new(42);

let num = queue.pop();
assert_eq!(num, 42);

Trait Implementations§

Source§

impl<Front: Clone> Clone for QueueSingle<Front>

Source§

fn clone(&self) -> QueueSingle<Front>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<Front: Debug> Debug for QueueSingle<Front>

Source§

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

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

impl<Front: PartialEq> PartialEq for QueueSingle<Front>

Source§

fn eq(&self, other: &QueueSingle<Front>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<F> StQueue for QueueSingle<F>

Source§

const LEN: usize = 1usize

Number of elements in the queue.
Source§

type PushBack<Elem> = Queue<F, QueueSingle<Elem>>

Type of the queue obtained by adding an element of type Elem to this queue.
Source§

type Front = F

Type of the element at the front of the queue.
Source§

type Back = QueueSingle<F>

Type of the queue that would be obtained by popping the Front element of the queue.
Source§

fn push<Elem>(self, element: Elem) -> Self::PushBack<Elem>

Pushes the element and returns the resulting queue. Read more
Source§

fn front(&self) -> &Self::Front

Returns a reference to the element in the front of the queue. Read more
Source§

fn front_mut(&mut self) -> &mut Self::Front

Returns a mutable reference to the element in the front of the queue. Read more
Source§

fn into_front(self) -> Self::Front

Consumes the queue and returns the element in the front of the queue. Read more
Source§

fn len(&self) -> usize

Pushes the element and returns the resulting queue. Read more
Source§

impl<Front: Copy> Copy for QueueSingle<Front>

Source§

impl<Front: Eq> Eq for QueueSingle<Front>

Source§

impl<Front> StructuralPartialEq for QueueSingle<Front>

Auto Trait Implementations§

§

impl<Front> Freeze for QueueSingle<Front>
where Front: Freeze,

§

impl<Front> RefUnwindSafe for QueueSingle<Front>
where Front: RefUnwindSafe,

§

impl<Front> Send for QueueSingle<Front>
where Front: Send,

§

impl<Front> Sync for QueueSingle<Front>
where Front: Sync,

§

impl<Front> Unpin for QueueSingle<Front>
where Front: Unpin,

§

impl<Front> UnwindSafe for QueueSingle<Front>
where Front: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

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

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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, 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.