Skip to content

Commit b15cb68

Browse files
committed
fix clippy
1 parent b176f81 commit b15cb68

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

prover/src/io.rs

+16-6
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,28 @@ use halo2_proofs::{
44
plonk::{Circuit, VerifyingKey},
55
SerdeFormat,
66
};
7+
use serde::de::Deserialize;
78
use snark_verifier::util::arithmetic::PrimeField;
89
use snark_verifier_sdk::Snark;
10+
use std::io::BufReader;
911
use std::{
1012
fs::File,
1113
io::{Cursor, Read, Write},
1214
path::{Path, PathBuf},
1315
};
1416

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);
1825
}
1926

2027
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));
2229
deserializer.disable_recursion_limit();
2330
let deserializer = serde_stacker::Deserializer::new(&mut deserializer);
2431

@@ -53,7 +60,10 @@ pub fn serialize_instance(instance: &[Vec<Fr>]) -> Vec<u8> {
5360
serde_json::to_vec(&instances_for_serde).unwrap()
5461
}
5562

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+
{
5767
let mut buf = vec![];
5868
let mut fd = std::fs::File::open(filename).unwrap();
5969
fd.read_to_end(&mut buf).unwrap();
@@ -76,7 +86,7 @@ pub fn try_to_read(dir: &str, filename: &str) -> Option<Vec<u8>> {
7686
path.push(filename);
7787

7888
if path.exists() {
79-
Some(read_all(&path.to_string_lossy()))
89+
Some(read_all(path))
8090
} else {
8191
None
8292
}

prover/src/proof.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ pub fn dump_vk(dir: &str, filename: &str, raw_vk: &[u8]) {
119119

120120
pub fn from_json_file<'de, P: serde::Deserialize<'de>>(dir: &str, filename: &str) -> Result<P> {
121121
let file_path = dump_proof_path(dir, filename);
122-
crate::io::from_json_file(&file_path)
122+
crate::io::from_json_file(file_path)
123123
}
124124

125125
fn dump_proof_path(dir: &str, filename: &str) -> String {

0 commit comments

Comments
 (0)