Rust - Standard library and crates
The Rust Standard Library
https://doc.rust-lang.org/std/index.html
Primitives from Standard Library: https://doc.rust-lang.org/std/index.html#primitives Modules from Standard Library: https://doc.rust-lang.org/std/index.html#modules Macros from Standard Library: https://doc.rust-lang.org/std/index.html#macros Keywords from Standard Library: https://doc.rust-lang.org/std/index.html#keywords
println macro
https://doc.rust-lang.org/std/macro.println.html
prelude
By default, Rust has a few items defined in the standard library that it brings into the scope of every program. This set is called the prelude, and you can see everything in it in the standard library documentation: https://doc.rust-lang.org/stable/std/prelude/index.html
If a type you want to use isn’t in the prelude, you have to bring that type into scope explicitly with a use statement.
e.g.
use std::io;
pub
The keyword pub makes any module, function, or data structure accessible from inside of external modules. By default, they are private.
pub fn greet() {
println!("Hello, world!");
}
crates
Think of it as a synonym for package
. In Rust, packages of code are referred to as crates. They are more analogous to jar files. From Java, crates are analogous to Java dependencies/jar files.
Most of the time when Rustaceans say “crate”, they mean library crate, and they use “crate” interchangeably with the general programming concept of a “library".
Things that are not available in the Standard Library will be available here.
https://doc.rust-lang.org/book/ch07-01-packages-and-crates.html
Most of the time when Rustaceans say crate
, they mean library crate, and they use crate
interchangeably with the general programming concept of a library
.
Crates.io
is where people in the Rust ecosystem post their open source Rust projects for others to use: https://crates.io/
Note: You won’t just know which traits to use and which methods and functions to call from a crate, so each crate has documentation with instructions for using it. Another neat feature of Cargo is that running the cargo doc --open
command will build documentation provided by all your dependencies locally and open it in your browser. If you’re interested in other functionality in the rand crate, for example, run cargo doc --open
and click rand
in the sidebar on the left.