Skip to content

Instantly share code, notes, and snippets.

@stouset
Last active August 29, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stouset/fb0fe244a849c600e9a9 to your computer and use it in GitHub Desktop.
Save stouset/fb0fe244a849c600e9a9 to your computer and use it in GitHub Desktop.
/* current API */
{
let secret = Secret::new( /* bytes */ );
secret.read(|slice| { println!("{}", slice) });
}
/* desired API */
{
let secret = Secret::new( /* bytes */ );
let slice = secret.read(); // when slice goes out of scope, memory is re-protected
println!("{}", slice);
}
/* especially awesome API */
{
let slice;
{
let secret = Secret::new( /* bytes */ );
slice = secret.read();
}
/* compile error, since slice outlives the secret */
println!("{}", slice);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment