#dictionary #key-value #hash-map #index-map #std

dictionary_rs

dictionary是rust-lang的关键值类型

2个版本

0.2.1 2022年11月12日
0.2.0 2022年11月12日

#5 in #index-map

MIT/Apache

13KB
312 行(代码,不包括注释)

Rust字典类型

使用indexmap实现关键值类型处理

示例

在Cargo.toml中添加此行

dictionary_rs = "0.1.0"

from_iter_main.rs

extern crate dictionary_rs as dictionary;
use dictionary::Dictionary;

fn main() {
    let tuples: Vec<(u8, u8)> = vec![(1, 3), (5, 7)];
    let _d: Dictionary<u8, u8> = Dictionary::from_iter(tuples.iter());
    let tuples_array: Vec<(u8, [u8; 5])> = vec![(2, [3, 4, 5, 6, 7]),(8,[9,10,11,12,13])];
    let _d_array: Dictionary<u8, [u8; 5]> = Dictionary::from_iter(tuples_array.iter());

    println!("{}",*_d.get(&5).unwrap());
    println!("{:?}",*_d_array.get(&8).unwrap());
}

insert.rs

extern crate dictionary_rs as dictionary;
use dictionary::Dictionary;
fn main() {
    let mut _d: Dictionary<u8, u8> = Dictionary::new();
    _d.insert(1, 2);
    _d.insert(3, 4);

    println!("{}", *_d.get(&3).unwrap());
}

依赖项

~1MB
~16K SLoC