Skip to content

Latest commit

 

History

History
53 lines (41 loc) · 531 Bytes

课后4.md

File metadata and controls

53 lines (41 loc) · 531 Bytes

语句和表达式

语句

  1. 🌟🌟
// 使用两种方法让代码工作起来
fn main() {
   let v = {
       let mut x = 1;
       x += 2
       x
   };

   assert_eq!(v, 3);
}

fn main() {
   let v = {
       let mut x = 1;
       x += 2;
   };

   assert_eq!(v, ());
}
  1. 🌟🌟
fn main1() {
   let v = {
        let x = 3;
        x
   }

   assert!(v == 3);
}
  1. 🌟
fn main() {
    let s = sum(1 , 2);
    assert_eq!(s, 3);
}

fn sum(x: i32, y: i32) -> i32 {
    x + y
}