rust如何使用货架_Rust 包管理器 cargo

Rust 内置了一个包管理器 cargo。它会随着 Rust 的安装而安装。

cargo 类似于 Python 中的 pip 或 Ruby 中的 RubyGems 或 Node.js 中的 NPM。

当然了,cargo 不仅仅是一个包管理器,它还是 Rust 的项目管理利器。

检查 cargo 是否安装和安装的版本

打开终端或命令行提示符或 Shell,输入下面的命令然后回车

cargo --version

如果已经安装,则输出结果类似于

cargo 1.35.0

cargo 包管理器的版本和 Rust 语言是同步的。

cargo 的帮助信息

如果想要查看 cargo 的帮助信息或查看 cargo 提供了哪些命令和功能,可以在 终端 中输入 cargo 或 cargo -h 然后回车

输出结果类似于

Rust's package manager

USAGE:

cargo [OPTIONS] [SUBCOMMAND]

OPTIONS:

-V, --version Print version info and exit

--list List installed commands

--explain Run `rustc --explain CODE`

-v, --verbose Use verbose output (-vv very verbose/build.rs output)

-q, --quiet No output printed to stdout

--color Coloring: auto, always, never

--frozen Require Cargo.lock and cache are up to date

--locked Require Cargo.lock is up to date

-Z ... Unstable (nightly-only) flags to Cargo, see 'cargo -Z help' for details

-h, --help Prints help information

Some common cargo commands are (see all commands with --list):

build Compile the current package

check Analyze the current package and report errors, but don't build object files

clean Remove the target directory

doc Build this package's and its dependencies' documentation

new Create a new cargo package

init Create a new cargo package in an existing directory

run Run a binary or example of the local package

test Run the tests

bench Run the benchmarks

update Update dependencies listed in Cargo.lock

search Search registry for crates

publish Package and upload this package to the registry

install Install a Rust binary. Default location is $HOME/.cargo/bin

uninstall Uninstall a Rust binary

See 'cargo help ' for more information on a specific command.

cargo 提供的命令

正如上面 cargo 帮助信息中所描述的那样,如果我们想要查看 cargo 提供的所有命令,可以直接在终端里输入

cargo --list

输出结果如下

Installed Commands:

bench Execute all benchmarks of a local p

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值