pub trait IsQueue<T: Clone> {
// Required methods
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;
}
Expand description
Defines methods that would be expected on a queue data structure
Required Methods§
Sourcefn add(&mut self, val: T) -> Result<Option<T>, &str>
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.