Skip to content

Instantly share code, notes, and snippets.

@jlowry
Created October 8, 2020 20:34
Show Gist options
  • Save jlowry/d0c195be09cfb2c91f6408d1e3ea7130 to your computer and use it in GitHub Desktop.
Save jlowry/d0c195be09cfb2c91f6408d1e3ea7130 to your computer and use it in GitHub Desktop.
Genna's efficient tuple lookups with some unsafe-but-not-really memory manipulation.
// It copies only the string headers (no more expensive than two &str copies)
// It's unsafe but only a little type trick to make the HashMap work properly with tuple keys
let owned: ManuallyDrop<(String, String)> =
ManuallyDrop::new(unsafe {(mem::read(my_ref.0), mem::read(my_ref.1))});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment