Skip to content

Commit 017a9ab

Browse files
committed
Format code using rustfmt before hashing (please don't yell at me for this D:)
1 parent f2ad3b3 commit 017a9ab

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

packages/vm-derive-impl/src/hash_function.rs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,33 @@
1+
use std::{
2+
io::Write,
3+
process::{Command, Stdio},
4+
};
5+
16
use proc_macro2::TokenStream;
27
use quote::quote;
38

49
use super::{bail, maybe};
510

11+
// i do what i must because i can
12+
fn format_code<C>(code: C) -> String
13+
where
14+
C: AsRef<[u8]>,
15+
{
16+
let mut child = Command::new("rustfmt")
17+
.stdin(Stdio::piped())
18+
.stdout(Stdio::piped())
19+
.spawn()
20+
.unwrap();
21+
22+
{
23+
let mut stdin = child.stdin.take().unwrap();
24+
stdin.write_all(code.as_ref()).unwrap();
25+
}
26+
27+
let output = child.wait_with_output().unwrap();
28+
String::from_utf8(output.stdout).unwrap()
29+
}
30+
631
pub fn hash_function_impl(attr: TokenStream, input: TokenStream) -> TokenStream {
732
if !attr.is_empty() {
833
bail!(attr, "Unexpected parameters");
@@ -11,8 +36,7 @@ pub fn hash_function_impl(attr: TokenStream, input: TokenStream) -> TokenStream
1136
// Just verify that this is actually a function
1237
let _: syn::ItemFn = maybe!(syn::parse2(input.clone()));
1338

14-
let display = input.to_string();
15-
panic!("display: {:?}", display);
39+
let display = format_code(input.to_string());
1640
let hex_hash = blake3::hash(display.as_bytes()).to_hex();
1741
let hex_hash = hex_hash.as_str();
1842

0 commit comments

Comments
 (0)