入门指南

在 Linux、macOS 和 Windows 上安装 Rust。(rustup是下载 rust 的工具,rustc 是编译的工具,cargo 是集成的工具)

编写一个打印 Hello, world! 的程序

fn main() {
    println!("Hello, world!");
}

(base) kimshan@MacBook-Pro use_rustc % ls
main.rs
(base) kimshan@MacBook-Pro use_rustc % rustc main.rs
(base) kimshan@MacBook-Pro use_rustc % ./main
Hello World!

使用 cargo,这是 Rust 的包管理器和构建系统

(base) kimshan@MacBook-Pro LearnRust % cargo new hello_world
     Created binary (application) `hello_world` package
error: could not find `Cargo.toml` in `/Users/kimshan/workplace/LearnRust` or any parent directory
(base) kimshan@MacBook-Pro LearnRust % cd hello_world 
(base) kimshan@MacBook-Pro hello_world % cargo run            
   Compiling hello_world v0.1.0 (/Users/kimshan/workplace/LearnRust/hello_world)
    Finished dev [unoptimized + debuginfo] target(s) in 1.04s
     Running `target/debug/hello_world`
Hello, world!