[−][src]Macro sortedvec::sortedvec
A macro that defines a sorted vector data collection.
The generated struct is specific to the given keys and value types. To create the struct, four bits are required:
- a struct name,
- a value type,
- a key type. Since we will sort on these internally, this type must implement
Ord
, - a key extraction function of type
FnMut(&T) -> K
.
Matches the following input:
$(#[$attr:meta])*
$v:vis struct $name:ident {
fn $keyfn:ident ($i:ident : & $val:ty) -> $key:ty {
$keyexpr:expr
} $(,)?
}
Example
use sortedvec::sortedvec; /// Example key #[derive(PartialOrd, Ord, PartialEq, Eq, Debug, Clone, Copy)] pub struct K; /// Example value #[derive(Debug, Clone)] pub struct T { key: K, } sortedvec! { /// Sorted vector type that provides quick access to `T`s through `K`s. #[derive(Debug, Clone)] pub struct ExampleSortedVec { fn key(t: &T) -> K { t.key } } } let sv = ExampleSortedVec::default();