Skip to main content

dedent_to

Function dedent_to 

Source
pub fn dedent_to(text: &str, indent: &str) -> Option<String>
Expand description

Reduce a block’s indentation to match the provided indentation.

This function looks at the first line in the block to determine the current indentation, then removes whitespace from each line to match the provided indentation.

Leading comments are ignored unless the block is only composed of comments.

Lines that are indented by less than the indent of the first line are left unchanged.

Lines that consist solely of whitespace are trimmed to a blank line.

§Panics

If the first line is indented by less than the provided indent.