Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #![feature(nll)]
- fn get_or_insert<T: Eq>(vec: &mut Vec<T>, x: T) -> &mut T {
- {
- if let Some(y) = vec.iter_mut().find(|z| *z == &x) {
- return y
- }
- }
- {
- vec.push(x);
- vec.last_mut().unwrap()
- }
- }
- fn main() {}
Add Comment
Please, Sign In to add comment