Skip to content

Instantly share code, notes, and snippets.

@killerswan
Created January 17, 2012 06:22
Show Gist options
  • Save killerswan/1625138 to your computer and use it in GitHub Desktop.
Save killerswan/1625138 to your computer and use it in GitHub Desktop.
reserve_empty
fn reserve_empty(nn: uint) -> str unsafe {
// start with something
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);
// make a string
let ss_ : str = unsafe::reinterpret_cast(vv);
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