Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
add build.rs usage example
  • Loading branch information
mfreeborn authored Jul 23, 2023
1 parent f4e8afe commit 3e644f1
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,18 @@ convenient for a human to read and debug.
Be aware that no kind of hygiene or span information is retained when tokens are
written to a file; the conversion from tokens to source code is lossy.

Example usage in build.rs:

```rust
let input = quote! { ... };
let syntax_tree = syn::parse2(input).unwrap();
let formatted = prettyplease::unparse(&syntax_tree);

let out_dir = env::var_os("OUT_DIR").unwrap();
let dest_path = Path::new(&out_dir).join("out.rs");
fs::write(dest_path, formatted).unwrap();
```

[prettyplease]: https://github.com/dtolnay/prettyplease

<br>
Expand Down

0 comments on commit 3e644f1

Please sign in to comment.