orlp / slotmap

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

Provide more terse `Debug` implementation for keys. #32

Closed olson-sean-k closed 5 years ago

olson-sean-k commented 5 years ago

KeyData and containing types like DefaultKey derive a Debug implementation. This allows keys to be printed, but includes superfluous text. For example, a DefaultKey may be printed as DefaultKey(KeyData { idx: 0, version: 1 }).

This change provides a custom Debug implementation for KeyData that prints 0v1 instead. For containing key types like DefaultKey, the output looks like DefaultKey(0v1).

This change also introduces an into_key_data function on generated key types. This allows user code to more easily extract KeyData for debugging purposes. For example, this could be used for Debug implementations for downstream key abstractions.

orlp commented 5 years ago

I don't particularly see the reason for into_key_data. I think KeyData::from(key) or just key.into() when type inference allows it is sufficient. Please update your pull request to remove that and I'll accept it.

olson-sean-k commented 5 years ago

Please update your pull request to remove that and I'll accept it.

Sounds good to me. I've removed into_key_data. Let me know if you'd like me to squash the commits.