macro_rules! llist {
(
$( $key: expr ),* $( , )?
) => { ... };
}Expand description
Function and structures to work with collections.
Creates a LinkedList from a llist of elements.
The llist macro facilitates the creation of a LinkedList with initial elements.
§Origin
This collection is reexported from alloc.
§Syntax
The macro can be called with a comma-separated llist of elements. A trailing comma is optional.
// LinkedList of i32
let lst1 = llist!( 1, 2, 3, 4, 5 );
// LinkedList of &str
let lst2 = llist!{ "hello", "world", "rust" };
// With trailing comma
let lst3 = llist!( 1.1, 2.2, 3.3, );§Parameters
$( $key: expr ),* $( , )?: A comma-separated llist of elements to insert into theLinkedList. Each element can be of any type that implements theInto< T >trait, whereTis the type stored in theLinkedList.
§Returns
Returns a LinkedList containing all the specified elements. The capacity of the llist is
dynamically adjusted based on the number of elements provided.
§Example
Basic usage with integers :
let lst = llist!( 1, 2, 3 );
assert_eq!( lst.front(), Some( &1 ) ); // The first element is 1
assert_eq!( lst.back(), Some( &3 ) ); // The last element is 3§Example
Creating a LinkedList of &str from string literals :
let fruits = llist!{ "apple", "banana", "cherry" };
assert_eq!( fruits.front(), Some( &"apple" ) ); // The first element
assert_eq!( fruits.back(), Some( &"cherry" ) ); // The last element