Modify Rustfmt to force empty line between function bodies

⚓ Rust    📅 2025-07-18    👤 surdeus    👁️ 12      

surdeus

Warning

This post was published 61 days ago. The information described in this article may have changed.

Generally I am very happy with the defauts of Rustfmt.

Only this is what I do not like:

I would like an empty line between function bodies:

impl Something {
    pub fn path(&self) -Option<&String{
        self.path.as_ref()
    }
    pub fn set_path(&mut self, path: &str) {
        self.path = Some(path.to_string());
    }
    pub fn set_path_option(&mut self, path_option: Option<String>) {
        self.path = path_option;
    }
}

I would like an empty line between function bodies:

impl Something {
    pub fn path(&self) -Option<&String{
        self.path.as_ref()
    }

    pub fn set_path(&mut self, path: &str) {
        self.path = Some(path.to_string());
    }

    pub fn set_path_option(&mut self, path_option: Option<String>) {
        self.path = path_option;
    }
}

I could not find any option for this (Rustfmt), as this should not apply to all braces and for functions this options does not seem available.

2 posts - 2 participants

Read full topic

🏷️ rust_feed