lrk

Crates.iolrk
lib.rslrk
version0.1.3
sourcesrc
created_at2023-02-08 14:25:05.303697
updated_at2023-02-08 23:08:19.155786
descriptionlearning rust
homepagehttps://github.com/kagemeka/learn-rust#readme
repositoryhttps://github.com/kagemeka/learn-rust
max_upload_size
id779673
size31,542
Hiroshi Tsuyuki (kagemeka)

documentation

https://docs.rs/lrk

README

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
Commit count: 0

cargo fmt