Skip to content

Instantly share code, notes, and snippets.

@brson
Forked from killerswan/gist:1625138
Created January 17, 2012 06:24
Show Gist options
  • Save brson/1625144 to your computer and use it in GitHub Desktop.
Save brson/1625144 to your computer and use it in GitHub Desktop.
reserve_empty
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