Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fn main() {
- let v = vec![1, 2, 3];
- // Borrow v to sum
- let s = sum(& v);
- println!("{}", s);
- // v is still accessible
- println!("{}", v[1]);
- }
- fn sum(v: &Vec<i32>) -> i32 {
- let mut sum = 0;
- for e in v.iter() {
- sum += *e;
- }
- sum
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement