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

Custom license

12KB
111 lines

lrk

Crates.io Apache-2.0 licensed CI pre-commit

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

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.
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

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