Crate trait_based_collection
source · [−]Expand description
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: AFIFOdata structure based on linked nodes.Deque: AFIFOandLIFOdata structure based on linked nodes.CircularDeque: AFIFOandLIFOdata structure based on a circular array.Stack: ALIFOdata structure based on a linked nodes.ArrayStack: ALIFOdata structure based on a fixed size array.BinaryHeap: APriorityQueuedata 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 bothFIFOandLIFO.
The crate also contains the following macros for easily creating data structures:
queue!: A macro that creates aQueuedata structure.deque!: A macro that creates aDequedata structure.circular_deque!: A macro that creates aCircularDequedata structure.stack!: A macro that creates aStackdata structure.array_stack!: A macro that creates aArrayStackdata structure.binary_heap!: A macro that creates aBinaryHeapdata 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!();
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));
}Re-exports
pub use self::collection::Collection;pub use self::collection::ExpansionMode;pub use self::collection::FixedSizeCollection;pub use self::collection::Iterators;pub use self::priority_queue::BinaryHeap;pub use self::queue::CircularDeque;pub use self::queue::Deque;pub use self::queue::DequeCollection;pub use self::queue::Queue;pub use self::stack::ArrayStack;pub use self::stack::Stack;Modules
Traits, helpers, and type definitions for the collection framework.
A collection of all the procedural macros used in this crate. This macros can be divided into
two categories:
A module that contains all the traits that are used in this crate. This module is meant to be
used as a total import using the
prelude::* syntax. The module also contains a macro that
creates the prelude for this crate allowing to also import the macros in this crate.A collection of different implementations of priority queues. The priority queue is a data
structure that allows you to insert elements into it and then retrieve them in order of
priority. The priority is determined through a comparator function that is passed to the
priority queue.
A collection of different implementations of a queue based on the
FIFO principle. There some
structs that implement the DequeCollection trait, which allows them to be used as both
LIFO and FIFO queues.A collection of different implementations of a stack based on the
LIFO principle.Macros
Creates a
ArrayStack containing the arguments.Creates a
BinaryHeap containing the arguments.Creates a
CircularDeque containing the arguments.Creates the prelude for this crate. This macro is meant to a substitute for the
use trait_based_collection::prelude::* statement if the macros in this crate are also needed.