
mkdir hello_world
cd h*
code .rshello_world.rsfn main() {
println!("Hello,World!");
}rustc main.rs.\main.exe./main
运行结果如下:user@MacBook-Pro hello_world % mv hello_world.rs main.rs
user@MacBook-Pro hello_world % rustc main.rs
user@MacBook-Pro hello_world % ./main
Hello,World!fn main() {} println!("Hello,World!"); println! 是一个 Rust macro (宏) !"Hello,World!" 是字符串,他是 println! 的参数; 结尾rustc 源文件名.pdb 文件,里面包含调试信息cargo --versionxinggongwuyue@DioxideCN-MacBook-Air hello_world % cargo --version
cargo 1.60.0 (d1fd9fe2c 2022-03-01)cargo new hello_cargo hello_cargohello_cargo cargo new program --vcscrate[package]
name = "hello_cargo"
version = "0.1.0"
authors = ["Dioxide <dioxide-cn@qq.com>"]
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]target/debug/hello_cargotarget\debug\hello_cargo.exe./target/debug/hello_cargo.\target\debug\hello_cargo.execargo build 会在顶层目录生成 cargo.lock 文件 xinggongwuyue@DioxideCN-MacBook-Air hello_cargo % cargo run
Compiling hello_cargo v0.1.0 (/Users/xinggongwuyue/Desktop/项目工程/rust/hello_cargo)
Finished dev [unoptimized + debuginfo] target(s) in 0.32s
Running `target/debug/hello_cargo`
Hello, world!
xinggongwuyue@DioxideCN-MacBook-Air hello_cargo % cargo run
Finished dev [unoptimized + debuginfo] target(s) in 0.01s
Running `target/debug/hello_cargo`
Hello, world!