Skip to content

Commit 89bc45f

Browse files
committed
io error
1 parent 43bf168 commit 89bc45f

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/error.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,16 @@ pub enum Error {
1010
BadJson(simd_json::Error),
1111
/// rope related failure
1212
Rope(&'static str),
13+
/// IO related failure
14+
IO(std::io::Error),
1315
}
1416

1517
impl fmt::Display for Error {
1618
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1719
match self {
1820
Error::BadJson(err) => write!(f, "bad json: {err}"),
1921
Error::Rope(err) => write!(f, "rope error: {err}"),
22+
Error::IO(err) => write!(f, "io error: {err}"),
2023
}
2124
}
2225
}
@@ -28,3 +31,9 @@ impl From<simd_json::Error> for Error {
2831
Error::BadJson(err)
2932
}
3033
}
34+
35+
impl From<std::io::Error> for Error {
36+
fn from(err: std::io::Error) -> Error {
37+
Error::IO(err)
38+
}
39+
}

src/source.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ impl SourceMap {
391391
Self::from_slice(&mut json_bytes)
392392
}
393393

394-
/// Create a [SourceMap] from [&mut [u8]].
394+
/// Create a SourceMap from a mutable byte slice (`&mut [u8]`).
395395
pub fn from_slice(json_bytes: &mut [u8]) -> Result<Self> {
396396
let value = simd_json::to_borrowed_value(json_bytes)?;
397397
Ok(Self {
@@ -440,13 +440,13 @@ impl SourceMap {
440440
/// Create a [SourceMap] from reader.
441441
pub fn from_reader<R: std::io::Read>(mut s: R) -> Result<Self> {
442442
let mut json_bytes = vec![];
443-
let _ = s.read_to_end(&mut json_bytes);
443+
s.read_to_end(&mut json_bytes)?;
444444
Self::from_slice(&mut json_bytes)
445445
}
446446

447447
/// Generate source map to a json string.
448448
pub fn to_json(&self) -> Result<String> {
449-
let json = simd_json::to_string(&self)?;
449+
let json = simd_json::serde::to_string(&self)?;
450450
Ok(json)
451451
}
452452

0 commit comments

Comments
 (0)