#[rustfmt::skip]
allows you to skip a "block" of code while formatting, but this requires putting skip
on each {}
instead of Clang-style on/off
Consider this code:
fn add(a : i32, b : i32) -> i32 { a + b }
fn sub(a : i32, b : i32) -> i32 { a - b }
rustfmt will format this to:
fn add(a: i32, b: i32) -> i32 {
a + b
}
fn sub(a: i32, b: i32) -> i32 {
a - b
}
One needs two #[rustfmt::skip]
attributes instead of a single on/off
.
There is a rustfmt option for single-line functions, but this example is for demonstration purposes only. I want to control any possible rustfmt setting in the region.
A tool for formatting Rust code according to style guidelines.
rustfmt is a tool for formatting Rust source code. You can install it on Fedora by running: $ sudo dnf install rustfmt.
You could put the functions you do not want to format in a module, tag the entire module with a #[rustfmt::skip]
, then pull in the items to the parent module with use
.
#[rustfmt::skip]
mod unformatted {
pub fn add(a : i32, b : i32) -> i32 { a + b }
pub fn sub(a : i32, b : i32) -> i32 { a - b }
}
use unformatted::*;
fn main() {
dbg!(add(2, 3));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With