1. 程式人生 > >通過例子學習Rust之 1 Hello World

通過例子學習Rust之 1 Hello World

1 Hello World
世界,你好。
This is the source code of the traditional Hello World program.
這是傳統的Hello World的原始碼。

// This is a comment, and will be ignored by the compiler
// 本行為註釋,會被編譯器忽略
// You can test this code by clicking the "Run" button over there ->
// 點選Run按鈕即可執行此程式碼
// or if prefer to use your keyboard, you can use the "Ctrl + Enter"
shortcut // 或者希望使用鍵盤,可以用"Ctrl + Enter"快捷鍵 // 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 // 這是主函式 fn main() { // The statements here will be executed when the compiled binary is
called // Print text to the console println!("Hello World!"); }

println! is a macro that prints text to the console.
println! 是一個向控制檯列印文字的巨集
A binary can be generated using the Rust compiler: rustc.
使用Rust編譯器命令rustc即可生成二進位制檔案
$ rustc hello.rs
rustc will produce a hello binary that can be executed.

rustc 將產生一個可執行的二進位制檔案hello
$ ./hello
Hello World!