Skip to content

Using rustfmt programmatically #1534

@kardeiz

Description

@kardeiz

Unless I am missing something, there isn't a super nice way to use rustfmt programmatically—

For example, I have a project where I am generating some repetitive Rust code with syn and quote in build.rs. The output is missing newlines, etc., so it is desirable to run the code through rustfmt.

Currently I am writing the generated string to a file and then using rustfmt::format_input to format and overwrite that file. This works, and is really not so bad, I was mostly just surprised to find that there was no function like fn(config: Config, input: &str) -> String.

Is there some reason not to support this simple case? Or am I missing something?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions