The dev loop
id-effect dev
id-effect dev [--path DIR] [--package NAME] [--bin NAME] [--watch PATH]... [--services]
[--poll-ms MS] [--debounce-ms MS] [--grace-secs SECS] [-- APP ARGS...]
id-effect dev builds the project in DIR (default: the current directory), runs its binary with ID_EFFECT_PROFILE=dev (so id_effect_config profiles load config/dev.toml; see Config profiles), and rebuilds and restarts it whenever a watched file changes:
- Every
--poll-ms(default 500) it compares the modification time and length of every file undersrc/,Cargo.toml,config/and each--watch PATHwith the previous scan. It skipstarget, hidden entries (.git,.idea, …) and editor backups (*~,*.swp,*.swx). - A change waits until a scan finds the files quiet for
--debounce-ms(default 200), so a save that touches several files, or a formatter run, rebuilds once. - It runs
cargo build(with--package/--binwhen given). The compiler's output streams to the terminal. - Only when the build succeeds is the running app stopped: SIGTERM, then up to
--grace-secs(default 10) to drain in-flight work and exit, after which it is killed. Then the new binary starts, with the arguments after--.
A failed build keeps the running app: you see the compiler errors and keep using the last good version until the next change fixes it.
$ id-effect dev -- --port 8080
id-effect dev: watching src, Cargo.toml, config every 500ms
id-effect dev: cargo build
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.21s
id-effect dev: started /home/me/orders-api/target/debug/orders-api (pid 41022, ID_EFFECT_PROFILE=dev)
… the app's output …
id-effect dev: changed src/routes.rs; rebuilding
id-effect dev: cargo build
error[E0425]: cannot find value `ordr` in this scope
id-effect dev: build failed (`cargo build` exit status: 101); keeping the running app (pid 41022); waiting for a change
id-effect dev: changed src/routes.rs; rebuilding
id-effect dev: cargo build
id-effect dev: stopped pid 41022 (signal: 15 (SIGTERM))
id-effect dev: started /home/me/orders-api/target/debug/orders-api (pid 41107, ID_EFFECT_PROFILE=dev)
--services first runs docker compose up -d in DIR when it has a compose file (compose.yaml, which every generated project has, compose.yml, docker-compose.yaml or docker-compose.yml), so the database and broker are up before the app starts. Without a compose file it says so and carries on; a failing docker compose stops id-effect dev with exit status 1.
When the build makes more than one binary (a workspace, or a package with several [[bin]] targets), id-effect dev asks for --package or --bin instead of guessing.
What id-effect dev does not do:
- It polls; it does not use file system notifications (the
notifycrate's license is not on the workspace's allow list). A scan of a project'ssrc/andconfig/costs little, but a large--watchdirectory is rescanned every--poll-ms. - It restarts the process; nothing is hot-swapped in a running app, and the new process binds the port again after the old one released it. An app that drains slowly delays the restart by up to
--grace-secs. - On Windows the old app is killed at once (there is no SIGTERM).
- Ctrl-C stops
id-effect devand the app together (they share the terminal's process group); the app sees the interrupt like any Ctrl-C. - The app's stdin, stdout and stderr are the terminal's.
Live reload, precisely
id-effect dev is id_effect's live-reload loop, and the reload is a rebuild and restart: save a file and, a poll interval plus the debounce plus one cargo build later, the new code is serving, with the same arguments and ID_EFFECT_PROFILE=dev. What it guarantees, and what checks it:
| Behaviour | Checked by |
|---|---|
An edit under a watched path rebuilds the app, stops the old process (the stopped pid line names it) and starts the new binary with the same arguments and profile; the old process is gone | crates/id_effect_tool/tests/dev.rs, edit_triggers_rebuild_and_restart (line 160) |
An edit that does not compile leaves the running app up (build failed …; keeping the running app (pid N)), shows the compiler's error, and the next edit that compiles restarts it | the same file, build_error_keeps_previous_child (line 180) |
A bad edit never takes the app down: the old process is stopped only after the new build succeeded, so the only gap is the restart itself (stop, then start). In-process state (open connections, caches, fibers) does not survive the restart; nothing is patched into the running process. A change under config/ restarts the app the same way (its cargo build is a no-op); to apply configuration edits without a restart, in development or production, watch the profile from inside the app with Profiles::watch (Hot reload).
The dev container
Every project id-effect new generates, whatever the template, has a .devcontainer/ directory: open it in VS Code ("Reopen in Container"), GitHub Codespaces or any tool that reads the Dev Container spec (devcontainer up --workspace-folder . with the CLI) and you get the same toolchain on every machine.
.devcontainer/Dockerfilestarts fromrust:1.99-bookworm, pinned by itssha256digest (current stable; the id_effect crates need Rust 1.94 or newer), addsrustfmtandclippy, and installs theid-effectcommand at the version that generated the project (cargo install id_effect_tool --version … --locked, the build argumentID_EFFECT_VERSION). It runs as a non-root userdev, so files written to the workspace are not root's..devcontainer/devcontainer.jsonis plain JSON (no comments). It adds thedocker-in-dockerfeature, sodocker composeworks inside the container against the project'scompose.yaml; ports that compose publishes are on the container'slocalhost, which is what.env.examplepoints at. Theservicetemplate forwards port 8080 and setsHOST=0.0.0.0andPORT=8080.postCreateCommandrunscargo fetchand prints the dev loop.
Inside the container the dev loop is id-effect dev. With --db pg, start the database first with docker compose up -d db: id-effect dev --services brings up every compose service, including app, the release build of the project itself, which would take port 8080 (and in the other templates would run a second copy of the program).
What the dev container does not do:
- The Rust version is pinned, not tracked: move to a newer release by changing the
FROMline (tag and digest;docker buildx imagetools inspect rust:<version>-bookwormprints the digest). - The
docker-in-dockerfeature is referenced by its major version tag (:2), not a digest, and runs the container privileged. id-effect new --local-workspaceprojects get the samecargo installfrom crates.io; inside the container the checkout is not mounted, so build against it from the host.