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:
QueueSinglewhich includes exactly one element, andQueuecontaining 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
- examples 3_composition_idea and 5_solution_with_macros; and
- the article zero cost composition.
Required Associated Constants§
Required Associated Types§
Required Methods§
Sourcefn push<Elem>(self, element: Elem) -> Self::PushBack<Elem>
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"));Sourcefn front(&self) -> &Self::Front
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");Sourcefn front_mut(&mut self) -> &mut Self::Front
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'));Sourcefn into_front(self) -> Self::Front
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§
Sourcefn len(&self) -> usize
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.