Skip to content

Instantly share code, notes, and snippets.

@buzztaiki
Created September 27, 2020 16: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 buzztaiki/94134a6f78be93df18fad46175c1eba3 to your computer and use it in GitHub Desktop.
Save buzztaiki/94134a6f78be93df18fad46175c1eba3 to your computer and use it in GitHub Desktop.
Rustの式と文
// セミコロンは文を区切る。
fn x() -> i32 {
let x = 10;
return x;
}
// セミコロンがないと式になる。式は値を返す。文全体は式になる。
fn y() -> i32 {
let x = 10;
x
}
// 文の値は () になる。よって 10; とすると返値のエラーとなる。
// fn z() -> i32 {
// 10;
// }
fn main() {
println!("{}", x());
println!("{}", y());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment