My code from working through Zero to Production in Rust.
- Install Rust
- Install Docker
brew install libpqto installpsqlcargo install sqlx-cli --no-default-features --features rustls,postgrescargo install bunyanfor pretty printing logs
bash scripts/init_db.shto start database server in Docker container (detached) for testingSKIP_DOCKER=true bash scripts/init_db.shto apply migrations to database running in containerpsql -h localhost -p 5432 -U postgresto connect to database server from command linecargo run | bunyanto run app with pretty-printed logscargo watch --exec 'run | bunyan' --ignore *.mdto run app on file changes
cargo watch --exec check --exec test --ignore *.mdto run tests on file changesTEST_LOG=true cargo testto see logs from tests, orTEST_LOG=true cargo test | bunyanwith pretty printing
To manually test API endpoints, use for example:
curl -v http://127.0.0.1:8000/health_checkcurl -v http://127.0.0.1:8000/subscriptions -H "Content-Type: application/x-www-form-urlencoded" -d "email=test@test.com&name=tester"
If you see the following error, you can increase the maximum number of open file handles:
thread 'actix-server worker ...' panicked at ... called
Result::unwrap()on anErrvalue: Os { code: 24, kind: Uncategorized, message: "Too many open files" }
ulimit -Snto see the current soft limitulimit -Sn <value>to set a new limit for the current Shell session, e.g.ulimit -Sn 1000
psql -h localhost -p 5432 -U postgresto connect to the database server from command line
cargo sqlx prepare --workspace, to work with sqlx offline, together withSQLX_OFFLINE=truedocker build --tag zero2prod --file Dockerfile .docker run -p 8000:8000 zero2prod
cargo clippyfor lintingcargo tarpaulin --ignore-testsfor code coveragecargo watchfor triggering commands automatically on code changescargo auditto check for vulnerabilitiescargo expandto show result of macro expansionscargo +nightly udepsto remove unused dependencies, requiresrustup toolchain install nightlycargo treeto display dependency tree, useful for debugging incompatible dependencies
rustup updateto update the Rust toolchain includingrustcandcargotmux new-session -t <existing-session>to attach to the same session multiple times and switch windows independently, using tmux grouped sessions (see SO post), e.g. for monitoring output fromcargo watchcommands in separate windows