-
-
Save brson/1625144 to your computer and use it in GitHub Desktop.
reserve_empty
This file contains 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
fn reserve_empty(nn: uint) -> str unsafe { | |
// start with a null-terminated 0-length string | |
let ss = ""; | |
// make a vector | |
let vv: [u8] = unsafe::reinterpret_cast(ss); | |
unsafe::leak(ss); | |
// expand it to size + \0 | |
vec::reserve(vv, nn+1u); | |
// forget the vector | |
unsafe::leak(vv); | |
// return it | |
ret ss; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment