Skip to content

Instantly share code, notes, and snippets.

@brson
Created December 10, 2012 23:09
Show Gist options
  • Save brson/4254210 to your computer and use it in GitHub Desktop.
Save brson/4254210 to your computer and use it in GitHub Desktop.
pub fn shift<T>(v: &mut ~[T]) -> T {
let ln = v.len();
assert (ln > 0);
let mut vv = ~[];
*v <-> vv;
unsafe {
let mut rr;
{
let vv = vec::raw::to_ptr(vv);
rr = /*move*/ *vv; // removing this move breaks things
for uint::range(1, ln) |i| {
let r = move *ptr::offset(vv, i);
v.push(move r);
}
}
vec::raw::set_len(&mut vv, 0);
move rr
}
}
fn main() {
let mut i = ~[~1];
shift(&mut i);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment