Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fn main() {
- let x = 3;
- let y = x;
- let mut v = vec![2, 4];
- let w = v.clone();
- println!("Hello, world! {} {}, {:?} {:?}", x, y, v, w);
- v.push(4);
- println!("v is now {:?}", v);
- println!("w is now {:?}", w);
- println!("max of v is {}", max(&v).expect("Expected a max"));
- }
- fn max(v: &[i32]) -> Option<i32>
- {
- if v.len() == 0 {
- return None;
- }
- let mut i = v[0];
- for &j in v {
- if j > i {
- i = j;
- }
- }
- Some(i)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement