blob: 009aff9461a46f5f14e5e4a0d33bf8b9ab8e642e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
Module -> Crate -> Package
Binary Crate
Library Crate (tip: should contain the module tree, binary crate should be a client to the lib)
Package: n binary crates, 1 library crate
`src/main.rs` package exports binary crate of package name
`src/bin/*.rs` multiple binary crates
`src/lib.rs` package exports library crate of package name
---
Absolute import path start with `crate::` etc.
Relative import path start with `self::` , `super::`, or an identifier in the current mod.
`super` starts rel path from the parent module.
child scope can access everything in parent scope even privates.
`use` to create a shortcut to crates **only** in the **current** scope.
It's idiomatic when calling a function to import its parent module so it's clear that the function call is not to a local function. For importing structs and enums and such it's idiomatic to import them all the way (unless its name collides ofc).
`use .. as name` is also possible.
`pub use ..` to re-export it so external callers can also reference it shortly, exposing a different structure to callers than the internal package actually is.
Nesting `use` stmts: `use std::{cmp::Ordering, io};`
or `use std::io::{self, Write};` instead of `std::io;` and `std::io::Write;`.
Glob: `use std::collections::*;`
`pub mod blaat;` -> `src/blaat.rs` -> `pub mod henk;` -> `src/blaat/henk.rs`.
old-style: `src/blaat/mod.rs` -> `src/blaat/henk/mod.rs` (many mod.rs files)
---
Standard stuff:
- cargo build
- cargo update
- cargo run
Cool tidbit:
- cargo doc --open
|