简体   繁体   English

Rust 中的库 crate 和普通 crate 有什么区别?

[英]What is the difference between library crates and normal crates in Rust?

While reading the official book, I stumbled upon packages and crates.在阅读官方书籍时,我偶然发现了包裹和板条箱。 To create a new "project", this is what I ran:要创建一个新的“项目”,这就是我运行的:

$ cargo new my-project
     Created binary (application) `my-project` package
$ ls my-project
Cargo.toml
src
$ ls my-project/src
main.rs

The book states the following:该书记载如下:

A package must contain zero or one library crates, and no more.一个包必须包含零个或一个库包,不能更多。 It can contain as many binary crates as you'd like, but it must contain at least one crate (either library or binary).它可以包含任意数量的二进制 crate,但它必须至少包含一个 crate(库或二进制)。

My doubt is, what is the difference between binary crates and normal crates?我的疑问是,二进制板条箱和普通板条箱有什么区别?

The difference is between binary crate and library crate.区别在于二进制 crate 和 library crate。 There are no "normal" crates.没有“正常”的板条箱。

  • A binary crate is an executable program.二进制 crate 是一个可执行程序。

  • A library crate is a library of reusable components that can be included in another library crate or in a binary crate. library crate 是一个可重用组件的库,可以包含在另一个 library crate 或二进制 crate 中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM