Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "json"
version = "0.10.3"
version = "0.11.0"
authors = ["Maciej Hirsz <[email protected]>"]
description = "JSON implementation in Rust"
repository = "https://github.com/maciejhirsz/json-rust"
Expand Down
4 changes: 4 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub enum Error {
column: usize,
},
UnexpectedEndOfJson,
ExceededDepthLimit,
FailedUtf8Parsing,
WrongType(String),
}
Expand All @@ -35,6 +36,7 @@ impl fmt::Display for Error {
} => write!(f, "Unexpected character: {} at ({}:{})", ch, line, column),

UnexpectedEndOfJson => write!(f, "Unexpected end of JSON"),
ExceededDepthLimit => write!(f, "Exceeded depth limit"),
FailedUtf8Parsing => write!(f, "Failed to parse UTF-8 bytes"),
WrongType(ref s) => write!(f, "Wrong type, expected: {}", s),
}
Expand All @@ -44,9 +46,11 @@ impl fmt::Display for Error {
impl error::Error for Error {
fn description(&self) -> &str {
use Error::*;

match *self {
UnexpectedCharacter { .. } => "Unexpected character",
UnexpectedEndOfJson => "Unexpected end of JSON",
ExceededDepthLimit => "Exceeded depth limit",
FailedUtf8Parsing => "Failed to read bytes as UTF-8 from JSON",
WrongType(_) => "Wrong type",
}
Expand Down
7 changes: 7 additions & 0 deletions src/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,13 @@ impl Object {
}
}

#[inline]
pub fn override_last(&mut self, value: JsonValue) {
if let Some(node) = self.store.last_mut() {
node.value = value;
}
}

pub fn get(&self, key: &str) -> Option<&JsonValue> {
if self.store.len() == 0 {
return None;
Expand Down
Loading