Skip to content

Instantly share code, notes, and snippets.

@jmeggitt
Last active July 30, 2022 23:54
Show Gist options
  • Save jmeggitt/ec507341331caeebaa6f48979228e38b to your computer and use it in GitHub Desktop.
Save jmeggitt/ec507341331caeebaa6f48979228e38b to your computer and use it in GitHub Desktop.
A cheat sheet of data structures provided by different crates in Rust for different

(Incomplete)

Crate Type Owned Sync Send Mutable Inner Mutability Description
bytes Bytes ❌* ✔️ ✔️ Provides zero-copy sharing of byte buffers. A group of Bytes/BytesMut can share ownership of the underlying buffer similar to an Arc.
bytes BytesMut ✔️* ✔️ ✔️ ✔️ Similar to Bytes in functionality, but for exclusive ownership of a portion of a buffer.
smallvec SmallVec<[T;N]> ✔️ ✔️ Functions the same as a regular Vec<T>, but stores the first N elements on the stack before allocating space on the heap.
generic-array GenericArray<T, N> ✔️ ✔️ An array of T whos length is determined by a length placeholder type (Ex: U0, U1, U2, etc). A useful alternative to const generics which can allow for better control of the length via traits. Once const generic support improves, this might become deprecated.

(TODO, currenty missing a lot of stuff)

Key
✔️ Yes, always
Dependent on contents
No
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment