orlp / slotmap

Slotmap data structure for Rust
zlib License
1.13k stars 70 forks source link

Convert Keys to integer values for state/other APIs? #84

Closed Absolucy closed 2 years ago

Absolucy commented 2 years ago

I'm making an filesystem API, and SlotMap would be PERFECT for holding file handles and such.

However, I need to interface with non-Rust at some point, and pass some sort of file descriptor to it. This can be any sort of 64-bit integer - it doesn't need to be sequential or represent an actual index - but I don't see any way to do this with a SlotMap without like, leaking the Key and using a pointer to it as the fd, which is very unsafe and something I would very much not like to do.

A different way to explain it is that I want some sort of value that represents a key, which I can hand off to some API that doesn't know what a slotmap is or even what Rust is, and then said API can hand me back that value later, unchanged, which I can once again use as a key for the slotmap.

orlp commented 2 years ago

See KeyData::as_ffi.

Absolucy commented 2 years ago

Thanks!