Last active
August 29, 2015 14:11
-
-
Save stouset/fb0fe244a849c600e9a9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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