Skip to content

Instantly share code, notes, and snippets.

@pzol
Created February 16, 2014 19:11
Show Gist options
  • Select an option

  • Save pzol/9039158 to your computer and use it in GitHub Desktop.

Select an option

Save pzol/9039158 to your computer and use it in GitHub Desktop.
fn pos(pos: int, len: uint) -> uint {
let ilen = len as int;
let result = match pos {
p if p < 0 && ilen + p < 0 => 0,
p if p < 0 => ilen + p,
p => p
} as uint;
result
}
#[test]
fn test_slice_pos(){
let p = pos(-1, 10);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment