Rust zero-copy types/keys cheatsheet

Hi,

I need to figure out some non-trivial handling of zero copy in a database API and I really had a hard time to wrap my head around it, so started from the basics and wrote myself a cheatsheet:

I'm planning to update the above links as I'm fixing the things that were pointed out.

I would appreciate any feedback. Am I doing it right? Any way to improve it? Naming OK? Anything else worth mentioning? I plan to polish it and publish somewhere for others to benefit.

1 Like

(Edited to remove outdated suggestions.)

Since these simply wrap other things that implement Borrow with no extra fields, all the deriving is okay, but you could mention Borrow's guarantees -- sometimes it's safer or necessary to implement the traits manually by dispatching to the "canonical borrowed form" implementation.[1]


  1. I mention it on this page which you can find by searching for "invariants" ↩ī¸Ž

1 Like

Updated. I also added a mention of benefits of using Arc<[u8]> and Arc<str>.

1 Like