Skip to content

Commit

Permalink
Add missing string de-serialization paths and update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Diggsey committed Sep 3, 2021
1 parent 23c8051 commit a5dbe78
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ijson"
version = "0.1.2"
version = "0.1.3"
authors = ["Diggory Blake <diggsey@googlemail.com>"]
edition = "2018"
readme = "README.md"
Expand All @@ -13,7 +13,7 @@ description = "A more memory efficient replacement for serde_json::Value"
tracing = ["mockalloc/tracing"]

[dependencies]
dashmap = { version = "3.11.10", features = ["raw-api"] }
dashmap = { version = "4.0.2", features = ["raw-api"] }
lazy_static = "1.4.0"
serde = "1.0.117"
serde_json = "1.0.59"
Expand All @@ -22,4 +22,4 @@ ctor = { version = "0.1.16", optional = true }
[dev-dependencies]
mockalloc = "0.1.2"
ctor = "0.1.16"
rand = "0.7.3"
rand = "0.8.4"
2 changes: 1 addition & 1 deletion src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ mod tests {
let mut arr = IArray::new();

for j in 0..1000 {
let index = rng.gen_range(0, arr.len() + 1);
let index = rng.gen_range(0..arr.len() + 1);
if rng.gen() {
arr.insert(index, j);
} else {
Expand Down
24 changes: 24 additions & 0 deletions src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,30 @@ impl<'de> Visitor<'de> for StringVisitor {
fn visit_str<E: SError>(self, value: &str) -> Result<IString, E> {
Ok(value.into())
}

#[inline]
fn visit_string<E: SError>(self, value: String) -> Result<Self::Value, E> {
Ok(value.into())
}

#[inline]
fn visit_bytes<E: SError>(self, value: &[u8]) -> Result<Self::Value, E> {
match std::str::from_utf8(value) {
Ok(s) => Ok(s.into()),
Err(_) => Err(SError::invalid_value(Unexpected::Bytes(value), &self)),
}
}

#[inline]
fn visit_byte_buf<E: SError>(self, value: Vec<u8>) -> Result<Self::Value, E> {
match String::from_utf8(value) {
Ok(s) => Ok(s.into()),
Err(e) => Err(SError::invalid_value(
Unexpected::Bytes(&e.into_bytes()),
&self,
)),
}
}
}

struct ArrayVisitor;
Expand Down

0 comments on commit a5dbe78

Please sign in to comment.