2023-09-15 16:40:41 +08:00

44 lines
1023 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: Rust
date: 2023-09-15 09:25:54
tags:
---
# Rust教程
## 第一个Rust程序
Rust语言代码文件后缀名为`.rs`如helloworld.rs。
```rust
fn main() {
println!("Hello World!");
}
```
使用`rustc`命令编译helloworld.rs文件
```shell
rustc helloworld.rs # 编译 helloworld.rs 文件
```
编译后会生成helloworld可执行文件
```shell
./helloworld # 执行 helloworld
Hello World!
```
# Rust环境搭建
## 安装Rust编译工具
Rust 编译工具从链接 [安装 Rust - Rust 程序设计语言 (rust-lang.org)](https://www.rust-lang.org/zh-CN/tools/install) 中下载的Rustup安装。下载好的Rustup在Windows 上是一个可执行程序 rustup-init.exe。在其他平台上应该是`rustup-init.sh`)。
现在执行 rustup-init 文件:
![image-20230915102448742](https://markdownhexo.oss-cn-hangzhou.aliyuncs.com/img/image-20230915102448742.png)
![image-20230915135358199](https://markdownhexo.oss-cn-hangzhou.aliyuncs.com/img/image-20230915135358199.png)