12 releases (6 breaking)

0.8.3 Aug 20, 2022
0.8.0 Jul 25, 2022
0.6.2 Aug 3, 2020
0.6.1 Jul 27, 2020
0.6.0 Feb 11, 2019

#1480 in Data structures

Download history 19/week @ 2024-02-19 4/week @ 2024-02-26 172/week @ 2024-04-01

172 downloads per month

GPL-3.0+

22KB
465 lines

Cursed Collections

Collections that (seem) to break Rust safety.

  • SymbolTable: a memory-efficient set of String, where its members can be equality compared in constant time.
  • AppendOnlyVec: a sequence where elements can be appended even when you hold reference to previous elements.
  • LazyArray: an array where elements can be initialized at a later time, even where reference to other, initialized elements exist.

Safety

All collections in this crate are implemented with unsafe code. While I cannot be 100% sure the interface they offer is safe, I use the following techniques to increase my confidence.

Documentation

https://docs.rs/cursed-collections/


lib.rs:

Collections that (seem) to break Rust safety.

Mutating a Vec as we still hold references to it's element is forbidden by the borrow checker. The reason is that the vector could grow and move its elements to a new buffer. Our poor references would point then point to invalid memory. But, what if you know you don't need more elements? Vec doesn't know about it, so that is where cursed-collections comes to the rescue. This create offers different collections that offer an extremely narrow interface in exchange of doing things that are unusual in safe rust.

All collections in this crate are extremely cursed, yet respect the safety guaranties of Rust… assuming they are bug free!

Dependencies

~1MB
~15K SLoC