Crate implementing real associative arrays, also known as dictionaries.
``` use dict::{ Dict, DictIface };
//create a dictionary of strings
let mut dict = Dict::
// add an element "val" indexed by the key "key" asserteq!( dict.add( "key".tostring(), "val".tostring() ), true ); asserteq!( dict.isempty(), false ); asserteq!( dict.len(), 1 );
// keys must be unique asserteq!( dict.add( "key".tostring() , "otherval".tostring() ), false ); asserteq!( dict.len(), 1 ); asserteq!( dict.add( "otherkey".tostring(), "otherval".tostring() ), true ); assert_eq!( dict.len(), 2 );
// we can iterate just like an array for o in &dict { println!( "{} - {}", o.key, o.val ); } dict.iter().for_each( |o| println!( "{} - {}", o.key, o.val ) );
// we can access the value by its key string with get() asserteq!( dict.get( "key" ).unwrap(), "val" ); asserteq!( dict.containskey( "key" ), true ); asserteq!( dict.removekey( "key" ).unwrap(), "val" ); asserteq!( dict.contains_key( "key" ), false ); ```