Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created April 15, 2019 16:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rust-play/3292280a7aa81bbc203b7c5ca49ffef2 to your computer and use it in GitHub Desktop.
Save rust-play/3292280a7aa81bbc203b7c5ca49ffef2 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
fn main() {
#[derive(Eq, PartialEq, Clone)]
struct A { a: Vec<u8> }
let a = A { a: vec![1, 2, 3] };
let c = A { a: vec![1, 2, 3] };
let mut b = vec![a.clone(), a.clone(), a];
// if let Some(pos) = b.iter().position(|elt| elt == c) { // This will error out
if let Some(pos) = b.iter().position(|elt| *elt == c) {
let _ = b.remove(pos);
b.push(c);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment