Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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

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

like image 884
Aviral Srivastava Avatar asked Feb 17 '20 16:02

Aviral Srivastava


People also ask

What is a library crate in Rust?

Rust programs may contain a binary crate or a library crate. A binary crate is an executable project that has a main() method. A library crate is a group of components that can be reused in other projects. Unlike a binary crate, a library crate does not have an entry point (main() method).

What is the best crate in Rust?

The Military Crate (also known as the Gun Crate) contains higher quality items than Basic Crates or Tool Boxes. These crates are only found in Monuments. The Military Crate can contain: High Quality Metal.

How do crates work in Rust?

A crate is the smallest amount of code that the Rust compiler considers at a time. Even if you run rustc rather than cargo and pass a single source code file (as we did all the way back in the “Writing and Running a Rust Program” section of Chapter 1), the compiler considers that file to be a crate.

How do you get free crates in Rust?

One of the most simple ways to obtain free skins in RUST is to simply load the game up. RUST has Steam's Playtime Item Grants enabled, which rewards players with free RUST skins and in rare cases skin crates, for simply having the game client open. It doesn't matter whether you're idle or actively playing on a server.


1 Answers

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.

like image 185
mcarton Avatar answered Sep 16 '22 16:09

mcarton