150 字
约 30 秒
1
初始化项目
初始化项目
使用 cargo init cli 初始化一个名为 cli 的项目。
目录结构如下:
# cli 目录结构
- .git
- src
- main.rs
- .gitignore
- Cargo.toml
其中的 src 目录存放的是项目源代码。 Cargo.toml 文件则用于保存项目依赖。
使用编辑器打开 src/main.rs。可以看见以下内容:
fn main() {
println!("Hello, world!");
}
使用终端打开项目。使用 cargo run 运行项目。
可以看见 Hello world! 被输出。
需要注意的是,在 Rust 中,语句末尾要加上分号 ;。
评论
0 条
还没有评论,先写一条吧。