Trait queues::IsQueue
[−]
[src]
pub trait IsQueue<T: Clone> { fn add(&mut self, val: T) -> Result<Option<T>, &str>; fn remove(&mut self) -> Result<T, &str>; fn peek(&self) -> Result<T, &str>; fn size(&self) -> usize; }
Defines methods that would be expected on a queue data structure
Required Methods
fn add(&mut self, val: T) -> Result<Option<T>, &str>
Adds a new value to a queue
Parameters
val
: Value to add to the queue
Returns
Ok(_)
: If the element add was successful.Some(T)
: If adding an element resulted in the removal of an existing one (in the case of a circular buffer, for instance)None
: Adding an element did not return any value
Error
: If the element add was unsuccessful
Errors
Attempting to add an element to a full queue that does not allow for overflow will return an error.
fn remove(&mut self) -> Result<T, &str>
Removes an element from the queue and returns it
For queues with default values, removing an element will add a new default value into the queue.
Returns
Ok(T)
: The oldest element in the queueError
Errors
Returns an error if an attempt is made to remove an element from an empty queue
fn peek(&self) -> Result<T, &str>
Peek at the head of the queue
Returns
Ok(T)
: The next element scheduled for removal from the queueError
Errors
Returns an error if an attempt is made to peek into an empty queue
fn size(&self) -> usize
Gets the size of the queue
Returns
The number of elements in the queue. Note, this includes default
values when specified, which means that the size
of a queue with
default values should always be equal to its capacity