Hey, dumb Rust noob question:
cargo fmt
does not format the Cargo.toml
and config.toml
right? How do you auto-format those files in your projects?
Hey, dumb Rust noob question:
cargo fmt
does not format the Cargo.toml
and config.toml
right? How do you auto-format those files in your projects?
# needed by all users not maintainer
cargo install cargo-sort candid-extractor ic-wasm
# cleanup
cargo sort -w 1>/dev/null
Oh nice, thanks!
It didnât work in my workspace, though.
thread âmainâ panicked at /Users/daviddalbusco/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cargo-sort-1.0.9/src/sort.rs:113:46:
calledResult::unwrap()
on anErr
value: TomlError { message: âTOML parse error at line 11, column 7\n |\n11 | candid.workspace = true\n | ^\nUnexpected.
\nExpected=
\nâ }
note: run withRUST_BACKTRACE=1
environment variable to display a backtrace
It seems it doesnât support referencing workspace dependencies the way I do in my crates:
[dependencies]
candid.workspace = true
ic-cdk.workspace = true
etc
As a result, I gave Google another try and found prettier-plugin-toml, which seems to work. Probably less state-of-the-art, but itâll do.
Nevertheless, cool to know whatâs the cargo way!
Oh, maybe something like candid.workspace = true
is not officially supported by cargo? I borrowed this pattern from having a look at crates of the foundation.
On VSCode, you want this:
I saw that project too but actually wondered if it was still active because on crate, thereâs no README, and the last release was published 8 months ago. As you mention it, I notice now that the plugin is more active (I donât use VS Code). Coolio, thx for the tips!