Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.