Skip to content

Commit dab9036

Browse files
authored
chore: use serde_json::from_str when possible (#8925)
chore: use serde_json::from_str when possible
1 parent a592f7a commit dab9036

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

crates/chisel/src/dispatcher.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -514,8 +514,7 @@ impl ChiselDispatcher {
514514
let json = response.json::<EtherscanABIResponse>().await.unwrap();
515515
if json.status == "1" && json.result.is_some() {
516516
let abi = json.result.unwrap();
517-
let abi: serde_json::Result<JsonAbi> =
518-
serde_json::from_slice(abi.as_bytes());
517+
let abi: serde_json::Result<JsonAbi> = serde_json::from_str(&abi);
519518
if let Ok(abi) = abi {
520519
let mut interface = format!(
521520
"// Interface of {}\ninterface {} {{\n",

crates/common/src/fs.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,8 @@ pub fn read_to_string(path: impl AsRef<Path>) -> Result<String> {
4343
pub fn read_json_file<T: DeserializeOwned>(path: &Path) -> Result<T> {
4444
// read the file into a byte array first
4545
// https://github.com/serde-rs/json/issues/160
46-
let bytes = read(path)?;
47-
serde_json::from_slice(&bytes)
48-
.map_err(|source| FsPathError::ReadJson { source, path: path.into() })
46+
let s = read_to_string(path)?;
47+
serde_json::from_str(&s).map_err(|source| FsPathError::ReadJson { source, path: path.into() })
4948
}
5049

5150
/// Writes the object as a JSON object.

0 commit comments

Comments
 (0)