@@ -4,21 +4,28 @@ use halo2_proofs::{
4
4
plonk:: { Circuit , VerifyingKey } ,
5
5
SerdeFormat ,
6
6
} ;
7
+ use serde:: de:: Deserialize ;
7
8
use snark_verifier:: util:: arithmetic:: PrimeField ;
8
9
use snark_verifier_sdk:: Snark ;
10
+ use std:: io:: BufReader ;
9
11
use std:: {
10
12
fs:: File ,
11
13
io:: { Cursor , Read , Write } ,
12
14
path:: { Path , PathBuf } ,
13
15
} ;
14
16
15
- pub fn from_json_file < ' de , P : serde:: Deserialize < ' de > > ( file_path : & str ) -> anyhow:: Result < P > {
16
- if !Path :: new ( & file_path) . exists ( ) {
17
- anyhow:: bail!( "File {file_path} doesn't exist" ) ;
17
+ pub fn from_json_file < ' de , P , T > ( filename : P ) -> anyhow:: Result < T >
18
+ where
19
+ P : AsRef < Path > ,
20
+ T : Deserialize < ' de > ,
21
+ {
22
+ let file_path = filename. as_ref ( ) ;
23
+ if !file_path. exists ( ) {
24
+ anyhow:: bail!( "File {:?} doesn't exist" , file_path) ;
18
25
}
19
26
20
27
let fd = File :: open ( file_path) ?;
21
- let mut deserializer = serde_json:: Deserializer :: from_reader ( fd ) ;
28
+ let mut deserializer = serde_json:: Deserializer :: from_reader ( BufReader :: new ( fd ) ) ;
22
29
deserializer. disable_recursion_limit ( ) ;
23
30
let deserializer = serde_stacker:: Deserializer :: new ( & mut deserializer) ;
24
31
@@ -53,7 +60,10 @@ pub fn serialize_instance(instance: &[Vec<Fr>]) -> Vec<u8> {
53
60
serde_json:: to_vec ( & instances_for_serde) . unwrap ( )
54
61
}
55
62
56
- pub fn read_all ( filename : & str ) -> Vec < u8 > {
63
+ pub fn read_all < P > ( filename : P ) -> Vec < u8 >
64
+ where
65
+ P : AsRef < Path > ,
66
+ {
57
67
let mut buf = vec ! [ ] ;
58
68
let mut fd = std:: fs:: File :: open ( filename) . unwrap ( ) ;
59
69
fd. read_to_end ( & mut buf) . unwrap ( ) ;
@@ -76,7 +86,7 @@ pub fn try_to_read(dir: &str, filename: &str) -> Option<Vec<u8>> {
76
86
path. push ( filename) ;
77
87
78
88
if path. exists ( ) {
79
- Some ( read_all ( & path. to_string_lossy ( ) ) )
89
+ Some ( read_all ( path) )
80
90
} else {
81
91
None
82
92
}
0 commit comments