# lrk [![Crates.io][crates-badge]][crates-url] [![Apache-2.0 licensed][apache-badge]][apache-url] [![CI][actions-badge]][actions-url] [![pre-commit][pre-commit-badge]][pre-commit-url] [crates-badge]: https://img.shields.io/crates/v/lrk.svg [crates-url]: https://crates.io/crates/lrk [apache-badge]: https://img.shields.io/badge/license-Apache2.0-green.svg [apache-url]: https://github.com/kagemeka/learn-rust/blob/main/LICENSE [actions-badge]: https://github.com/kagemeka/learn-rust/actions/workflows/ci.yml/badge.svg [actions-url]: https://github.com/kagemeka/learn-rust/actions/workflows/ci.yml [pre-commit-badge]: https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=yellow [pre-commit-url]: https://github.com/pre-commit/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 ### configuration ### init current directory as new project ```sh cargo init --bin # for binary(executable) crate cargo init --lib # for library crate ``` ### executable - - - single executable main.rs - `src/main.rs` ```sh 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. ```sh 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 ```sh cargo run --release ``` ### add another crate ```sh cargo new --lib another_crate ``` ### Cargo.lock to .gitignore? - library layer: yes - application, endpoint layer: no ### See document - ```sh cargo doc --open ``` ### Clean targets - - use when something is wrong. ```sh cargo clean ``` ### Check easy compilation errors - ```sh cargo check ``` ### publish to crates.io ```sh cargo login # only once cargo publish ``` ## formatter - rustfmt - - ## linter - clippy - - ## in vscode ### extensions - rust-analyzer - even better toml - bash IDE - shell-format - markdownlint - gitlens - live server