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

sh cargo init --bin # for binary(executable) crate cargo init --lib # for library crate

executable

sh cargo run

```sh cargo run --bin learn-rust # to run main.rs cargo run --bin anotherexecutable # to run bin/anotherexecutable.rs cargo run --bin multifilesexecutable

to run bin/multifilesexecutable/main.rs

cargo run # = cargo run --bin learn-rust (when default-run = learn-rust) ```

in releasee mode with optimization

sh cargo run --release

add another crate

sh cargo new --lib another_crate

Cargo.lock to .gitignore?

https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html

See document

sh cargo doc --open

Clean targets

sh cargo clean

Check easy compilation errors

sh cargo check

publish to crates.io

https://doc.rust-lang.org/cargo/reference/publishing.html

sh cargo login <token> # only once cargo publish

formatter

linter

in vscode

extensions