dlist

Macro dlist 

Source
macro_rules! dlist {
    (
    $( $key : expr ),* $( , )?
  ) => { ... };
}
Expand description

Creates a Vec from a list of elements.

The vec macro simplifies the creation of a Vec with initial elements.

§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.

// Vec of i32
let vec1 = vec!( 1, 2, 3, 4, 5 );

// Vec of &str
let vec2 = vec!{ "hello", "world", "rust" };

// With trailing comma
let vec3 = vec!( 1.1, 2.2, 3.3, );

§Parameters

  • $( $key : expr ),* $( , )?: A comma-separated list of elements to insert into the Vec. Each element can be of any type that implements the Into<T> trait, where T is the type stored in the Vec.

§Returns

Returns a Vec containing all the specified elements. The capacity of the vector is automatically determined based on the number of elements provided.

§Example

Basic usage with integers:

let vec = vec!( 1, 2, 3 );
assert_eq!( vec[ 0 ], 1 );
assert_eq!( vec[ 1 ], 2 );
assert_eq!( vec[ 2 ], 3 );

§Example

Creating a Vec of &str from string literals:

let mixed = vec!{ "value", "another value" };
assert_eq!( mixed[ 0 ], "value" );
assert_eq!( mixed[ 1 ], "another value" );