macro_rules! circular_deque {
() => { ... };
($($elem:expr),*) => { ... };
($elem:expr; $n:expr) => { ... };
}
Expand description
Creates a CircularDeque
containing the arguments.
circular_deque! allows CircularDeque
s to be defined with the same syntax as array expressions.
There are three forms of this macro:
- Create an empty
CircularDeque
:
use trait_based_collection::{prelude::*, CircularDeque, circular_deque};
let mut c = circular_deque![];
c.add(1);
assert_eq!(c.remove(), Some(1));
- Create a
CircularDeque
containing a given list of elements:
use trait_based_collection::{prelude::*, CircularDeque, circular_deque};
use std::iter::zip;
let c1 = circular_deque![1, 2, 3];
let c2 = CircularDeque::from_iter([1, 2, 3].into_iter());
for (actual, expected) in zip(c1, c2) {
assert_eq!(actual, expected);
}
- Create a
CircularDeque
from a given element and size:
use trait_based_collection::{prelude::*, CircularDeque, circular_deque};
use std::iter::zip;
let c1 = circular_deque![1; 3];
let c2 = CircularDeque::from_iter([1; 3].into_iter());
for (actual, expected) in zip(c1, c2) {
assert_eq!(actual, expected);
}
Note that unlike array expressions this syntax supports all elements
which implement Clone
and the number of elements doesn’t have to be
a constant.
This will use clone
to duplicate an expression, so one should be careful
using this with types having a nonstandard Clone
implementation. For
example, circular_deque![Rc::new(1); 5]
will create a vector of five references
to the same boxed integer value, not five references pointing to independently
boxed integers.