eclectic 0.6.0

Experimental collection traits.
Documentation

Collection traits for generic programming.

Code that uses these traits should use them as generally as possible. For example, consider the following function that fills a map with default values for some keys:

use eclectic::map::*;

fn fill<M, K>(keys: K) -> M
where
    M: Default + Map,
    K: IntoIterator<Item = M::Key>,
    M::Value: Default,
{
    let mut map = M::default();
    for key in keys { map.insert(key, M::Value::default()); }
    map
}

Map is a convenient shorthand for code that uses multiple map APIs, but this code only ever calls insert, so it could be rewritten more generally as:

use eclectic::map;

fn fill<M, K>(keys: K) -> M
where
    M: Default + map::Insert,
    K: IntoIterator<Item = M::Key>,
    M::Value: Default,
{
    let mut map = M::default();
    for key in keys { map.insert(key, M::Value::default()); }
    map
}