5个版本

使用旧的Rust 2015

0.1.5 2018年4月17日
0.1.4 2018年4月17日

#2426Rust模式

Download history 379/week @ 2024-03-13 191/week @ 2024-03-20 273/week @ 2024-03-27 201/week @ 2024-04-03 248/week @ 2024-04-10 307/week @ 2024-04-17 157/week @ 2024-04-24 432/week @ 2024-05-01 215/week @ 2024-05-08 362/week @ 2024-05-15 215/week @ 2024-05-22 226/week @ 2024-05-29 232/week @ 2024-06-05 174/week @ 2024-06-12 217/week @ 2024-06-19 169/week @ 2024-06-26

831 每月下载量
4 crates 中使用

GPL-3.0 许可

15KB

rust-dict

实现真正关联数组的仓库,也称为字典。

use dict::{ Dict, DictIface };

//create a dictionary of strings
let mut dict = Dict::<String>::new();
assert_eq!( dict.is_empty(), true );
assert_eq!( dict.len(), 0 );

// add an element "val" indexed by the key "key"
assert_eq!( dict.add( "key".to_string(), "val".to_string() ), true );
assert_eq!( dict.is_empty(), false );
assert_eq!( dict.len(), 1 );

// keys must be unique
assert_eq!( dict.add( "key".to_string()      , "other_val".to_string() ), false );
assert_eq!( dict.len(), 1 );
assert_eq!( dict.add( "other_key".to_string(), "other_val".to_string() ), 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()
assert_eq!( dict.get( "key" ).unwrap(), "val" );
assert_eq!( dict.contains_key( "key" ), true );
assert_eq!( dict.remove_key( "key" ).unwrap(), "val" );
assert_eq!( dict.contains_key( "key" ), false );

ownyourbits.com

crates.io

无运行时依赖