3 releases

Uses old Rust 2015

0.0.3 Jan 12, 2015
0.0.2 Jan 12, 2015
0.0.1 Jan 12, 2015

#1542 in Data structures

MIT license

3KB
73 lines

Construct

The vec! macro is pretty great, but it does only create Vecs. The construct! macro works for any type that implements iter::Extend, which is basically every collection!

Install

Cargo.toml

[dependencies]
construct = "*"

Example

#[macro_use]
extern crate construct;

use std::collections::HashMap;

fn main() {
    // Vector construction
    let v = construct!(Vec<_>, 1,2,3,4);
    assert_eq!(v, vec![1,2,3,4]);


    // Hashmap construction
    let m = construct!(HashMap<_,_>, (1, "hi"), (2, "bye"));

    let mut manual = HashMap::new();
    manual.insert(1, "hi");
    manual.insert(2, "bye");
    assert_eq!(m, manual);
}

No runtime deps