Skip to content
This repository has been archived by the owner on Oct 26, 2023. It is now read-only.

A simple wrapper around rustfmt to use it as a library for use when generating code

License

Notifications You must be signed in to change notification settings

franklin-ai/rustfmt-wrapper

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rustfmt-wrapper

Rust makes it easy to generate more Rust code--for macros, builders, whatever. It's nice to format that code to be a little easier on the eyes. While rustfmt does a pretty good job, it does a pretty good job as a command and isn't usable as a library. This is a probably-too-simple wrapper library.

It's pretty simple to use and mixes well with quote!:

let codegen = quote::quote!{ struct Foo { bar: String } };
let formatted: String = rustfmt_wrapper::rustfmt(codegen).unwrap();

If you need more control over the vast array of rustfmt configuration options, you can use the second form:

let codegen = quote::quote!{
    async fn go() {
        let _ = Client::new().operation_id().send().await?;
    }
};
let config = Config {
    max_width: Some(45),
    ..Default::default()
};

let narrow_formatted = rustfmt_config(config, codegen).unwrap();

Note that in order to use unstable configuration options, you will need to have a the nightly version of rustfmt installed.


Thanks to David Tolnay for so many tools including cargo-expand from which this borrows.

About

A simple wrapper around rustfmt to use it as a library for use when generating code

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Rust 100.0%