learn-rust
package
learn-rust is a package. a crate is a binary or library. a package can have a library crate (lib.rs) and multiple binary crates (main.rs, bin/*.rs, bin/*/main.rs). (need at least one library or binary crate. a workspace can have multiple packages as members.
cargo
https://doc.rust-lang.org/stable/cargo/
configuration
https://doc.rust-lang.org/stable/cargo/reference/config.html https://doc.rust-lang.org/stable/cargo/reference/environment-variables.html
init current directory as new project
executable
- https://doc.rust-lang.org/cargo/reference/cargo-targets.html#binaries
- https://doc.rust-lang.org/cargo/guide/project-layout.html
- single executable main.rs
src/main.rs
- multiple executable
- put other binaries except main.rs in the
src/bindirectory. src/main.rssrc/bin/another_executable.rssrc/bin/multi_files_executable/main.rs- you can set
default-runin Cargo.toml- you should set this value to exec
cargo runwithout--binoption.
- you should set this value to exec
- put other binaries except main.rs in the
# to run bin/multi_files_executable/main.rs
in releasee mode with optimization
add another crate
Cargo.lock to .gitignore?
https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
- library layer: yes
- application, endpoint layer: no
See document
Clean targets
- https://doc.rust-lang.org/cargo/commands/cargo-clean.html
- use when something is wrong.
Check easy compilation errors
publish to crates.io
https://doc.rust-lang.org/cargo/reference/publishing.html
formatter
linter
in vscode
extensions
- rust-analyzer
- even better toml
- bash IDE
- shell-format
- markdownlint
- gitlens
- live server