A hacky wrapper around [rustfmt
] to format inside [if_chain
] invocations
rustfmt_if_chain
is not guaranteed to work on all Rust source files, but it should work on most of [Clippy]'s source files.
cargo install rustfmt_if_chain
Usage: rustfmt_if_chain FILENAME
Before
rust
fn main() -> PhilosophicalResult<()> {
if_chain! { if let Some (it) = tree . falls_in (forest) ; if ! listeners . any (| one | one . around_to_hear (it)) ; if ! it . makes_a_sound () ; then { return Err (PhilosophicalError :: new ()) ; } }
Ok(())
}
After
rust
fn main() -> PhilosophicalResult<()> {
if_chain! {
if let Some(it) = tree.falls_in(forest);
if !listeners.any(|one| one.around_to_hear(it));
if !it.makes_a_sound();
then {
return Err(PhilosophicalError::new());
}
}
Ok(())
}
rustfmt
is run on the original source file.if_chain
invocations are rewritten according to the following rules, where x
is an identifier that does not appear elsewhere in the file:
if_chain!
-> fn x()
if ... ;
-> if ... { x; }
then
-> if x
rustfmt
is run on the file resulting fro step 2.