当前位置: 首页 > news >正文

Rust入门

Rust入门

  • 安装 Rust
    • 类似Linix的系统
    • Windows
    • 验证安装
  • cargo - Rust 构建工具和包管理器

安装 Rust

使用 rustup安装Rust,rustup是一个用于管理 Rust 版本,及其相关工具的命令行工具。安装过程会因操作系统而略有不同。

类似Linix的系统

  • 打开终端 terminal
  • 运行以下命令,下载并执行rustup安装脚本
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
  • 按照屏幕上的指示操作。默认的“标准安装”,通常足以满足大多数用户的需求

Windows

  • 从 Rust 官方网站 (rust-lang.org/tools/install) 下载 rustup-init.exe 安装程序
  • 运行下载的 rustup-init.exe 文件
  • 按照屏幕上的说明进行操作。通常情况下,默认的“标准安装”,通常足以满足大多数用户的需求
  • 在Windows上编译Rust,通常需要C++构建工具,这些工具通常由 Visual Studio 提供。如果未安装这些工具,rustup 安装程序可能会提示您安装,或者您可能需要单独安装它们

验证安装

安装完成后,通过打开一个新的终端,或命令提示符并运行以下命令来验证

cargo --version

屏幕输出

cargo 1.91.0 (ea2d97820 2025-10-10)

该命令输出 Cargo 的版本,cargo 是 Rust 的构建工具和包管理器,以确认 Rust 已成功安装。

可以用下列的命令,列出cargo工具的功能

~$ cargo --list

屏幕输出

Installed Commands:add                  Add dependencies to a Cargo.toml manifest fileb                    alias: buildbench                Execute all benchmarks of a local packagebuild                Compile a local package and all of its dependenciesc                    alias: checkcheck                Check a local package and all of its dependencies for errorsclean                Remove artifacts that cargo has generated in the pastclippy               Checks a package to catch common mistakes and improve your Rust code.config               Inspect configuration valuesd                    alias: docdoc                  Build a package's documentationfetch                Fetch dependencies of a package from the networkfix                  Automatically fix lint warnings reported by rustcfmt                  Formats all bin and lib files of the current crate using rustfmt.generate-lockfile    Generate the lockfile for a packagegit-checkout         REMOVED: This command has been removedhelp                 Displays help for a cargo subcommandinfo                 Display information about a packageinit                 Create a new cargo package in an existing directoryinstall              Install a Rust binarylocate-project       Print a JSON representation of a Cargo.toml file's locationlogin                Log in to a registry.logout               Remove an API token from the registry locallymetadata             Output the resolved dependencies of a package, the concrete used versions including overrides, in machine-readable formatmirinew                  Create a new cargo package at <path>owner                Manage the owners of a crate on the registrypackage              Assemble the local package into a distributable tarballpkgid                Print a fully qualified package specificationpublish              Upload a package to the registryr                    alias: runread-manifest        DEPRECATED: Print a JSON representation of a Cargo.toml manifest.remove               Remove dependencies from a Cargo.toml manifest filereport               Generate and display various kinds of reportsrm                   alias: removerun                  Run a binary or example of the local packagerustc                Compile a package, and pass extra options to the compilerrustdoc              Build a package's documentation, using specified custom flags.search               Search packages in the registry. Default registry is crates.iot                    alias: testtest                 Execute all unit and integration tests and build examples of a local packagetree                 Display a tree visualization of a dependency graphuninstall            Remove a Rust binaryupdate               Update dependencies as recorded in the local lock filevendor               Vendor all dependencies for a project locallyverify-project       DEPRECATED: Check correctness of crate manifest.version              Show version informationyank                 Remove a pushed crate from the index

cargo - Rust 构建工具和包管理器

当使用rustup安装Rust时,构建工具和包管理器cargo。

常用的cargo功能

  • cargo new,产生一个应用程序项目
  • cargo build,编译。链接应用程序项目
  • cargo run,运行应用程序
  • cargo test,测试应用程序
  • cargo doc,生成应用程序项目文档
  • cargo publish,将库发布到 crates.io
$ source $HOME/.cargo/env
$ cargo new hello
$ cd hello
$ cargo build
$ cargo run

屏幕输出

    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.01sRunning `target/debug/hello`
Hello, world!
http://www.dtcms.com/a/613547.html

相关文章:

  • Rust入门 之一
  • “伪”局域网
  • C语言编译软件Mac | 在Mac上选择最合适的C语言编译工具
  • 怎么样建设一个网上教学网站网页版微信二维码不能直接识别
  • Linux BPF 技术深度解析:从原理到实践
  • 高端网站报价wordpress如何添加背景音乐
  • C# 对多个任务进行符合管理
  • 在Eclipse IDE for Embedded C/C++ Developers软件中定义的宏,编译C源文件时编译器无法找到宏定义!
  • 从局域网到全网可用!PDFMathTranslate 翻译工具的进阶使用法
  • 深入理解 JavaScript 异步编程:从单线程到 Promise 的完整指南
  • 怎么自己做歌曲网站沈阳网站建设方案策划
  • 电脑卡顿因重复文件?AllDup无安装版快速查重+批量删除 文件管理混乱?AllDup多模式查重工具,Python开发者也能高效用
  • Dubbo Mock机制详解:服务降级与本地测试的利器
  • JDBC与事务的协同:ThreadLocal的巧妙运用
  • 底层视觉及图像增强-项目实践理论补充(十六-0-(13):HDR技术全链路解析:从原理到LED显示工程实践):从奥运大屏,到手机小屏,快来挖一挖里面都有什么
  • 深圳服务平台网站网站提示域名解析错误怎么办
  • 论文阅读13——基于大语言模型和视觉模态融合的可解释端到端自动驾驶框架:DriveLLM-V的设计与应用
  • 考研408--数据结构--day2--顺序表及其增删改查
  • 软件演示环境动态扩展与成本优化:基于目标跟踪与计划扩展的AWS Auto Scaling策略
  • 网站设计的资质叫什么花蝴蝶韩国免费视频
  • AI Agent 之工具使用:从函数定义到实际应用
  • 【C++】 map/multimap底层原理与逻辑详解
  • 如何利用国外网站开发客户wordpress的免费模板
  • C++、Java 还是测试开发?
  • Java 开发 - 粘包处理器 - 基于消息头 + 消息体(魔数验证、长度验证)
  • Spring Cloud Data Flow 简介
  • 前端性能优化指标,首次内容绘制与交互时间
  • MySQL :实用函数、约束、多表查询与事务隔离
  • 【Java架构师体系课 | MySQL篇】③ Explain执行计划详解
  • Bugku-web题目-xxx二手交易市场