From c3929f7a6bdd6f4ef04b88b60c77f5e69deb3f5e Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Mon, 12 Jan 2026 23:40:56 -0500 Subject: [PATCH 1/4] chore: refactor write functions, improve CI --- .github/workflows/ci.yml | 139 +++-- Cargo.lock | 4 +- Cargo.lock.msrv | 1254 ++++++++++++++++++++++++++++++++++++++ deny.toml | 1 - justfile | 29 +- release-plz.toml | 4 + src/lib.rs | 329 +++++----- src/pad.rs | 15 +- 8 files changed, 1518 insertions(+), 257 deletions(-) create mode 100644 Cargo.lock.msrv create mode 100644 release-plz.toml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2611966..4ebd802 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,63 +6,106 @@ on: pull_request: workflow_dispatch: -env: - CARGO_INCREMENTAL: 0 - RUSTUP_MAX_RETRIES: 10 - CARGO_NET_RETRY: 10 - RUST_BACKTRACE: full +defaults: + run: + shell: bash jobs: - fmt: - name: Rustfmt - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v6 - - run: rustup component add rustfmt - - run: cargo fmt --all -- --check - - rust: - name: Rust + test: + name: Test runs-on: ${{ matrix.os }} - strategy: - fail-fast: false + fail-fast: true matrix: - os: [ubuntu-latest] - + os: [ ubuntu-latest ] steps: - - name: Checkout repository - uses: actions/checkout@v6 + - uses: actions/checkout@v6 with: { submodules: 'recursive' } + - if: github.event_name != 'release' && github.event_name != 'workflow_dispatch' + uses: Swatinem/rust-cache@v2 + - uses: taiki-e/install-action@v2 + with: { tool: 'just,cargo-binstall' } + - run: just ci-test - - name: Cache cargo registry - uses: actions/cache@v5 - with: - path: ~/.cargo/registry - key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }} - - name: Cache cargo index - uses: actions/cache@v5 - with: - path: ~/.cargo/git - key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }} - - name: Cache cargo target dir - uses: actions/cache@v5 + test-msrv: + name: Test MSRV + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v6 + with: { submodules: 'recursive' } + - if: github.event_name != 'release' && github.event_name != 'workflow_dispatch' + uses: Swatinem/rust-cache@v2 + - uses: taiki-e/install-action@v2 + with: { tool: 'just' } + - name: Read MSRV + id: msrv + run: echo "value=$(just get-msrv)" >> $GITHUB_OUTPUT + - name: Install MSRV Rust ${{ steps.msrv.outputs.value }} + uses: dtolnay/rust-toolchain@stable with: - path: target - key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }} + toolchain: ${{ steps.msrv.outputs.value }} + - run: just ci_mode=0 ci-test-msrv # Ignore warnings in MSRV - - name: Build - run: cargo build --workspace --all-features --all-targets --verbose - - name: Tests - run: cargo test --workspace --all-features --all-targets --verbose + coverage: + name: Code Coverage + if: github.event_name != 'release' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v6 + with: { submodules: 'recursive' } + - uses: Swatinem/rust-cache@v2 + - uses: taiki-e/install-action@v2 + with: { tool: 'just,cargo-llvm-cov' } + - name: Generate code coverage + run: just ci-coverage + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v5 + with: + token: ${{ secrets.CODECOV_TOKEN }} + files: target/llvm-cov/codecov.info - - name: Install Rust targets we use for embedded - run: rustup target install thumbv7em-none-eabihf - - name: Build for embedded - run: cargo build -p can-embedded --target=thumbv7em-none-eabihf --no-default-features + # This job checks if any of the previous jobs failed or were canceled. + # This approach also allows some jobs to be skipped if they are not needed. + ci-passed: + needs: [ test, test-msrv ] + if: always() + runs-on: ubuntu-latest + steps: + - name: Result of the needed steps + run: echo "${{ toJSON(needs) }}" + - if: ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }} + run: exit 1 - - name: Install clippy - run: rustup component add clippy - - name: Annotate commit with clippy warnings - if: startsWith(matrix.os, 'ubuntu') - run: cargo clippy --workspace --all-features --all-targets + # Release unpublished packages or create a PR with changes + release-plz: + needs: [ ci-passed ] + if: | + always() + && needs.ci-passed.result == 'success' + && github.event_name == 'push' + && github.ref == 'refs/heads/main' + && github.repository_owner == 'oxibus' + runs-on: ubuntu-latest + permissions: + contents: write + id-token: write + pull-requests: write + concurrency: + group: release-plz-${{ github.ref }} + cancel-in-progress: false + steps: + - uses: actions/checkout@v6 + with: { fetch-depth: 0 } + - uses: dtolnay/rust-toolchain@stable + - name: Publish to crates.io if crate's version is newer + uses: release-plz/action@v0.5 + id: release + with: { command: release } + env: + GITHUB_TOKEN: ${{ secrets.RELEASE_PLZ_TOKEN }} + - if: ${{ steps.release.outputs.releases_created == 'false' }} + name: If version is the same, create a PR proposing new version and changelog for the next release + uses: release-plz/action@v0.5 + with: { command: release-pr } + env: + GITHUB_TOKEN: ${{ secrets.RELEASE_PLZ_TOKEN }} diff --git a/Cargo.lock b/Cargo.lock index 1acf114..785ce5e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -270,9 +270,9 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.7.6" +version = "0.7.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1d728cc89cf3aee9ff92b05e62b19ee65a02b5702cff7d5a377e32c6ae29d8d" +checksum = "c3e64b0cc0439b12df2fa678eae89a1c56a529fd067a9115f7827f1fffd22b32" [[package]] name = "colorchoice" diff --git a/Cargo.lock.msrv b/Cargo.lock.msrv new file mode 100644 index 0000000..7922e85 --- /dev/null +++ b/Cargo.lock.msrv @@ -0,0 +1,1254 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "anstream" +version = "0.6.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd2405b3ac1faab2990b74d728624cd9fd115651fcecc7c2d8daf01376275ba" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41ed9a86bf92ae6580e0a31281f65a1b1d867c0cc68d5346e2ae128dddfa6a7d" + +[[package]] +name = "anstyle-parse" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e765fd216e48e067936442276d1d57399e37bce53c264d6fefbe298080cb57ee" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b" +dependencies = [ + "windows-sys 0.48.0", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0699d10d2f4d628a98ee7b57b289abbc98ff3bad977cb3152709d4bf2330628" +dependencies = [ + "anstyle", + "windows-sys 0.48.0", +] + +[[package]] +name = "anyhow" +version = "1.0.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a23eb6b1614318a8071c9b2521f36b424b2c83db5eb3a0fead4a6c0809af6e61" + +[[package]] +name = "approx" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "072df7202e63b127ab55acfe16ce97013d5b97bf160489336d3f1840fd78e99e" +dependencies = [ + "num-traits", +] + +[[package]] +name = "arbitrary" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "775a8770d29db3dadcb858482cc240af7b2ffde4ac4de67d1d4955728103f0e2" + +[[package]] +name = "bindgen" +version = "0.72.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "993776b509cfb49c750f11b8f07a46fa23e0a1386ffc01fb1e7d343efc387895" +dependencies = [ + "bitflags 2.2.1", + "cexpr", + "clang-sys", + "itertools", + "log", + "prettyplease", + "proc-macro2", + "quote", + "regex", + "rustc-hash", + "shlex", + "syn", +] + +[[package]] +name = "bitflags" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f5cde24d1b2e2216a726368b2363a273739c91f4e3eb4e0dd12d672d396ad989" + +[[package]] +name = "bitflags" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24a6904aef64d73cf10ab17ebace7befb918b82164785cb89907993be7f83813" + +[[package]] +name = "bitvec" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" +dependencies = [ + "funty", + "radium", + "tap", + "wyz", +] + +[[package]] +name = "block-buffer" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03588e54c62ae6d763e2a80090d50353b785795361b4ff5b3bf0a5097fc31c0b" +dependencies = [ + "generic-array", +] + +[[package]] +name = "can-dbc" +version = "8.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5dbfd754b95a7c0b9d8a1baa8d4e427b49f491686c6e45c3e7b6b5e3bc6bf798" +dependencies = [ + "can-dbc-pest", + "encoding_rs", + "serde", + "thiserror", +] + +[[package]] +name = "can-dbc-pest" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70d4baf7c06ef884041a7fc2fbad73372fd4b7c1b5d1d3c009f0d96b6f0b0f3f" +dependencies = [ + "encoding_rs", + "pest", + "pest_derive", +] + +[[package]] +name = "can-embedded" +version = "0.1.0" +dependencies = [ + "anyhow", + "arbitrary", + "bitvec", + "can-messages", + "dbc-codegen", + "defmt", + "embedded-can", +] + +[[package]] +name = "can-messages" +version = "0.1.0" +dependencies = [ + "anyhow", + "arbitrary", + "bitvec", + "dbc-codegen", + "defmt", + "embedded-can", +] + +[[package]] +name = "cantools-messages" +version = "0.1.0" +dependencies = [ + "bindgen", + "can-messages", + "cc", +] + +[[package]] +name = "cc" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1aeb932158bd710538c73702db6945cb68a8fb08c519e6e12706b94263b36db8" +dependencies = [ + "shlex", +] + +[[package]] +name = "cexpr" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" +dependencies = [ + "nom", +] + +[[package]] +name = "cfg-if" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4c819a1287eb618df47cc647173c5c4c66ba19d888a6e50d605672aed3140de" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "clang-sys" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cb92721cb37482245ed88428f72253ce422b3b4ee169c70a0642521bb5db4cc" +dependencies = [ + "glob", + "libc", + "libloading", +] + +[[package]] +name = "clap" +version = "4.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80c21025abd42669a92efc996ef13cfb2c5c627858421ea58d5c3b331a6c134f" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "458bf1f341769dfcf849846f65dffdf9146daa56bcd2a47cb4e1de9915567c99" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "307bc0538d5f0f83b8248db3087aa92fe504e4691294d0c96c0eabc33f47ba47" +dependencies = [ + "heck 0.4.0", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" + +[[package]] +name = "colorchoice" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" + +[[package]] +name = "console" +version = "0.15.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "054ccb5b10f9f2cbf51eb355ca1d05c2d279ce1804688d0db74b4733a5aeafd8" +dependencies = [ + "encode_unicode", + "libc", + "once_cell", + "windows-sys 0.59.0", +] + +[[package]] +name = "cpufeatures" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28d997bd5e24a5928dd43e46dc529867e207907fe0b239c3477d924f7f2ca320" +dependencies = [ + "libc", +] + +[[package]] +name = "crypto-common" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4600d695eb3f6ce1cd44e6e291adceb2cc3ab12f20a33777ecd0bf6eba34e06" +dependencies = [ + "generic-array", +] + +[[package]] +name = "dbc-codegen" +version = "0.3.0" +dependencies = [ + "anyhow", + "bitvec", + "can-dbc", + "embedded-can", + "heck 0.5.0", + "insta", + "test_each_file", + "trybuild", + "typed-builder", + "walkdir", +] + +[[package]] +name = "dbc-codegen-cli" +version = "0.3.0" +dependencies = [ + "clap", + "dbc-codegen", + "exitcode", +] + +[[package]] +name = "defmt" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "548d977b6da32fa1d1fda2876453da1e7df63ad0304c8b3dae4dbe7b96f39b78" +dependencies = [ + "bitflags 1.0.0", + "defmt-macros", +] + +[[package]] +name = "defmt-macros" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d4fc12a85bcf441cfe44344c4b72d58493178ce635338a3f3b78943aceb258e" +dependencies = [ + "defmt-parser", + "proc-macro-error2", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "defmt-parser" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10d60334b3b2e7c9d91ef8150abfb6fa4c1c39ebbcf4a81c2e346aad939fee3e" +dependencies = [ + "thiserror", +] + +[[package]] +name = "digest" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8cb780dce4f9a8f5c087362b3a4595936b2019e7c8b30f2c3e9a7e94e6ae9837" +dependencies = [ + "block-buffer", + "crypto-common", +] + +[[package]] +name = "either" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5845bf77d497f79416df39462df26d4a8b71dd6440246848ee63709476dbb9a6" + +[[package]] +name = "embedded-can" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9d2e857f87ac832df68fa498d18ddc679175cf3d2e4aa893988e5601baf9438" +dependencies = [ + "nb", +] + +[[package]] +name = "encode_unicode" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34aa73646ffb006b8f5147f3dc182bd4bcb190227ce861fc4a4844bf8e3cb2c0" + +[[package]] +name = "encoding_rs" +version = "0.8.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75030f3c4f45dafd7586dd6780965a8c7e8e285a5ecb86713e63a79c5b2766f3" +dependencies = [ + "cfg-if 1.0.0", +] + +[[package]] +name = "equivalent" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" + +[[package]] +name = "exitcode" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de853764b47027c2e862a995c34978ffa63c1501f2e15f987ba11bd4f9bba193" + +[[package]] +name = "funty" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" + +[[package]] +name = "generic-array" +version = "0.14.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "501466ecc8a30d1d3b7fc9229b122b2ce8ed6e9d9223f1138d4babb253e51817" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getrandom" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "wasi", +] + +[[package]] +name = "glob" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" + +[[package]] +name = "hashbrown" +version = "0.16.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100" + +[[package]] +name = "heck" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "indexmap" +version = "2.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7714e70437a7dc3ac8eb7e6f8df75fd8eb422675fc7678aff7364301092b1017" +dependencies = [ + "equivalent", + "hashbrown", +] + +[[package]] +name = "insta" +version = "1.46.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b66886d14d18d420ab5052cbff544fc5d34d0b2cdd35eb5976aaa10a4a472e5" +dependencies = [ + "console", + "once_cell", + "similar", + "tempfile", +] + +[[package]] +name = "itertools" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37d572918e350e82412fe766d24b15e6682fb2ed2bbe018280caa810397cb319" +dependencies = [ + "either", +] + +[[package]] +name = "itoa" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2" + +[[package]] +name = "libc" +version = "0.2.180" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bcc35a38544a891a5f7c865aca548a982ccb3b8650a5b06d0fd33a10283c56fc" + +[[package]] +name = "libloading" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c979a19ffb457f0273965c333053f3d586bf759bf7b683fbebc37f9a9ebedc4" +dependencies = [ + "winapi", +] + +[[package]] +name = "log" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3a89a0c46ba789b8a247d4c567aed4d7c68e624672d238b45cc3ec20dc9f940" +dependencies = [ + "cfg-if 0.1.2", +] + +[[package]] +name = "memchr" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b16bd47d9e329435e309c58469fe0791c2d0d1ba96ec0954152a5ae2b04387dc" + +[[package]] +name = "minimal-lexical" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6595bb28ed34f43c3fe088e48f6cfb2e033cab45f25a5384d5fdf564fbc8c4b2" + +[[package]] +name = "nb" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "546c37ac5d9e56f55e73b677106873d9d9f5190605e41a856503623648488cae" + +[[package]] +name = "nom" +version = "7.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ffd9d26838a953b4af82cbeb9f1592c6798916983959be223a7124e992742c1" +dependencies = [ + "memchr", + "minimal-lexical", + "version_check", +] + +[[package]] +name = "num-traits" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7de20f146db9d920c45ee8ed8f71681fd9ade71909b48c3acbd766aa504cf10" + +[[package]] +name = "once_cell" +version = "1.21.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" + +[[package]] +name = "pest" +version = "2.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "989e7521a040efde50c3ab6bbadafbe15ab6dc042686926be59ac35d74607df4" +dependencies = [ + "memchr", + "ucd-trie", +] + +[[package]] +name = "pest_derive" +version = "2.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "187da9a3030dbafabbbfb20cb323b976dc7b7ce91fcd84f2f74d6e31d378e2de" +dependencies = [ + "pest", + "pest_generator", +] + +[[package]] +name = "pest_generator" +version = "2.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49b401d98f5757ebe97a26085998d6c0eecec4995cad6ab7fc30ffdf4b052843" +dependencies = [ + "pest", + "pest_meta", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "pest_meta" +version = "2.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72f27a2cfee9f9039c4d86faa5af122a0ac3851441a34865b8a043b46be0065a" +dependencies = [ + "pest", + "sha2", +] + +[[package]] +name = "ppv-lite86" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "prettyplease" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43ded2b5b204571f065ab8540367d738dfe1b3606ab9eb669dcfb5e7a3a07501" +dependencies = [ + "proc-macro2", + "syn", +] + +[[package]] +name = "proc-macro-error-attr2" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96de42df36bb9bba5542fe9f1a054b8cc87e172759a1868aa05c1f3acc89dfc5" +dependencies = [ + "proc-macro2", + "quote", +] + +[[package]] +name = "proc-macro-error2" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74cdd32837fa2e86ec09c8266e5aad92400ac934c6dbca83d54673b298db3e45" +dependencies = [ + "proc-macro-error-attr2", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "proc-macro2" +version = "1.0.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b33eb56c327dec362a9e55b3ad14f9d2f0904fb5a5b03b513ab5465399e9f43" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc74d9a594b72ae6656596548f56f667211f8a97b3d4c3d467150794690dc40a" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "radium" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" + +[[package]] +name = "rand" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" +dependencies = [ + "getrandom", + "libc", + "rand_chacha", + "rand_core", + "rand_hc", +] + +[[package]] +name = "rand_chacha" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" +dependencies = [ + "getrandom", +] + +[[package]] +name = "rand_hc" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" +dependencies = [ + "rand_core", +] + +[[package]] +name = "read_candump" +version = "0.1.0" +dependencies = [ + "approx", + "can-messages", + "embedded-can", +] + +[[package]] +name = "redox_syscall" +version = "0.1.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" + +[[package]] +name = "regex" +version = "1.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce5f1ceb7f74abbce32601642fcf8e8508a8a8991e0621c7d750295b9095702b" +dependencies = [ + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.6.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" + +[[package]] +name = "remove_dir_all" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" +dependencies = [ + "winapi", +] + +[[package]] +name = "rustc-hash" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7fb8039b3032c191086b10f11f319a6e99e1e82889c5cc6046f515c9db1d497" + +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "serde" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.149" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83fc039473c5595ace860d8c4fafa220ff474b3fc6bfdb4293327f1a37e94d86" +dependencies = [ + "itoa", + "memchr", + "serde", + "serde_core", + "zmij", +] + +[[package]] +name = "serde_spanned" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8bbf91e5a4d6315eee45e704372590b30e260ee83af6639d64557f51b067776" +dependencies = [ + "serde_core", +] + +[[package]] +name = "sha2" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99c3bd8169c58782adad9290a9af5939994036b76187f7b4f0e6de91dbbfc0ec" +dependencies = [ + "cfg-if 1.0.0", + "cpufeatures", + "digest", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "similar" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbbb5d9659141646ae647b42fe094daf6c6192d1620870b449d9557f748b2daa" + +[[package]] +name = "strsim" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ee073c9e4cd00e28217186dbe12796d692868f432bf2e97ee73bed0c56dfa01" + +[[package]] +name = "syn" +version = "2.0.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25aa4ce346d03a6dcd68dd8b4010bcb74e54e62c90c573f394c46eae99aba32d" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tap" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" + +[[package]] +name = "target-triple" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "591ef38edfb78ca4771ee32cf494cb8771944bee237a9b91fc9c1424ac4b777b" + +[[package]] +name = "tempfile" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9" +dependencies = [ + "cfg-if 0.1.2", + "libc", + "rand", + "redox_syscall", + "remove_dir_all", + "winapi", +] + +[[package]] +name = "termcolor" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "test_each_file" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2de773517ee4367314c7918f6c9ef69c201ba72bfdbffb00234c22c50a153b73" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "unicode-ident", +] + +[[package]] +name = "thiserror" +version = "2.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f63587ca0f12b72a0600bcba1d40081f830876000bb46dd2337a3051618f4fc8" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ff15c8ecd7de3849db632e14d18d2571fa09dfc5ed93479bc4485c7a517c913" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "toml" +version = "0.9.11+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3afc9a848309fe1aaffaed6e1546a7a14de1f935dc9d89d32afd9a44bab7c46" +dependencies = [ + "indexmap", + "serde_core", + "serde_spanned", + "toml_datetime", + "toml_parser", + "toml_writer", + "winnow", +] + +[[package]] +name = "toml_datetime" +version = "0.7.5+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92e1cfed4a3038bc5a127e35a2d360f145e1f4b971b551a2ba5fd7aedf7e1347" +dependencies = [ + "serde_core", +] + +[[package]] +name = "toml_parser" +version = "1.0.6+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3198b4b0a8e11f09dd03e133c0280504d0801269e9afa46362ffde1cbeebf44" +dependencies = [ + "winnow", +] + +[[package]] +name = "toml_writer" +version = "1.0.6+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab16f14aed21ee8bfd8ec22513f7287cd4a91aa92e44edfe2c17ddd004e92607" + +[[package]] +name = "trybuild" +version = "1.0.114" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e17e807bff86d2a06b52bca4276746584a78375055b6e45843925ce2802b335" +dependencies = [ + "glob", + "serde", + "serde_derive", + "serde_json", + "target-triple", + "termcolor", + "toml", +] + +[[package]] +name = "typed-builder" +version = "0.23.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31aa81521b70f94402501d848ccc0ecaa8f93c8eb6999eb9747e72287757ffda" +dependencies = [ + "typed-builder-macro", +] + +[[package]] +name = "typed-builder-macro" +version = "0.23.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "076a02dc54dd46795c2e9c8282ed40bcfb1e22747e955de9389a1de28190fb26" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "typenum" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "373c8a200f9e67a0c95e62a4f52fbf80c23b4381c05a17845531982fa99e6b33" + +[[package]] +name = "ucd-trie" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e79c4d996edb816c91e4308506774452e55e95c3c9de07b6729e17e15a5ef81" + +[[package]] +name = "unicode-ident" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" + +[[package]] +name = "utf8parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" + +[[package]] +name = "version_check" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45d3d553fd9413fffe7147a20171d640eda0ad4c070acd7d0c885a21bcd2e8b7" + +[[package]] +name = "walkdir" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" +dependencies = [ + "same-file", + "winapi-util", +] + +[[package]] +name = "wasi" +version = "0.9.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" + +[[package]] +name = "winapi" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3ad91d846a4a5342c1fb7008d26124ee6cf94a3953751618577295373b32117" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a16a8e2ebfc883e2b1771c6482b1fb3c6831eab289ba391619a2d93a7356220f" + +[[package]] +name = "winapi-util" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" +dependencies = [ + "windows-sys 0.48.0", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ca29cb03c8ceaf20f8224a18a530938305e9872b1478ea24ff44b4f503a1d1d" + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.0", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b1eb6f0cd7c80c79759c929114ef071b87354ce476d9d94271031c0497adfd5" +dependencies = [ + "windows_aarch64_gnullvm 0.48.0", + "windows_aarch64_msvc 0.48.0", + "windows_i686_gnu 0.48.0", + "windows_i686_msvc 0.48.0", + "windows_x86_64_gnu 0.48.0", + "windows_x86_64_gnullvm 0.48.0", + "windows_x86_64_msvc 0.48.0", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "winnow" +version = "0.7.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a5364e9d77fcdeeaa6062ced926ee3381faa2ee02d3eb83a5c27a8825540829" + +[[package]] +name = "wyz" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30b31594f29d27036c383b53b59ed3476874d518f0efb151b27a4c275141390e" +dependencies = [ + "tap", +] + +[[package]] +name = "zerocopy" +version = "0.8.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "668f5168d10b9ee831de31933dc111a459c97ec93225beb307aed970d1372dfd" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.8.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c7962b26b0a8685668b671ee4b54d007a67d4eaf05fda79ac0ecf41e32270f1" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zmij" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac93432f5b761b22864c774aac244fa5c0fd877678a4c37ebf6cf42208f9c9ec" diff --git a/deny.toml b/deny.toml index 447d1ae..a899554 100644 --- a/deny.toml +++ b/deny.toml @@ -9,5 +9,4 @@ allow = [ "Apache-2.0", "BSD-3-Clause", "MIT", - "Unicode-DFS-2016", ] diff --git a/justfile b/justfile index 4178020..d80ab9c 100755 --- a/justfile +++ b/justfile @@ -21,14 +21,15 @@ export RUST_BACKTRACE := env('RUST_BACKTRACE', if ci_mode == '1' {'1'} else {'0' # Run all tests and save its output as the new expected output. bless: bless-generate bless-compile -# Run code generation tests and save its output as the new expected output -bless-generate: (cargo-install 'cargo-insta') - cargo insta test --accept --include-ignored --unreferenced=delete --all-features -- --skip compile_test - # Compile generated code tests and save its output as the new expected output bless-compile: TRYBUILD=overwrite cargo test --all-features -- --test compile_test +# Run code generation tests and save its output as the new expected output +bless-generate: (cargo-install 'cargo-insta') + rm -rf tests-snapshots + cargo insta test --accept --include-ignored --unreferenced=delete --all-features -- --skip compile_test + # Generate all snapshots, including forced (.gitignore-d) ones bless-generate-all: rm -rf tests-snapshots @@ -43,6 +44,10 @@ build-diagram: @echo " npm install -g @mermaid-js/mermaid-cli" mmdc -i docs/diagram.mmd -o docs/diagram.svg +# Test building for an embedded no_std target +build-thumbv7em-none-eabihf: (rustup-add-target 'thumbv7em-none-eabihf') + cargo build --package can-embedded --target thumbv7em-none-eabihf --no-default-features + # Quick compile without building a binary check: cargo check --workspace --all-features --all-targets @@ -55,13 +60,13 @@ ci-coverage: env-info && \ mkdir -p target/llvm-cov # Run all tests as expected by CI -ci-test: env-info test-fmt check clippy test test-doc deny && assert-git-is-clean +ci-test: env-info test-fmt build build-thumbv7em-none-eabihf clippy test test-doc deny && assert-git-is-clean # Run minimal subset of tests to ensure compatibility with MSRV ci-test-msrv: if [ ! -f Cargo.lock.bak ]; then mv Cargo.lock Cargo.lock.bak ; fi cp Cargo.lock.msrv Cargo.lock - {{just}} env-info check test + {{just}} env-info build build-thumbv7em-none-eabihf rm Cargo.lock mv Cargo.lock.bak Cargo.lock @@ -201,3 +206,15 @@ cargo-install $COMMAND $INSTALL_CMD='' *args='': { set +x; } 2>/dev/null fi fi + +# Check if cargo target is already installed, and install if needed +[private] +rustup-add-target target: + #!/usr/bin/env sh + set -eu + if ! rustup target list --installed | grep -q {{quote(target)}}; then + echo "Adding target {{target}}" + rustup target add {{quote(target)}} + else + echo "Target {{target}} is already installed" + fi diff --git a/release-plz.toml b/release-plz.toml new file mode 100644 index 0000000..1c6472e --- /dev/null +++ b/release-plz.toml @@ -0,0 +1,4 @@ +[workspace] +dependencies_update = true +git_release_name = "v{{ version }}" +git_tag_name = "v{{ version }}" diff --git a/src/lib.rs b/src/lib.rs index 64784f1..3fc2ab1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -150,11 +150,11 @@ pub fn codegen(config: Config<'_>, out: impl Write) -> Result<()> { Ok(()) } -fn render_dbc(mut w: impl Write, config: &Config<'_>, dbc: &Dbc) -> Result<()> { - render_root_enum(&mut w, dbc, config)?; +fn render_dbc(w: &mut impl Write, config: &Config<'_>, dbc: &Dbc) -> Result<()> { + render_root_enum(w, dbc, config)?; for msg in get_relevant_messages(dbc) { - render_message(&mut w, config, msg, dbc) + render_message(w, config, msg, dbc) .with_context(|| format!("write message `{}`", msg.name))?; writeln!(w)?; } @@ -162,20 +162,18 @@ fn render_dbc(mut w: impl Write, config: &Config<'_>, dbc: &Dbc) -> Result<()> { Ok(()) } -fn render_root_enum(mut w: impl Write, dbc: &Dbc, config: &Config<'_>) -> Result<()> { +fn render_root_enum(w: &mut impl Write, dbc: &Dbc, config: &Config<'_>) -> Result<()> { writeln!(w, "/// All messages")?; writeln!(w, "{ALLOW_LINTS}")?; - config.write_allow_dead_code(&mut w)?; + config.write_allow_dead_code(w)?; writeln!(w, "#[derive(Clone)]")?; - config.impl_debug.fmt_attr(&mut w, "derive(Debug)")?; - config - .impl_defmt - .fmt_attr(&mut w, "derive(defmt::Format)")?; - config.impl_serde.fmt_attr(&mut w, "derive(Serialize)")?; - config.impl_serde.fmt_attr(&mut w, "derive(Deserialize)")?; + config.impl_debug.fmt_attr(w, "derive(Debug)")?; + config.impl_defmt.fmt_attr(w, "derive(defmt::Format)")?; + config.impl_serde.fmt_attr(w, "derive(Serialize)")?; + config.impl_serde.fmt_attr(w, "derive(Deserialize)")?; writeln!(w, "pub enum Messages {{")?; { - let mut w = PadAdapter::wrap(&mut w); + let mut w = PadAdapter::wrap(w); for msg in get_relevant_messages(dbc) { writeln!(w, "/// {}", msg.name)?; writeln!(w, "{0}({0}),", type_name(&msg.name))?; @@ -185,16 +183,17 @@ fn render_root_enum(mut w: impl Write, dbc: &Dbc, config: &Config<'_>) -> Result writeln!(w)?; writeln!(w, "{ALLOW_LINTS}")?; - config.write_allow_dead_code(&mut w)?; + config.write_allow_dead_code(w)?; writeln!(w, "impl Messages {{")?; { - let mut w = PadAdapter::wrap(&mut w); + let mut w = PadAdapter::wrap(w); writeln!(w, "/// Read message from CAN frame")?; writeln!(w, "#[inline(never)]")?; writeln!( w, - "pub fn from_can_message(id: Id, payload: &[u8]) -> Result {{", + "pub fn from_can_message(id: Id, payload: &[u8]) -> Result {{" )?; + { let mut w = PadAdapter::wrap(&mut w); writeln!(w)?; @@ -222,7 +221,7 @@ fn render_root_enum(mut w: impl Write, dbc: &Dbc, config: &Config<'_>) -> Result Ok(()) } -fn render_message(mut w: impl Write, config: &Config<'_>, msg: &Message, dbc: &Dbc) -> Result<()> { +fn render_message(w: &mut impl Write, config: &Config<'_>, msg: &Message, dbc: &Dbc) -> Result<()> { writeln!(w, "/// {}", msg.name)?; writeln!(w, "///")?; match msg.id { @@ -240,11 +239,11 @@ fn render_message(mut w: impl Write, config: &Config<'_>, msg: &Message, dbc: &D } } writeln!(w, "#[derive(Clone, Copy)]")?; - config.impl_serde.fmt_attr(&mut w, "derive(Serialize)")?; - config.impl_serde.fmt_attr(&mut w, "derive(Deserialize)")?; + config.impl_serde.fmt_attr(w, "derive(Serialize)")?; + config.impl_serde.fmt_attr(w, "derive(Deserialize)")?; writeln!(w, "pub struct {} {{", type_name(&msg.name))?; { - let mut w = PadAdapter::wrap(&mut w); + let mut w = PadAdapter::wrap(w); config .impl_serde .fmt_attr(&mut w, "serde(with = \"serde_bytes\")")?; @@ -254,10 +253,10 @@ fn render_message(mut w: impl Write, config: &Config<'_>, msg: &Message, dbc: &D writeln!(w)?; writeln!(w, "{ALLOW_LINTS}")?; - config.write_allow_dead_code(&mut w)?; + config.write_allow_dead_code(w)?; writeln!(w, "impl {} {{", type_name(&msg.name))?; { - let mut w = PadAdapter::wrap(&mut w); + let mut w = PadAdapter::wrap(w); writeln!( w, @@ -278,19 +277,11 @@ fn render_message(mut w: impl Write, config: &Config<'_>, msg: &Message, dbc: &D .filter(|sig| signal_to_rust_type(sig) != "bool") { let typ = signal_to_rust_type(signal); - writeln!( - w, - "pub const {sig}_MIN: {typ} = {min}_{typ};", - sig = field_name(&signal.name).to_uppercase(), - min = signal.min, - )?; - - writeln!( - w, - "pub const {sig}_MAX: {typ} = {max}_{typ};", - sig = field_name(&signal.name).to_uppercase(), - max = signal.max, - )?; + let sig = field_name(&signal.name).to_uppercase(); + let min = signal.min; + let max = signal.max; + writeln!(w, "pub const {sig}_MIN: {typ} = {min}_{typ};")?; + writeln!(w, "pub const {sig}_MAX: {typ} = {max}_{typ};")?; } writeln!(w)?; @@ -323,7 +314,7 @@ fn render_message(mut w: impl Write, config: &Config<'_>, msg: &Message, dbc: &D w, "let {}res = Self {{ raw: [0u8; {}] }};", if msg.signals.is_empty() { "" } else { "mut " }, - msg.size + msg.size, )?; for signal in &msg.signals { if signal.multiplexer_indicator == MultiplexIndicator::Plain { @@ -364,26 +355,23 @@ fn render_message(mut w: impl Write, config: &Config<'_>, msg: &Message, dbc: &D writeln!(w, "}}")?; writeln!(w)?; - writeln!( - w, - "impl core::convert::TryFrom<&[u8]> for {} {{", - type_name(&msg.name) - )?; + let typ = type_name(&msg.name); + writeln!(w, "impl core::convert::TryFrom<&[u8]> for {typ} {{")?; { - let mut w = PadAdapter::wrap(&mut w); + let mut w = PadAdapter::wrap(w); writeln!(w, "type Error = CanError;")?; writeln!(w)?; writeln!(w, "#[inline(always)]")?; writeln!( w, - "fn try_from(payload: &[u8]) -> Result {{" + "fn try_from(payload: &[u8]) -> Result {{", )?; { let mut w = PadAdapter::wrap(&mut w); writeln!( w, r"if payload.len() != {} {{ return Err(CanError::InvalidPayloadSize); }}", - msg.size + msg.size, )?; writeln!(w, "let mut raw = [0u8; {}];", msg.size)?; writeln!(w, "raw.copy_from_slice(&payload[..{}]);", msg.size)?; @@ -394,13 +382,10 @@ fn render_message(mut w: impl Write, config: &Config<'_>, msg: &Message, dbc: &D writeln!(w, "}}")?; writeln!(w)?; - render_embedded_can_frame(&mut w, config, msg)?; - - render_debug_impl(&mut w, config, msg)?; - - render_defmt_impl(&mut w, config, msg)?; - - render_arbitrary(&mut w, config, msg)?; + render_embedded_can_frame(w, config, msg)?; + render_debug_impl(w, config, msg)?; + render_defmt_impl(w, config, msg)?; + render_arbitrary(w, config, msg)?; let enums_for_this_message = dbc.value_descriptions.iter().filter_map(|x| { if let ValueDescription::Signal { @@ -419,7 +404,7 @@ fn render_message(mut w: impl Write, config: &Config<'_>, msg: &Message, dbc: &D } }); for (signal, variants) in enums_for_this_message { - write_enum(&mut w, config, signal, msg, variants.as_slice())?; + write_enum(w, config, signal, msg, variants.as_slice())?; } let multiplexor_signal = msg @@ -435,7 +420,7 @@ fn render_message(mut w: impl Write, config: &Config<'_>, msg: &Message, dbc: &D } fn render_signal( - mut w: impl Write, + w: &mut impl Write, config: &Config<'_>, signal: &Signal, dbc: &Dbc, @@ -468,7 +453,7 @@ fn render_signal( // "f32" => |x: i64| format!("x if approx_eq!(f32, x, {x}_f32, ulps = 2)"), _ => |x: i64| format!("{x}"), }; - let mut w = PadAdapter::wrap(&mut w); + let mut w = PadAdapter::wrap(w); let read_fn = match signal.byte_order { can_dbc::ByteOrder::LittleEndian => { let (start, end) = le_start_end_bit(signal, msg)?; @@ -493,17 +478,11 @@ fn render_signal( let mut w = PadAdapter::wrap(&mut w); for variant in variants { let literal = match_on_raw_type(variant.id); - writeln!( - w, - "{literal} => {type_name}::{},", - enum_variant_name(&variant.description) - )?; + let variant_name = enum_variant_name(&variant.description); + writeln!(w, "{literal} => {type_name}::{variant_name},")?; } - writeln!( - w, - "_ => {type_name}::_Other(self.{}_raw()),", - field_name(&signal.name) - )?; + let field_name = field_name(&signal.name); + writeln!(w, "_ => {type_name}::_Other(self.{field_name}_raw()),")?; } writeln!(w, "}}")?; } @@ -517,7 +496,7 @@ fn render_signal( signal_to_rust_type(signal) )?; { - let mut w = PadAdapter::wrap(&mut w); + let mut w = PadAdapter::wrap(w); writeln!(w, "self.{}_raw()", field_name(&signal.name))?; } writeln!(w, "}}")?; @@ -540,19 +519,19 @@ fn render_signal( signal_to_rust_type(signal) )?; { - let mut w = PadAdapter::wrap(&mut w); + let mut w = PadAdapter::wrap(w); signal_from_payload(&mut w, signal, msg).context("signal from payload")?; } writeln!(w, "}}")?; writeln!(w)?; - render_set_signal(&mut w, config, signal, msg)?; + render_set_signal(w, config, signal, msg)?; Ok(()) } fn render_set_signal( - mut w: impl Write, + w: &mut impl Write, config: &Config<'_>, signal: &Signal, msg: &Message, @@ -576,7 +555,7 @@ fn render_set_signal( )?; { - let mut w = PadAdapter::wrap(&mut w); + let mut w = PadAdapter::wrap(w); if signal.size != 1 { if let FeatureConfig::Gated(gate) = config.check_ranges { @@ -584,21 +563,20 @@ fn render_set_signal( } if let FeatureConfig::Gated(..) | FeatureConfig::Always = config.check_ranges { - writeln!( - w, - r"if value < {min}_{typ} || {max}_{typ} < value {{", - typ = signal_to_rust_type(signal), - min = signal.min, - max = signal.max, - )?; + let typ = signal_to_rust_type(signal); + let min = signal.min; + let max = signal.max; + writeln!(w, r"if value < {min}_{typ} || {max}_{typ} < value {{")?; + { let mut w = PadAdapter::wrap(&mut w); + let typ = type_name(&msg.name); writeln!( w, - r"return Err(CanError::ParameterOutOfRange {{ message_id: {}::MESSAGE_ID }});", - type_name(&msg.name) + r"return Err(CanError::ParameterOutOfRange {{ message_id: {typ}::MESSAGE_ID }});", )?; } + writeln!(w, r"}}")?; } } @@ -612,7 +590,7 @@ fn render_set_signal( } fn render_set_signal_multiplexer( - mut w: impl Write, + w: &mut impl Write, multiplexor: &Signal, msg: &Message, switch_index: u64, @@ -627,17 +605,14 @@ fn render_set_signal_multiplexer( )?; { - let mut w = PadAdapter::wrap(&mut w); + let mut w = PadAdapter::wrap(w); writeln!(w, "let b0 = BitArray::<_, LocalBits>::new(self.raw);")?; writeln!(w, "let b1 = BitArray::<_, LocalBits>::new(value.raw);")?; writeln!(w, "self.raw = b0.bitor(b1).into_inner();")?; - writeln!( - w, - "self.set_{}({switch_index})?;", - field_name(&multiplexor.name), - )?; - writeln!(w, "Ok(())",)?; + let field_name = field_name(&multiplexor.name); + writeln!(w, "self.set_{field_name}({switch_index})?;")?; + writeln!(w, "Ok(())")?; } writeln!(w, "}}")?; @@ -647,7 +622,7 @@ fn render_set_signal_multiplexer( } fn render_multiplexor_signal( - mut w: impl Write, + w: &mut impl Write, config: &Config<'_>, signal: &Signal, msg: &Message, @@ -668,7 +643,7 @@ fn render_multiplexor_signal( signal_to_rust_type(signal) )?; { - let mut w = PadAdapter::wrap(&mut w); + let mut w = PadAdapter::wrap(w); signal_from_payload(&mut w, signal, msg).context("signal from payload")?; } writeln!(w, "}}")?; @@ -678,7 +653,7 @@ fn render_multiplexor_signal( w, "pub fn {}(&mut self) -> Result<{}, CanError> {{", field_name(&signal.name), - multiplex_enum_name(msg, signal)? + multiplex_enum_name(msg, signal)?, )?; let multiplexer_indexes: BTreeSet = msg @@ -695,7 +670,7 @@ fn render_multiplexor_signal( .collect(); { - let mut w = PadAdapter::wrap(&mut w); + let mut w = PadAdapter::wrap(w); writeln!(w, "match self.{}_raw() {{", field_name(&signal.name))?; { @@ -708,13 +683,13 @@ fn render_multiplexor_signal( enum_name = multiplex_enum_name(msg, signal)?, multiplexed_wrapper_name = multiplexed_enum_variant_wrapper_name(*multiplexer_index), multiplexed_name = - multiplexed_enum_variant_name(msg, signal, *multiplexer_index)? + multiplexed_enum_variant_name(msg, signal, *multiplexer_index)?, )?; } writeln!( w, "multiplexor => Err(CanError::InvalidMultiplexor {{ message_id: {}::MESSAGE_ID, multiplexor: multiplexor.into() }}),", - type_name(&msg.name) + type_name(&msg.name), )?; } @@ -722,10 +697,10 @@ fn render_multiplexor_signal( } writeln!(w, "}}")?; - render_set_signal(&mut w, config, signal, msg)?; + render_set_signal(w, config, signal, msg)?; for switch_index in multiplexer_indexes { - render_set_signal_multiplexer(&mut w, signal, msg, switch_index)?; + render_set_signal_multiplexer(w, signal, msg, switch_index)?; } Ok(()) @@ -749,11 +724,11 @@ fn be_start_end_bit(signal: &Signal, msg: &Message) -> Result<(u64, u64)> { ensure!( start_bit <= msg_bits, - "signal starts at {start_bit}, but message is only {msg_bits} bits" + "signal starts at {start_bit}, but message is only {msg_bits} bits", ); ensure!( end_bit <= msg_bits, - "signal ends at {end_bit}, but message is only {msg_bits} bits" + "signal ends at {end_bit}, but message is only {msg_bits} bits", ); Ok((start_bit, end_bit)) } @@ -763,7 +738,7 @@ fn le_start_end_bit(signal: &Signal, msg: &Message) -> Result<(u64, u64)> { let start_bit = signal.start_bit; ensure!( start_bit <= msg_bits, - "signal starts at {start_bit}, but message is only {msg_bits} bits" + "signal starts at {start_bit}, but message is only {msg_bits} bits", ); let end_bit = signal @@ -772,12 +747,12 @@ fn le_start_end_bit(signal: &Signal, msg: &Message) -> Result<(u64, u64)> { .context("overflow calculating last bit position")?; ensure!( end_bit <= msg_bits, - "signal ends at {end_bit}, but message is only {msg_bits} bits" + "signal ends at {end_bit}, but message is only {msg_bits} bits", ); Ok((start_bit, end_bit)) } -fn signal_from_payload(mut w: impl Write, signal: &Signal, msg: &Message) -> Result<()> { +fn signal_from_payload(w: &mut impl Write, signal: &Signal, msg: &Message) -> Result<()> { let read_fn = match signal.byte_order { can_dbc::ByteOrder::LittleEndian => { let (start, end) = le_start_end_bit(signal, msg)?; @@ -832,7 +807,7 @@ fn signal_from_payload(mut w: impl Write, signal: &Signal, msg: &Message) -> Res Ok(()) } -fn signal_to_payload(mut w: impl Write, signal: &Signal, msg: &Message) -> Result<()> { +fn signal_to_payload(w: &mut impl Write, signal: &Signal, msg: &Message) -> Result<()> { if signal.size == 1 { // Map boolean to byte so we can pack it writeln!(w, "let value = value as u8;")?; @@ -856,7 +831,7 @@ fn signal_to_payload(mut w: impl Write, signal: &Signal, msg: &Message) -> Resul writeln!( w, " .ok_or(CanError::ParameterOutOfRange {{ message_id: {}::MESSAGE_ID }})?;", - type_name(&msg.name) + type_name(&msg.name), )?; writeln!( w, @@ -879,14 +854,14 @@ fn signal_to_payload(mut w: impl Write, signal: &Signal, msg: &Message) -> Resul let (start, end) = le_start_end_bit(signal, msg)?; writeln!( w, - r"self.raw.view_bits_mut::()[{start}..{end}].store_le(value);" + r"self.raw.view_bits_mut::()[{start}..{end}].store_le(value);", )?; } can_dbc::ByteOrder::BigEndian => { let (start, end) = be_start_end_bit(signal, msg)?; writeln!( w, - r"self.raw.view_bits_mut::()[{start}..{end}].store_be(value);" + r"self.raw.view_bits_mut::()[{start}..{end}].store_be(value);", )?; } } @@ -896,7 +871,7 @@ fn signal_to_payload(mut w: impl Write, signal: &Signal, msg: &Message) -> Resul } fn write_enum( - mut w: impl Write, + w: &mut impl Write, config: &Config<'_>, signal: &Signal, msg: &Message, @@ -907,17 +882,15 @@ fn write_enum( writeln!(w, "/// Defined values for {}", signal.name)?; writeln!(w, "{ALLOW_LINTS}")?; - config.write_allow_dead_code(&mut w)?; + config.write_allow_dead_code(w)?; writeln!(w, "#[derive(Clone, Copy, PartialEq)]")?; - config.impl_debug.fmt_attr(&mut w, "derive(Debug)")?; - config - .impl_defmt - .fmt_attr(&mut w, "derive(defmt::Format)")?; - config.impl_serde.fmt_attr(&mut w, "derive(Serialize)")?; - config.impl_serde.fmt_attr(&mut w, "derive(Deserialize)")?; + config.impl_debug.fmt_attr(w, "derive(Debug)")?; + config.impl_defmt.fmt_attr(w, "derive(defmt::Format)")?; + config.impl_serde.fmt_attr(w, "derive(Serialize)")?; + config.impl_serde.fmt_attr(w, "derive(Deserialize)")?; writeln!(w, "pub enum {type_name} {{")?; { - let mut w = PadAdapter::wrap(&mut w); + let mut w = PadAdapter::wrap(w); for variant in variants { writeln!(w, "{},", enum_variant_name(&variant.description))?; } @@ -934,7 +907,7 @@ fn write_enum( _ => |x: i64| format!("{x}"), }; - let mut w = PadAdapter::wrap(&mut w); + let mut w = PadAdapter::wrap(w); writeln!(w, "fn from(val: {type_name}) -> {signal_rust_type} {{")?; { let mut w = PadAdapter::wrap(&mut w); @@ -950,7 +923,7 @@ fn write_enum( enum_variant_name(&variant.description), )?; } - writeln!(w, "{type_name}::_Other(x) => x,",)?; + writeln!(w, "{type_name}::_Other(x) => x,")?; } writeln!(w, "}}")?; } @@ -1175,9 +1148,9 @@ fn multiplex_enum_name(msg: &Message, multiplexor: &Signal) -> Result { ensure!( matches!( multiplexor.multiplexer_indicator, - MultiplexIndicator::Multiplexor + MultiplexIndicator::Multiplexor, ), - "signal {multiplexor:?} is not the multiplexor" + "signal {multiplexor:?} is not the multiplexor", ); Ok(format!( "{}{}Index", @@ -1194,9 +1167,9 @@ fn multiplexed_enum_variant_name( ensure!( matches!( multiplexor.multiplexer_indicator, - MultiplexIndicator::Multiplexor + MultiplexIndicator::Multiplexor, ), - "signal {multiplexor:?} is not the multiplexor" + "signal {multiplexor:?} is not the multiplexor", ); Ok(format!( @@ -1256,7 +1229,7 @@ impl embedded_can::Frame for {0} {{ }) } -fn render_debug_impl(mut w: impl Write, config: &Config<'_>, msg: &Message) -> Result<()> { +fn render_debug_impl(w: &mut impl Write, config: &Config<'_>, msg: &Message) -> Result<()> { match &config.impl_debug { FeatureConfig::Always => {} FeatureConfig::Gated(gate) => writeln!(w, r"#[cfg(feature = {gate:?})]")?, @@ -1266,10 +1239,10 @@ fn render_debug_impl(mut w: impl Write, config: &Config<'_>, msg: &Message) -> R let typ = type_name(&msg.name); writeln!(w, r"impl core::fmt::Debug for {typ} {{")?; { - let mut w = PadAdapter::wrap(&mut w); + let mut w = PadAdapter::wrap(w); writeln!( w, - "fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {{" + "fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {{", )?; { let mut w = PadAdapter::wrap(&mut w); @@ -1305,7 +1278,7 @@ fn render_debug_impl(mut w: impl Write, config: &Config<'_>, msg: &Message) -> R Ok(()) } -fn render_defmt_impl(mut w: impl Write, config: &Config<'_>, msg: &Message) -> Result<()> { +fn render_defmt_impl(w: &mut impl Write, config: &Config<'_>, msg: &Message) -> Result<()> { match &config.impl_defmt { FeatureConfig::Always => {} FeatureConfig::Gated(gate) => writeln!(w, r"#[cfg(feature = {gate:?})]")?, @@ -1315,7 +1288,7 @@ fn render_defmt_impl(mut w: impl Write, config: &Config<'_>, msg: &Message) -> R let typ = type_name(&msg.name); writeln!(w, r"impl defmt::Format for {typ} {{")?; { - let mut w = PadAdapter::wrap(&mut w); + let mut w = PadAdapter::wrap(w); writeln!(w, "fn format(&self, f: defmt::Formatter) {{")?; { let mut w = PadAdapter::wrap(&mut w); @@ -1348,7 +1321,7 @@ fn render_defmt_impl(mut w: impl Write, config: &Config<'_>, msg: &Message) -> R } fn render_multiplexor_enums( - mut w: impl Write, + w: &mut impl Write, config: &Config<'_>, dbc: &Dbc, msg: &Message, @@ -1372,29 +1345,25 @@ fn render_multiplexor_enums( writeln!(w, "/// Defined values for multiplexed signal {}", msg.name)?; writeln!(w, "{ALLOW_LINTS}")?; - config.write_allow_dead_code(&mut w)?; - - config.impl_debug.fmt_attr(&mut w, "derive(Debug)")?; - config - .impl_defmt - .fmt_attr(&mut w, "derive(defmt::Format)")?; - config.impl_serde.fmt_attr(&mut w, "derive(Serialize)")?; - config.impl_serde.fmt_attr(&mut w, "derive(Deserialize)")?; - writeln!( - w, - "pub enum {} {{", - multiplex_enum_name(msg, multiplexor_signal)? - )?; + config.write_allow_dead_code(w)?; + + config.impl_debug.fmt_attr(w, "derive(Debug)")?; + config.impl_defmt.fmt_attr(w, "derive(defmt::Format)")?; + config.impl_serde.fmt_attr(w, "derive(Serialize)")?; + config.impl_serde.fmt_attr(w, "derive(Deserialize)")?; + + let enum_name = multiplex_enum_name(msg, multiplexor_signal)?; + writeln!(w, "pub enum {enum_name} {{")?; { - let mut w = PadAdapter::wrap(&mut w); + let mut w = PadAdapter::wrap(w); for switch_index in multiplexed_signals.keys() { writeln!( w, "{multiplexed_wrapper_name}({multiplexed_name}),", multiplexed_wrapper_name = multiplexed_enum_variant_wrapper_name(*switch_index), multiplexed_name = - multiplexed_enum_variant_name(msg, multiplexor_signal, *switch_index)? + multiplexed_enum_variant_name(msg, multiplexor_signal, *switch_index)?, )?; } } @@ -1405,19 +1374,17 @@ fn render_multiplexor_enums( let struct_name = multiplexed_enum_variant_name(msg, multiplexor_signal, *switch_index)?; writeln!(w, "{ALLOW_LINTS}")?; - config.write_allow_dead_code(&mut w)?; - config.impl_debug.fmt_attr(&mut w, "derive(Debug)")?; - config - .impl_defmt - .fmt_attr(&mut w, "derive(defmt::Format)")?; - config.impl_serde.fmt_attr(&mut w, "derive(Serialize)")?; - config.impl_serde.fmt_attr(&mut w, "derive(Deserialize)")?; + config.write_allow_dead_code(w)?; + config.impl_debug.fmt_attr(w, "derive(Debug)")?; + config.impl_defmt.fmt_attr(w, "derive(defmt::Format)")?; + config.impl_serde.fmt_attr(w, "derive(Serialize)")?; + config.impl_serde.fmt_attr(w, "derive(Deserialize)")?; writeln!(w, r"#[derive(Default)]")?; writeln!(w, "pub struct {struct_name} {{ raw: [u8; {}] }}", msg.size)?; writeln!(w)?; writeln!(w, "{ALLOW_LINTS}")?; - config.write_allow_dead_code(&mut w)?; + config.write_allow_dead_code(w)?; writeln!(w, "impl {struct_name} {{")?; writeln!( @@ -1427,7 +1394,7 @@ fn render_multiplexor_enums( )?; for signal in multiplexed_signals { - render_signal(&mut w, config, signal, dbc, msg)?; + render_signal(w, config, signal, dbc, msg)?; } writeln!(w, "}}")?; @@ -1437,7 +1404,7 @@ fn render_multiplexor_enums( Ok(()) } -fn render_arbitrary(mut w: impl Write, config: &Config<'_>, msg: &Message) -> Result<()> { +fn render_arbitrary(w: &mut impl Write, config: &Config<'_>, msg: &Message) -> Result<()> { match &config.impl_arbitrary { FeatureConfig::Always => {} FeatureConfig::Gated(gate) => writeln!(w, r"#[cfg(feature = {gate:?})]")?, @@ -1445,12 +1412,9 @@ fn render_arbitrary(mut w: impl Write, config: &Config<'_>, msg: &Message) -> Re } writeln!(w, "{ALLOW_LINTS}")?; - config.write_allow_dead_code(&mut w)?; - writeln!( - w, - "impl<'a> Arbitrary<'a> for {typ} {{", - typ = type_name(&msg.name) - )?; + config.write_allow_dead_code(w)?; + let typ = type_name(&msg.name); + writeln!(w, "impl<'a> Arbitrary<'a> for {typ} {{")?; { let filtered_signals: Vec<&Signal> = msg .signals @@ -1460,7 +1424,7 @@ fn render_arbitrary(mut w: impl Write, config: &Config<'_>, msg: &Message) -> Re || signal.multiplexer_indicator == MultiplexIndicator::Multiplexor }) .collect(); - let mut w = PadAdapter::wrap(&mut w); + let mut w = PadAdapter::wrap(w); writeln!( w, "fn arbitrary({}u: &mut Unstructured<'a>) -> Result {{", @@ -1497,7 +1461,7 @@ fn render_arbitrary(mut w: impl Write, config: &Config<'_>, msg: &Message) -> Re Ok(()) } -fn render_error(mut w: impl Write, config: &Config<'_>) -> io::Result<()> { +fn render_error(w: &mut impl Write, config: &Config<'_>) -> io::Result<()> { w.write_all(include_bytes!("./includes/errors.rs"))?; config.impl_error.fmt_cfg(w, |w| { @@ -1505,8 +1469,8 @@ fn render_error(mut w: impl Write, config: &Config<'_>) -> io::Result<()> { }) } -fn render_arbitrary_helpers(mut w: impl Write, config: &Config<'_>) -> io::Result<()> { - config.impl_arbitrary.fmt_cfg(&mut w, |w| { +fn render_arbitrary_helpers(w: &mut impl Write, config: &Config<'_>) -> io::Result<()> { + config.impl_arbitrary.fmt_cfg(&mut *w, |w| { config.write_allow_dead_code(w)?; writeln!(w, "trait UnstructuredFloatExt {{")?; writeln!(w, " fn float_in_range(&mut self, range: core::ops::RangeInclusive) -> arbitrary::Result;")?; @@ -1514,24 +1478,15 @@ fn render_arbitrary_helpers(mut w: impl Write, config: &Config<'_>) -> io::Resul writeln!(w) })?; - config.impl_arbitrary.fmt_cfg(&mut w, |w| { - writeln!( - w, - "impl UnstructuredFloatExt for arbitrary::Unstructured<'_> {{" - )?; + config.impl_arbitrary.fmt_cfg(w, |w| { + writeln!(w, "impl UnstructuredFloatExt for arbitrary::Unstructured<'_> {{")?; writeln!(w, " fn float_in_range(&mut self, range: core::ops::RangeInclusive) -> arbitrary::Result {{")?; writeln!(w, " let min = range.start();")?; writeln!(w, " let max = range.end();")?; writeln!(w, " let steps = u32::MAX;")?; writeln!(w, " let factor = (max - min) / (steps as f32);")?; - writeln!( - w, - " let random_int: u32 = self.int_in_range(0..=steps)?;" - )?; - writeln!( - w, - " let random = min + factor * (random_int as f32);" - )?; + writeln!(w, " let random_int: u32 = self.int_in_range(0..=steps)?;")?; + writeln!(w, " let random = min + factor * (random_int as f32);")?; writeln!(w, " Ok(random)")?; writeln!(w, " }}")?; writeln!(w, "}}")?; @@ -1545,17 +1500,13 @@ fn signal_to_arbitrary(signal: &Signal) -> String { if signal.size == 1 { "u.int_in_range(0..=1)? == 1".to_string() } else if signal_is_float_in_rust(signal) { - format!( - "u.float_in_range({min}_f32..={max}_f32)?", - min = signal.min, - max = signal.max, - ) + let min = signal.min; + let max = signal.max; + format!("u.float_in_range({min}_f32..={max}_f32)?",) } else { - format!( - "u.int_in_range({min}..={max})?", - min = signal.min, - max = signal.max, - ) + let min = signal.min; + let max = signal.max; + format!("u.int_in_range({min}..={max})?",) } } @@ -1579,7 +1530,7 @@ impl Config<'_> { } impl FeatureConfig<'_> { - fn fmt_attr(&self, mut w: impl Write, attr: impl Display) -> io::Result<()> { + fn fmt_attr(&self, w: &mut impl Write, attr: impl Display) -> io::Result<()> { match self { FeatureConfig::Always => writeln!(w, "#[{attr}]"), FeatureConfig::Gated(gate) => writeln!(w, "#[cfg_attr(feature = {gate:?}, {attr})]"), @@ -1587,11 +1538,7 @@ impl FeatureConfig<'_> { } } - fn fmt_cfg( - &self, - mut w: W, - f: impl FnOnce(&mut W) -> io::Result<()>, - ) -> io::Result<()> { + fn fmt_cfg(&self, mut w: W, f: impl FnOnce(W) -> io::Result<()>) -> io::Result<()> { match self { // If config is Never, return immediately without calling `f` FeatureConfig::Never => return Ok(()), @@ -1605,7 +1552,7 @@ impl FeatureConfig<'_> { FeatureConfig::Always => {} } - f(&mut w) + f(w) } } @@ -1633,7 +1580,7 @@ mod tests { assert_eq!( get_range_of_values(Signed, 0, 1, 0), None, - "0 bit signal should be invalid" + "0 bit signal should be invalid", ); } @@ -1656,12 +1603,12 @@ mod tests { assert_eq!(signal_params_to_rust_int(Signed, 63, 1, 0).unwrap(), "i64"); assert_eq!( signal_params_to_rust_int(Unsigned, 64, -1, 0).unwrap(), - "i128" + "i128", ); assert_eq!( signal_params_to_rust_int(Unsigned, 65, 1, 0), None, - "This shouldn't be valid in a DBC, it's more than 64 bits" + "This shouldn't be valid in a DBC, it's more than 64 bits", ); } } diff --git a/src/pad.rs b/src/pad.rs index edeec0f..81f910d 100644 --- a/src/pad.rs +++ b/src/pad.rs @@ -25,15 +25,12 @@ impl Write for PadAdapter<'_> { self.buf.write_all(b" ")?; } - let split = match s.iter().position(|&v| v == b'\n') { - Some(pos) => { - self.on_newline = true; - pos.checked_add(1).unwrap() - } - None => { - self.on_newline = false; - s.len() - } + let split = if let Some(pos) = s.iter().position(|&v| v == b'\n') { + self.on_newline = true; + pos.checked_add(1).unwrap() + } else { + self.on_newline = false; + s.len() }; self.buf.write_all(&s[..split])?; s = &s[split..]; From edaa3d3f550be9fba766dfe94b465c1a149e580b Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Mon, 12 Jan 2026 23:48:13 -0500 Subject: [PATCH 2/4] Bump MSRV to 1.88 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 2e99bef..5074777 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,7 @@ exclude = [ keywords = ["dbc", "can", "automotive", "codegen", "embedded"] license = "MIT OR Apache-2.0" repository = "https://github.com/oxibus/dbc-codegen" -rust-version = "1.81.0" +rust-version = "1.88" [features] std = [] From 909cb7be28367157e92852acc2e8a518dcedce4e Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Mon, 12 Jan 2026 23:49:02 -0500 Subject: [PATCH 3/4] allow unicode 3 license --- deny.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/deny.toml b/deny.toml index a899554..e5ca97e 100644 --- a/deny.toml +++ b/deny.toml @@ -9,4 +9,5 @@ allow = [ "Apache-2.0", "BSD-3-Clause", "MIT", + "Unicode-3.0", ] From e924f826b6c32d5df1e9e4bf6b42ba391913af20 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Tue, 13 Jan 2026 00:00:25 -0500 Subject: [PATCH 4/4] adjust MSRV validation, default ws member --- Cargo.toml | 3 ++- justfile | 9 +++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5074777..0554502 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,7 +28,7 @@ anyhow = "1.0.100" can-dbc = "8.0.0" embedded-can = "0.4.1" heck = "0.5.0" -typed-builder = "0.23.2" +typed-builder = "0.23.0" [dev-dependencies] bitvec = "1.0.1" @@ -58,6 +58,7 @@ members = [ "testing/cantools-messages", "testing/rust-integration", ] +default-members = ["."] [package.metadata.docs.rs] # Indicates features that docs.rs should enable when building documentation. diff --git a/justfile b/justfile index d80ab9c..f8d311e 100755 --- a/justfile +++ b/justfile @@ -53,6 +53,11 @@ check: cargo check --workspace --all-features --all-targets cargo check --workspace --no-default-features --all-targets +check-msrv: (rustup-add-target 'thumbv7em-none-eabihf') + cargo check --all-features + cargo check --no-default-features + cargo check --package can-embedded --target thumbv7em-none-eabihf --no-default-features + # Generate code coverage report to upload to codecov.io ci-coverage: env-info && \ (coverage '--codecov --output-path target/llvm-cov/codecov.info') @@ -66,7 +71,7 @@ ci-test: env-info test-fmt build build-thumbv7em-none-eabihf clippy test test-do ci-test-msrv: if [ ! -f Cargo.lock.bak ]; then mv Cargo.lock Cargo.lock.bak ; fi cp Cargo.lock.msrv Cargo.lock - {{just}} env-info build build-thumbv7em-none-eabihf + {{just}} env-info check-msrv rm Cargo.lock mv Cargo.lock.bak Cargo.lock @@ -128,7 +133,7 @@ msrv: (cargo-install 'cargo-msrv') # Initialize Cargo.lock file with minimal versions of dependencies. msrv-init: (cargo-install 'cargo-minimal-versions') rm -f Cargo.lock.msrv Cargo.lock - @if ! cargo minimal-versions check --workspace ; then \ + @if ! cargo minimal-versions check ; then \ echo "ERROR: Could not generate minimal Cargo.lock.msrv" ;\ echo " fix the lock file with 'cargo update ... --precise ...'" ;\ echo " make sure it passes 'just check' " ;\