Best practices on setting up a new Rust project

Cargo tool has a `cargo new` or `cargo init` command, but is it the only step that you need to think about for your Rust project? Let's see the important extra steps of creating a Rust crate, step 43 will shock you.

.gitignore and equivalents

The `cargo new` command has a `--vcs` option, and supports: git, hg, pijul, or fossil. But if you forgot to pass that option, set up the ignore files for your chosen VCS.

For binaries, you're supposed to exclude `target` directory, and for libraries, `target` directory and the `Cargo.lock` file (FAQ entry).

#.gitignore file contents

# Build artifacts

# For library crates

Cargo.toml fields

`cargo new` creates the Cargo.toml file with fields; name, version, and edition. But to be able to upload the crate to, you'll also need to provide a `description` and `license` (Or `license-file`) fields. The `license` field is a string, filled with your chosen license(s) from If the license is not covered there, you can provide the license-file, as well. Keep in mind that it's a good practice to include the entire license in a file named `LICENSE` in the repository root, and add any required comment headers of the license to the source files.

There are also optional fields which you probably want to fill:
  • documentation (more on this later)
  • homepage
  • repository
  • keywords
  • categories

Publishing to may not be the only registry, but it's the one we will be using here.

This requires creating an account in, verifying your email, getting an API key and running

cargo login  # need the api key now
cargo publish --dry-run  # check warnings/errors
cargo publish   # need the email verified account now



Bu blogdaki popüler yayınlar

Ubuntu'yu CD iso dosyası ile güncellemek

Bir kaç izin meselesi

NFS ve Xen sorunu, çözüm UDP