Skip to content

Instantly share code, notes, and snippets.

@kivikakk
Last active March 24, 2023 08:51
Show Gist options
  • Save kivikakk/ea0861d78ecaeb3a93f38b86a583b037 to your computer and use it in GitHub Desktop.
Save kivikakk/ea0861d78ecaeb3a93f38b86a583b037 to your computer and use it in GitHub Desktop.
pub fn rtrim_slice_a(i: &[u8]) -> &[u8] {
let mut len = i.len();
while len > 0 && isspace(i[len - 1]) {
len -= 1;
}
&i[..len]
}
pub fn rtrim_slice_b(mut i: &[u8]) -> &[u8] {
let mut len = i.len();
while len > 0 && isspace(i[len - 1]) {
i = &i[..len - 1];
len -= 1;
}
i
}
pub fn rtrim_slice_c(mut i: &[u8]) -> &[u8] {
let mut len = i.len();
while len > 0 && isspace(i[len - 1]) {
len -= 1;
}
i = &i[..len];
i
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment