c7303154cc
Compared this template against the older nix-templates/templates/rust
("rrrr") ahead of eventually replacing it. Ported the pieces that were
genuinely missing and non-controversial:
- flake.templates.default, so `nix flake init -t <url>` works once
this repo is published — the actual mechanism a "template" needs.
- justfile wrapping the cargo/nix commands for discoverability.
- .envrc (use flake) for direnv auto-activation.
- `just` added to the dev shell so the justfile is usable without a
separate install.
Left out on purpose: workspace crate split, tracing/serde/tokio-heavy
example code, docker.nix, nightly coverage toolchain, and copier.yaml —
those make it an opinionated async-service starter rather than a blank
Rust template, and copier.yaml in the old repo was dead configuration
(no file actually referenced its Jinja variables).
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018ALEXkc7pTro7tF1WcUuKb
43 lines
1.6 KiB
Markdown
43 lines
1.6 KiB
Markdown
# rust_template
|
|
|
|
A minimal Rust project template: a `clap` CLI backed by a library crate, with unit tests, an
|
|
integration test, a `criterion` benchmark, and a Nix flake (crane + fenix) — so it builds the same
|
|
way with plain `cargo` or with `nix`.
|
|
|
|
## Using this template
|
|
|
|
1. Copy/clone this repo (or, once published, `nix flake init -t <this-repo-url>`).
|
|
2. Rename the placeholder crate name:
|
|
```bash
|
|
./scripts/rename-project.sh my_project
|
|
cd .. && mv rust_template my_project && cd my_project
|
|
```
|
|
3. Build whatever you actually came here for — replace `greet` in `src/lib.rs`, extend the CLI in
|
|
`src/main.rs`, add your own tests and benchmarks.
|
|
|
|
## Building and running
|
|
|
|
**With Cargo** (needs Rust installed, or run inside `nix develop`):
|
|
```bash
|
|
cargo run -- Zeke # build + run, prints "Hello, Zeke!"
|
|
cargo build --release
|
|
cargo test # unit + integration tests
|
|
cargo bench # criterion benchmark
|
|
```
|
|
|
|
**With Nix** (no local Rust install needed):
|
|
```bash
|
|
nix develop # dev shell with the pinned toolchain + tools
|
|
nix build # produces ./result/bin/rust_template
|
|
nix run -- Zeke # build + run
|
|
nix flake check # clippy, fmt, doc, audit, tests — all in one go
|
|
nix fmt # format Rust, Nix, and TOML files
|
|
```
|
|
|
|
If you have [direnv](https://direnv.net/) installed, `direnv allow` activates the dev shell
|
|
automatically on `cd` (see `.envrc`).
|
|
|
|
`just` (available inside `nix develop`) wraps the common commands above — run `just` to list them.
|
|
|
|
See `CLAUDE.md` for more detail on the project layout and how the pieces fit together.
|