Skip to content

Commit

Permalink
chore: use serde_json::from_str (#203)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes committed Sep 21, 2024
1 parent f50d9a4 commit aaef121
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
1 change: 0 additions & 1 deletion crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ workspace = true
alloy-primitives.workspace = true
cfg-if.workspace = true
dunce.workspace = true
memmap2.workspace = true
once_cell.workspace = true
path-slash.workspace = true
regex.workspace = true
Expand Down
5 changes: 2 additions & 3 deletions crates/core/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -587,9 +587,8 @@ pub fn tempdir(name: &str) -> Result<tempfile::TempDir, SolcIoError> {
/// Reads the json file and deserialize it into the provided type.
pub fn read_json_file<T: DeserializeOwned>(path: &Path) -> Result<T, SolcError> {
// See: https://github.com/serde-rs/json/issues/160
let file = fs::File::open(path).map_err(|err| SolcError::io(err, path))?;
let bytes = unsafe { memmap2::Mmap::map(&file).map_err(|err| SolcError::io(err, path))? };
serde_json::from_slice(&bytes).map_err(Into::into)
let s = fs::read_to_string(path).map_err(|err| SolcError::io(err, path))?;
serde_json::from_str(&s).map_err(Into::into)
}

/// Writes serializes the provided value to JSON and writes it to a file.
Expand Down

0 comments on commit aaef121

Please sign in to comment.