Skip to content

Instantly share code, notes, and snippets.

@noemk2
Created December 22, 2022 20:16
Show Gist options
  • Select an option

  • Save noemk2/d42563b23ce4fba7a0c94b61176ca429 to your computer and use it in GitHub Desktop.

Select an option

Save noemk2/d42563b23ce4fba7a0c94b61176ca429 to your computer and use it in GitHub Desktop.
pop in rust
#![allow(unused)]
fn main() {
let rust = "Rust";
let popped = &rust[..rust.len() - 1];
println!("{}", popped);
let poo = {
let mut chars = rust.chars();
chars.next_back();
chars.as_str()
};
assert_eq!(popped, "Rus");
assert_eq!(poo, "Rus");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment