StQueue

Trait StQueue 

Source
pub trait StQueue {
    type PushBack<Elem>: StQueue;
    type Front;
    type Back: StQueue;

    const LEN: usize;

    // Required methods
    fn push<Elem>(self, element: Elem) -> Self::PushBack<Elem>;
    fn front(&self) -> &Self::Front;
    fn front_mut(&mut self) -> &mut Self::Front;
    fn into_front(self) -> Self::Front;

    // Provided method
    fn len(&self) -> usize { ... }
}
Expand description

A strongly typed non-empty queue of heterogeneous elements.

There exist two implementations:

  • QueueSingle which includes exactly one element, and
  • Queue containing multiple (>=2) elements.

Also see define_queue macro to define a queue of heterogeneous elements all of which exhibit a common behavior, or implement a common set of traits. For more information, please see

Required Associated Constants§

Source

const LEN: usize

Number of elements in the queue.

Required Associated Types§

Source

type PushBack<Elem>: StQueue

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

Source

type Front

Type of the element at the front of the queue.

Source

type Back: StQueue

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

Required Methods§

Source

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

Pushes the element and returns the resulting queue.

Type of the resulting queue is known by the generic associated type Self::PushBack<Elem>.

§Examples
use orx_meta::queue::*;

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

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

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

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

Returns a reference to the element in the front of the queue.

§Examples
use orx_meta::queue::*;

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

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

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

let (flag, queue) = queue.pop();
assert_eq!(flag, true);
assert_eq!(queue.front(), &'x');

let (c, queue) = queue.pop();
assert_eq!(c, 'x');
assert_eq!(queue.front(), &"foo");

let s = queue.pop();
assert_eq!(s, "foo");
Source

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

Returns a mutable reference to the element in the front of the queue.

§Examples
use orx_meta::queue::*;

let mut queue = Queue::new(42).push(true).push('x');

*queue.front_mut() *= 2;
*queue.back_mut().front_mut() = false;
*queue.back_mut().back_mut().front_mut() = 'y';

assert_eq!(queue.as_tuple(), (&84, &false, &'y'));
Source

fn into_front(self) -> Self::Front

Consumes the queue and returns the element in the front of the queue.

§Examples
use orx_meta::queue::*;

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

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

let queue = Queue::new(42).push(true).push('x').push("foo".to_string());
let (num, queue) = queue.pop();
assert_eq!(num, 42);
let (flag, queue) = queue.pop();
assert_eq!(flag, true);

assert_eq!(queue.into_front(), 'x');

Provided Methods§

Source

fn len(&self) -> usize

Pushes the element and returns the resulting queue.

This method is provided for convention. Length of the queue is actually known by the constant Self::LEN.

§Examples
use orx_meta::queue::*;

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

let queue = Queue::new(42).push(true).push('x');
assert_eq!(queue.len(), 3);

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

let queue = queue.push(true);
assert_eq!(queue.len(), 3);

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<F> StQueue for QueueSingle<F>

Source§

const LEN: usize = 1usize

Source§

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

Source§

type Front = F

Source§

type Back = QueueSingle<F>

Source§

impl<F, B> StQueue for Queue<F, B>
where B: StQueue,

Source§

const LEN: usize

Source§

type PushBack<Elem> = Queue<F, <B as StQueue>::PushBack<Elem>>

Source§

type Front = F

Source§

type Back = B