Rust学习

本文详细介绍了如何在Windows上安装Rust编程语言,包括官网下载、C++环境设置、MSYS2安装、IntelliJIDEA集成以及使用命令行创建Rust项目。
摘要由CSDN通过智能技术生成

第一章 Rust 安装



前言

随着Rust的不断发展,它已经连续六年获得最佳语言,很多人都开启了学习这个语言的学习,本文就记录了最基础的安装。


一、访问官网下载exe文件

Rust官网下载
根据你的操作系统下载对应位数的exe

二、安装rust

安装

在windows上安装Rust需要有C++环境 当然你的系统环境里面没有C++也是没有关系的,运行你刚刚下载的rustup-init.exe文件 他会弹出以下界面

代码如下(示例):

PS C:\Users\Hehongyuan> rustup-init.exe
......
Current installation options:

   default host triple: x86_64-pc-windows-msvc
     default toolchain: stable (default)
               profile: default
  modify PATH variable: yes

1) Proceed with installation (default)
2) Customize installation
3) Cancel installation

此时我们选择1 默认继续安装即可 此时如果你没有C++环境 他会帮助你安装Microsoft C++ Build Tools 等待安装完成 会重启电脑 重启完之后再运行rustup-init.exe文件 此刻他的运行界面就变成:


Welcome to Rust!

This will download and install the official compiler for the Rust
programming language, and its package manager, Cargo.

Rustup metadata and toolchains will be installed into the Rustup
home directory, located at:

  C:\Users\Administrator\.rustup

This can be modified with the RUSTUP_HOME environment variable.

The Cargo home directory is located at:

  C:\Users\Administrator\.cargo

This can be modified with the CARGO_HOME environment variable.

The cargo, rustc, rustup and other commands will be added to
Cargo's bin directory, located at:

  C:\Users\Administrator\.cargo\bin

This path will then be added to your PATH environment variable by
modifying the HKEY_CURRENT_USER/Environment/PATH registry key.

You can uninstall at any time with rustup self uninstall and
these changes will be reverted.

Current installation options:


   default host triple: x86_64-pc-windows-msvc
     default toolchain: stable (default)
               profile: default
  modify PATH variable: yes

1) Proceed with standard installation (default - just press enter)
2) Customize installation
3) Cancel installation
>

或许有一些出入 毕竟我这是第二次安装 这时我们继续选择1默认安装 等待。完成后您就已经安装了 Rust

查询版本

win + r 唤出运行对话框 输入cmd 打开命令提示符 输入

rustc --version
cargo --version

即可出现
rust版本信息
cargo版本信息
到此rust安装环境就结束了

三、安装MSYS

MSYS2是工具和库的集合,为您提供了一个易于使用的环境来构建、安装和运行本机 Windows 软件。
MSYS2下载地址 此地址里也有他的安装步骤并配置MSYS
配置好后,在 MSYS 中输入下面的命令来安装 rustup。

curl https://sh.rustup.rs -sSf | sh

按1 继续根据提示完成默认安装

更新

要更新 Rust,在终端执行以下命令即可更新:
win + r 唤出运行对话框 输入cmd 打开命令提示符 输入

rustup update

卸载

要卸载 Rust 和 rustup,在终端执行以下命令即可卸载:
win + r 唤出运行对话框 输入cmd 打开命令提示符 输入

rustup self uninstall

四、在IntelliJ IDEA上使用Rust

我这里使用的编译器是IntelliJ IDEA 但是应该一般人都是用的 vscode 我当时用的没debug 所以我选择了 IntelliJ IDEA

首先打开IntelliJ IDEA选择插件搜索 [Deprecated] Rust 点击安装 重启idea即可
ps:不知道为啥我搜索 Rust 搜不出来这玩意儿 要命了
在这里插入图片描述
重启完毕只有选择 新建项目 语言选择 Rust 项目模板(Project Template)选择 Binary (application) 之后点击创建
在这里插入图片描述
在这里插入图片描述

五、用命令创建Rust项目

到此你就能使用idea进行Rust代码的编写了,但是还有些小伙伴想知道自己的环境是否正确或者喜欢用命令来创建项目那我们就开始吧!
win + r 唤出运行对话框 输入cmd 打开命令提示符 输入

cargo new world_hello

还是那句话 创建世界 如果你的一切配置和环境都正确那么 他就会出现这样的代码
在这里插入图片描述
如果你想编译运行他那么直接

cargo run

即可 此时打印的消息为
在这里插入图片描述

总结

到此无论你用哪种方式创建使用Rust项目,都可以跟这个世界打招呼了 Hello World!
如果这篇文章对你有用 拜托给我一个免费的小心心和赞吧~

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值