Skip to content

Remove trailing newline at the end of the string #68

Description

@philipostr

I am using this crate, along with indent, to generate code. For example:

let inner = indent::indent_by(4, indoc::indoc! {r#"
    println!("hello world");
    return true;
"#});

let outer = indoc::formatdoc! {r#"
    fn do_things() -> bool {{
        {inner}
    }}
"#};

The result should be

fn do_things() -> bool {
    println!("hello world");
    return true;
}

but it actually produces

fn do_things() -> bool {
    println!("hello world");
    return true;

}

Notice the extra newlines after the strings created by the indoc macros. I could fix this by doing either

indoc::indoc! {r#"
    stuff"#};

or

indoc::indoc! {r#"
    stuff
"#}.trim_end().to_string();

but both of these options are ugly, and I am using this crate entirely to not have ugly. I think that this idea is appropriate considering this crate already removes the leading newline as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions