macro_rules! collection {
    ($collection_type:ty) => { ... };
    ($collection_type:ty; $($key:expr => $value:expr),* $(,)?) => { ... };
    ($($key:expr => $value:expr),* $(,)?) => { ... };
    ($collection_type:ty; $($value:expr),* $(,)?) => { ... };
    ($($value:expr),* $(,)?) => { ... };
}
Expand description

Macro for initializing collections of any type. You must specify type of collection.

use std::collections::LinkedList;
use collection_literals::collection;

let linked_list: LinkedList<String> = collection! { "Hello".to_string(), "Hallo".to_string() };
assert_eq!(linked_list, LinkedList::from(["Hello".to_string(), "Hallo".to_string()]));

let linked_list = collection! { LinkedList::<&str>; "Bonjour", "Здравствуй" };
assert_eq!(linked_list, LinkedList::from(["Bonjour", "Здравствуй"]));