Skip to content

TyOverby/construct

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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);
}

About

A rust macro for building container literals.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages