macro_rules! deque {
(
$( $key: expr ),* $( , )?
) => { ... };
}Expand description
Creates a VecDeque from a list of elements.
The deque macro allows for the convenient creation of a VecDeque with initial elements.
Elements passed to the macro are automatically converted into the deque’s element type
using .into(), enabling the use of literals or values of different, but convertible types.
Note: The deque macro relies on the .into() method to convert each element into the target type
of the VecDeque. This means that the elements must be compatible with the Into< T > trait for the
type T used in the VecDeque.
§Origin
This collection is reexported from alloc.
§Syntax
The macro can be called with a comma-separated list of elements. A trailing comma is optional.
// VecDeque of i32
let vd1 = deque!( 1, 2, 3, 4, 5 );
// VecDeque of String
let vd2 = deque!{ "hello", "world", "rust" };
// With trailing comma
let vd3 = deque!( 1.1, 2.2, 3.3, );§Parameters
$( $key: expr ),* $( , )?: A comma-separated list of elements to insert into theVecDeque. Each element can be of any type that implements theInto< T >trait, whereTis the type stored in theVecDeque.
§Returns
Returns a VecDeque containing all the specified elements. The capacity of the deque is
automatically determined based on the number of elements provided.
§Example
Basic usage with integers :
let vd: VecDeque< i32 > = deque!( 1, 2, 3 );
assert_eq!( vd.front(), Some( &1 ) ); // The first element is 1
assert_eq!( vd.back(), Some( &3 ) ); // The last element is 3§Example
Creating a VecDeque of &str from string literals :
let fruits = deque!{ "apple", "banana", "cherry" };
assert_eq!( fruits.front(), Some( &"apple" ) ); // The first element
assert_eq!( fruits.back(), Some( &"cherry" ) ); // The last element