44 lines
1023 B
Markdown
44 lines
1023 B
Markdown
---
|
||
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 文件:
|
||
|
||

|
||
|
||

|
||
|