Hello World

ここでは伝統的な"Hello World!"プログラムのソースを紹介します。 

// This is a comment, and is ignored by the compiler
// You can test this code by clicking the "Run" button over there ->
// or if you prefer to use your keyboard, you can use the "Ctrl + Enter" shortcut
// これはコメントです。コンパイラによって無視されます。
// 右にある「Run」ボタンからこのコードをテストできます。
// キーボードを使いたければ「Ctrl + Enter」もOKです。

// This code is editable, feel free to hack it!
// You can always return to the original code by clicking the "Reset" button ->
// このコードは編集可能です。ぜひハックしてみましょう!
// 「Reset」ボタンでいつでも元のコードに戻すことができます ->

// This is the main function
// main関数です
fn main() {
    // Statements here are executed when the compiled binary is called
    // コンパイルされたバイナリが実行されるとこの関数が呼び出されます

    // Print text to the console
    // コンソールに文字列を出力する
    println!("Hello World!");
}

println!は文字列をコンソールにプリントするための マクロ です。

バイナリファイルはrustcと呼ばれるRustのコンパイラを用いて生成することができます。

$ rustc hello.rs

するとhelloという名前の実行可能なバイナリファイルができます。

$ ./hello
Hello World!

演習

上に書いている'Run'をクリックしてアウトプットを見てみましょう。 次に、println!マクロをもう一行追加してアウトプットがどうなるか見てみましょう。

Hello World!
I'm a Rustacean!
関連キーワード:  関数, Result, Rust, By, Example, エラー, Option, テストケース, use, This