Skip to content

Instantly share code, notes, and snippets.

@LaylBongers
Created April 22, 2019 13:55
Show Gist options
  • Save LaylBongers/1f8d437eb42daa3bed331762424aefab to your computer and use it in GitHub Desktop.
Save LaylBongers/1f8d437eb42daa3bed331762424aefab to your computer and use it in GitHub Desktop.
let mut formatted_bytes = Vec::new();
{
struct UnimplementedCliOptions;
impl rustfmt_nightly::CliOptions for UnimplementedCliOptions {
fn apply_to(self, _config: &mut Config) { unimplemented!() }
fn config_path(&self) -> Option<&std::path::Path> { unimplemented!() }
}
let (mut config, _) = load_config::<UnimplementedCliOptions>(None, None).unwrap();
config.set().emit_mode(EmitMode::Files);
config.set().edition(Edition::Edition2018);
let mut session = Session::new(config, Some(&mut formatted_bytes));
session.format(Input::Text(code)).unwrap();
}
String::from_utf8_lossy(&formatted_bytes).to_string()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment