summaryrefslogtreecommitdiff
path: root/Cargo.md
diff options
context:
space:
mode:
Diffstat (limited to 'Cargo.md')
-rw-r--r--Cargo.md35
1 files changed, 34 insertions, 1 deletions
diff --git a/Cargo.md b/Cargo.md
index baa57ed..009aff9 100644
--- a/Cargo.md
+++ b/Cargo.md
@@ -1,4 +1,37 @@
-[[Rust]]
+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