multi_index_map icon indicating copy to clipboard operation
multi_index_map copied to clipboard

Embedded indexes

Open OvermindDL1 opened this issue 2 years ago • 1 comments

Say I have a mock-up like this:

struct Inner {
  blah: String,
  more: String
}

#[derive(MultiIndexMap)]
struct Outer {
  #[multi_index(hashed_unique)]
  id: String,
  #[multi_index(hashed_unique)]
  inner: Inner,
}

Except for the inner I'm not wanting 'it' to be hashed, rather I want the inner.blah to be hashed, what about being able to specify something like #[multi_index(hashed_unique, extract = "&self.inner.blah")] or so for an extraction expression (with the documentation of course that it should be fast and always return the same value). Maybe better belong on the struct itself like #[multi_index(indexes = {blah: "&self.inner.blah"})] or something like that so it can have a more appropriate index name as well.

In addition, an index embedded in an Option, like say inner: Option<Inner> it would be nice to be an optional unique index, so it's a unique index if it exists, but if it doesn't exist then it's not part of that index at all.

OvermindDL1 avatar Feb 22 '24 18:02 OvermindDL1

In addition, it also doesn't seem to use Borrow for the key value like std's HashMap and so forth use either, so we have to actually construct the full key instead of just a borrowed value of it (like being able to look up with a &str instead of a full heap allocated &String).

OvermindDL1 avatar Feb 22 '24 18:02 OvermindDL1

Hey, thanks I like the second idea! I've implemented the logic for this, and will make a release with this soon. Unfortunately I think the first idea adds too much complexity to this library, so I am closing this issue for now.

lun3x avatar Aug 15 '24 10:08 lun3x