Logo

Programming-Idioms

History of Idiom 135 > diff from v14 to v15

Edit summary for version 15 by GobbleCock:
New Rust implementation by user [GobbleCock]

Version 14

2018-03-27, 21:52:12

Version 15

2018-06-12, 20:44:57

Idiom #135 Remove item from list, by its value

Remove at most 1 item from list items, having value x.
This will alter the original list or return a new list, depending on which is more idiomatic. If there are several occurrences of x in items, remove only one of them.

Idiom #135 Remove item from list, by its value

Remove at most 1 item from list items, having value x.
This will alter the original list or return a new list, depending on which is more idiomatic. If there are several occurrences of x in items, remove only one of them.

Code
if let Some(i) = items.first(&x) {
    items.remove(i);
}
Doc URL
https://doc.rust-lang.org/stable/std/vec/struct.Vec.html#method.remove