你好,世界
这是传统的 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. // This code is editable, feel free to hack it! // You can always return to the original code by clicking the "Reset" button -> // This is the main function. fn main() { // Statements here are executed when the compiled binary is called. // Print text to the console. println!("Hello World!"); }
println! 是一个 宏,用于向控制台输出文本。
可以使用 Rust 编译器生成可执行文件:rustc。
$ rustc hello.rs
rustc 会生成一个名为 hello 的可执行文件,该文件可以执行。
$ ./hello
Hello World!
活动
点击上方的 'Run' 查看预期输出。接下来,添加新的一行,使用第二个 println! 宏,使输出显示
Hello World!
I'm a Rustacean!