Macro velcro::hash_set_from

source ·
hash_set_from!() { /* proc-macro */ }
Expand description

An initializer for HashSet that works the same as hash_set! except that values can be of any type that can be converted into the collection’s item type via an Into implementation.

The type of the item must be known at compile time, and usually this means an explicit type annotation is required.

Usage

use velcro::{hash_set, hash_set_from};

#[derive(Debug, PartialEq, Eq, Hash)]
struct Foo(u64);

impl From<u64> for Foo {
    fn from(other: u64) -> Self {
        Foo(other)
    }
}

let foos: HashSet<Foo> = hash_set_from![1, 2, Foo(3), ..(4..=6), 7];
assert_eq!(foos, hash_set![Foo(1), Foo(2), Foo(3), Foo(4), Foo(5), Foo(6), Foo(7)]);