Getting started

您所在的位置:网站首页 如何评价rust Getting started

Getting started

2023-11-27 03:14| 来源: 网络整理| 查看: 265

Adding dependencies

Let’s add a dependency to our application. You can find all sorts of libraries on crates.io, the package registry for Rust. In Rust, we often refer to packages as “crates.”

In this project, we’ll use a crate called ferris-says.

In our Cargo.toml file we’ll add this information (that we got from the crate page):

[dependencies] ferris-says = "0.3.1"

We can also do this by running cargo add ferris-says.

Now we can run:

cargo build

...and Cargo will install our dependency for us.

You’ll see that running this command created a new file for us, Cargo.lock. This file is a log of the exact versions of the dependencies we are using locally.

To use this dependency, we can open main.rs, remove everything that’s in there (it’s just another example), and add this line to it:

use ferris_says::say;

This line means that we can now use the say function that the ferris-says crate exports for us.



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3