stable-vec icon indicating copy to clipboard operation
stable-vec copied to clipboard

Missing trait implementations

Open Luro02 opened this issue 5 years ago • 1 comments

There are some traits missing for StableVec that could be implemented.

Important traits:

  • [ ] Hash
  • [ ] Ord
  • [ ] Write
  • [ ] RefUnwindSafe
  • [ ] UnwindSafe
  • [ ] PartialOrd

serdes Serialize and Deserialize could also be supported?

Convenience:

  • [ ] From<BTreeMap<usize, T>>
  • [ ] Extend<&'a T>
  • [ ] From<&'_ str>
  • [ ] From<BinaryHeap<T>>
  • [ ] From<Box<[T]>>
  • [ ] From<CString>
  • [ ] From<String>
  • [ ] From<Cow<'a, [T]>>
  • [ ] PartialEq<&'_ [B; N]>
  • [ ] PartialEq<&'_ mut [B]>
  • [ ] PartialEq<[B; N]>

Luro02 avatar Apr 18 '20 07:04 Luro02

This crate is deliberately low level; API convenience is not particularly high on the priority list. Of course, if adding an impl makes sense and has a low maintenance cost, we can add it.

Ord, PartialOrd

I think it's not completely obvious how those would be implemented. Just use the filled slots for comparison? This could easily lead to confusion and subtle bugs. I think I prefer not to implement those.

Hash

Since StableVec implements PartialEq, we need to uphold the property k1 == k2 -> hash(k1) == hash(k2). And our PartialEq impl currently does this: "empty slots, capacity, next_push_index and the indices of elements are all checked. In other words: all observable properties of the stable vectors need to be the same for them to be equal."

So implementing Hash might be non-trivial.

RefUnwindSafe and UnwindSafe

Those are in a strange place right now. I already read proposals to deprecated them.

LukasKalbertodt avatar May 23 '20 10:05 LukasKalbertodt