foniod / redbpf

Rust library for building and running BPF/eBPF modules
Apache License 2.0
1.71k stars 136 forks source link

How to turn a map in to specific hashmap? #255

Open d0u9 opened 2 years ago

d0u9 commented 2 years ago
let map = Map::from_pin_file("pin_file").unwrap();
let hasmap = HashMap::<u32, u32>::new(&map).unwrap();

The hashmap internally references map, so I can't use hashmap alone without a valid map;

If there has a way like map::into::<HashMap>(), it will be more convenient:

let map = Map::from_pin_file("pin_file").unwrap();
let hasmap: HashMap<u32, u32> = map.try_into().unwrap();
rhdxmr commented 2 years ago

Hello @d0u9 It's really nice to see you again. Lucky day!

Thanks for your suggestion :+1: It looks like convenient and neat!