diff options
author | Michael Freeborn <31806808+mfreeborn@users.noreply.github.com> | 2023-07-23 11:40:37 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-23 11:40:37 +0100 |
commit | 3e644f1624b7b3039df52c4dee2a8bec525b0216 (patch) | |
tree | deb23bd9bd95c5d04738215814e67ca37a456ba9 | |
parent | f4e8afed8770681efd8a3e08da527ae9728c63cc (diff) | |
download | quote-3e644f1624b7b3039df52c4dee2a8bec525b0216.tar.gz |
Update README.md
add build.rs usage example
-rw-r--r-- | README.md | 12 |
1 files changed, 12 insertions, 0 deletions
@@ -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> |