A collection of data structures that implement the [Collection
] trait, allowing for a common
interface for all the data structures in this crate. This crate is intended to be a proof of
concept a common interface for all the data structures in Rust. Not all the data structures
are implemented in this crate, but the ones that are implemented are:
- [
Queue
]: AFIFO
data structure based on linked nodes. - [
Deque
]: AFIFO
andLIFO
data structure based on linked nodes. - [
CircularDeque
]: AFIFO
andLIFO
data structure based on a circular array. - [
Stack
]: ALIFO
data structure based on a linked nodes. - [
ArrayStack
]: ALIFO
data structure based on a fixed size array. - [
BinaryHeap
]: APriorityQueue
data structure based on a binary heap.
The crate also contains the following traits:
- [
Collection
]: A trait that defines the common interface for all the data structures in this crate. - [
FixedSizeCollection
]: A trait that defines the common interface for all the data structures in this crate that have a fixed size. - [
Iterators
]: A trait that defines the common interface for all the iterators in this crate. - [
DequeCollection
]: A trait that defines the common interface for all the data structures in this crate that are bothFIFO
andLIFO
.
The crate also contains the following macros for easily creating data structures:
- [
queue!
]: A macro that creates a [Queue
] data structure. - [
deque!
]: A macro that creates a [Deque
] data structure. - [
circular_deque!
]: A macro that creates a [CircularDeque
] data structure. - [
stack!
]: A macro that creates a [Stack
] data structure. - [
array_stack!
]: A macro that creates a [ArrayStack
] data structure. - [
binary_heap!
]: A macro that creates a [BinaryHeap
] data structure.
The crate also contain extra modules for creating new data structures and for creating macros
that can be used to add functionality to the data structures in this crate. For more information
about these modules, see the documentation of [macros
].
Example
use trait_based_collection::{import, Deque};
import!();
# fn main() {
let mut deque = deque![1, 2, 3];
for i in 4..=10 {
deque.add(i);
}
for i in 1..=10 {
assert_eq!(deque.remove(), Some(i));
}
# }