4 releases
0.1.3 | Feb 8, 2023 |
---|---|
0.1.2 | Feb 8, 2023 |
0.1.1 | Feb 8, 2023 |
0.1.0 | Feb 8, 2023 |
#425 in Cargo plugins
12KB
111 lines
lrk
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
cargo init --bin # for binary(executable) crate
cargo init --lib # for library crate
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
cargo run
- multiple executable
- put other binaries except main.rs in the
src/bin
directory. src/main.rs
src/bin/another_executable.rs
src/bin/multi_files_executable/main.rs
- you can set
default-run
in Cargo.toml- you should set this value to exec
cargo run
without--bin
option.
- you should set this value to exec
- put other binaries except main.rs in the
cargo run --bin learn-rust # to run main.rs
cargo run --bin another_executable # to run bin/another_executable.rs
cargo run --bin multi_files_executable
# to run bin/multi_files_executable/main.rs
cargo run # = cargo run --bin learn-rust (when default-run = learn-rust)
in releasee mode with optimization
cargo run --release
add another crate
cargo new --lib 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
cargo doc --open
Clean targets
- https://doc.rust-lang.org/cargo/commands/cargo-clean.html
- use when something is wrong.
cargo clean
Check easy compilation errors
cargo check
publish to crates.io
https://doc.rust-lang.org/cargo/reference/publishing.html
cargo login <token> # only once
cargo publish
formatter
linter
in vscode
extensions
- rust-analyzer
- even better toml
- bash IDE
- shell-format
- markdownlint
- gitlens
- live server
Dependencies
~10KB