Elektrine lite

← Feed

@rain@hachyderm.io

Post #645386

2025-05-21 21:21 UTC

new #rustlang crate drop: iddqd! ID-based maps where keys are borrowed from values. Four maps are included: IdOrdMap, IdHashMap, a bijective (1:1) BiHashMap and a trijective (1:1:1) TriHashMap. At Oxide we've found this pattern to be extraordinarily useful. iddqd is no-std compatible, too! https://docs.rs/iddqd

Replies (13)

  • @slatian@pleroma.envs.net 2025-05-21 21:40

    @rain This looks like what I was searching for my database cache (mapping forward and back between something stringy and a number)

    Open ##1101010

  • @rain@hachyderm.io 2025-05-21 21:23

    This is the repo -- quite happy with all the testing! https://github.com/oxidecomputer/iddqd

    Open ##2489037

  • @crowbriarhexe@tech.lgbt 2025-05-21 21:23

    @rain@hachyderm.io Help, I installed this crate and my eyes turned gold! 😅

    Open ##2489038

  • @skinnylatte@hachyderm.io 2025-05-21 21:24

    @rain@hachyderm.io relevant to your interests @wilson@hachyderm.io

    Open ##2489039

  • @noratrieb@hachyderm.io 2025-05-21 21:29

    @rain@hachyderm.io this is awesome, I've definitely done things like this before many times.. in my cases the usage was simple enough that a normal map worked fine, but this is nicer even then

    Open ##2489040

  • @rukai@hachyderm.io 2025-05-21 21:33

    @rain@hachyderm.io this looks so good. I have definitely needed this in the past.

    Open ##2489041

  • @rain@hachyderm.io Ooh neat. I was wanting something like this for years. I would have preferred if the map takes a function to extract the key from the value, though, rather than requiring the value to implement a trait. Then I could, for example, index `User`s by both `name` and `age` (as separate `IdHashMap`s), which unless I'm mistaken would be difficult with this trait-based design.

    Open ##2489042

  • @brianm@hachyderm.io 2025-05-21 22:49

    @rain@hachyderm.io oh. OH! This is cool. I didn’t know I wanted this until now!

    Open ##2489046

  • @zkat@toot.cat 2025-05-21 22:59

    @rain@hachyderm.io holy cow this is cool!!

    Open ##2489048

  • @anselmschueler@ieji.de 2025-05-21 23:50

    @rain@hachyderm.io Is the upcast method just a way to reify the fact that it's covariant?

    Open ##2489049

  • @hermitcl@aus.social 2025-05-22 00:57

    @rain@hachyderm.io I mean, I have no real idea what this does, but I love the name (am I showing my age?)

    Open ##2489052

  • @weiznich@social.weiznich.de 2025-05-22 06:52

    @rain@hachyderm.io Great Work. That seems like a really nice crate for creating maps from database types. Given that you might consider adding a wild card impl for IdHashItem based on diesels Identifiable trait so that you get these impls for free for all database structs. (Obviously that's something you want to put behind a feature flag)

    Open ##2489055

  • @skade@hachyderm.io 2025-09-26 20:33

    @rain@hachyderm.io needs a datastore implemented in it called idkva.

    Open ##2489056