File tree Expand file tree Collapse file tree 3 files changed +43
-5
lines changed Expand file tree Collapse file tree 3 files changed +43
-5
lines changed Original file line number Diff line number Diff line change @@ -11,4 +11,4 @@ blake3 = "1.5.4"
11
11
cargo-manifest = " 0.15.2"
12
12
proc-macro2 = " 1.0.86"
13
13
quote = " 1.0.37"
14
- syn = { version = " 2.0.77" , features = [" full" ] }
14
+ syn = { version = " 2.0.77" , features = [" extra-traits " , " full" ] }
Original file line number Diff line number Diff line change
1
+ use std:: hash:: { Hash , Hasher } ;
2
+
1
3
use proc_macro2:: TokenStream ;
2
4
use quote:: quote;
3
5
4
6
use super :: { bail, maybe} ;
5
7
8
+ struct Blake3Hasher {
9
+ hasher : blake3:: Hasher ,
10
+ }
11
+
12
+ impl Blake3Hasher {
13
+ fn new ( ) -> Self {
14
+ Self {
15
+ hasher : blake3:: Hasher :: new ( ) ,
16
+ }
17
+ }
18
+
19
+ fn consume ( self ) -> String {
20
+ self . hasher . finalize ( ) . to_hex ( ) . to_string ( )
21
+ }
22
+ }
23
+
24
+ impl Hasher for Blake3Hasher {
25
+ fn write ( & mut self , bytes : & [ u8 ] ) {
26
+ self . hasher . update ( bytes) ;
27
+ }
28
+
29
+ fn finish ( & self ) -> u64 {
30
+ unimplemented ! ( ) ;
31
+ }
32
+ }
33
+
6
34
pub fn hash_function_impl ( attr : TokenStream , input : TokenStream ) -> TokenStream {
7
35
if !attr. is_empty ( ) {
8
36
bail ! ( attr, "Unexpected parameters" ) ;
9
37
}
10
38
11
39
// Just verify that this is actually a function
12
- let _: syn:: ItemFn = maybe ! ( syn:: parse2( input. clone( ) ) ) ;
40
+ let function: syn:: ItemFn = maybe ! ( syn:: parse2( input. clone( ) ) ) ;
41
+
42
+ let mut hasher = Blake3Hasher :: new ( ) ;
43
+ function. hash ( & mut hasher) ;
13
44
14
- let display = input. to_string ( ) ;
15
- let hex_hash = blake3:: hash ( display. as_bytes ( ) ) . to_hex ( ) ;
16
- let hex_hash = hex_hash. as_str ( ) ;
45
+ let hex_hash = hasher. consume ( ) ;
17
46
18
47
quote ! {
19
48
#input
Original file line number Diff line number Diff line change @@ -465,4 +465,13 @@ mod tests {
465
465
assert_eq ! ( v2, v3) ;
466
466
assert_eq ! ( v3, v4) ;
467
467
}
468
+
469
+ #[ test]
470
+ fn module_version_static ( ) {
471
+ let version = raw_module_version_discriminator ( ) ;
472
+ assert_eq ! (
473
+ version,
474
+ "9ef3de8cb5fb770171ae3ea14db67fe25d946fef383472a18ddd75ced7bfcd4b"
475
+ ) ;
476
+ }
468
477
}
You can’t perform that action at this time.
0 commit comments