Skip to content

Instantly share code, notes, and snippets.

@nyinyithann
Created January 18, 2019 06:58
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 nyinyithann/18ec619bf833d7e16b28582ae4d80c8e to your computer and use it in GitHub Desktop.
Save nyinyithann/18ec619bf833d7e16b28582ae4d80c8e to your computer and use it in GitHub Desktop.
update a particular slice of vector
let mut v = vec![1, 2, 3, 4, 5];
let r = v
.get_mut(1..=2)
.map(|x| x.iter_mut().for_each(|y| *y *= 10));
if r.is_some() {
println!("Succeed : {:?}", v);
} else {
println!("Not Succeed. Do something here.");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment