Created
April 15, 2019 16:09
-
-
Save rust-play/3292280a7aa81bbc203b7c5ca49ffef2 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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