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

怎甘沉沦 提交于 2020-11-29 09:05:50

问题


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).

My doubt is, what is the difference between binary crates and normal crates?


回答1:


The difference is between binary crate and library crate. There are no "normal" crates.

  • A binary crate is an executable program.

  • A library crate is a library of reusable components that can be included in another library crate or in a binary crate.



来源:https://stackoverflow.com/questions/60266905/what-is-the-difference-between-library-crates-and-normal-crates-in-rust

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!