Skip to content

Commit

Permalink
0.8.0 remove deprecated methods #34
Browse files Browse the repository at this point in the history
  • Loading branch information
maciejhirsz committed Jun 26, 2016
1 parent 8e3b796 commit b0f7a67
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 129 deletions.
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.7.4"
version = "0.8.0"
authors = ["Maciej Hirsz <[email protected]>"]
description = "JSON implementation in Rust"
repository = "https://github.com/maciejhirsz/json-rust"
Expand Down
5 changes: 0 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,11 +264,6 @@ pub fn from<T>(value: T) -> JsonValue where T: Into<JsonValue> {
value.into()
}

#[deprecated(since="0.5.0", note="Use `value.dump(0)` instead")]
pub fn stringify_ref(root: &JsonValue) -> String {
root.dump()
}

/// Pretty prints out the value as JSON string.
pub fn stringify<T>(root: T) -> String where T: Into<JsonValue> {
let root: JsonValue = root.into();
Expand Down
123 changes: 0 additions & 123 deletions src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,6 @@ impl JsonValue {
JsonValue::Array(Vec::new())
}

/// Checks if the value stored matches `other`.
#[deprecated(since="0.7.0", note="Use `value == other` instead")]
pub fn is<T>(&self, other: T) -> bool where T: Into<JsonValue> {
*self == other.into()
}

pub fn is_string(&self) -> bool {
match *self {
JsonValue::String(_) => true,
Expand Down Expand Up @@ -116,29 +110,13 @@ impl JsonValue {
}
}

#[deprecated(since="0.6.1", note="Use `as_str` instead")]
pub fn as_string(&self) -> JsonResult<&String> {
match *self {
JsonValue::String(ref value) => Ok(value),
_ => Err(JsonError::wrong_type("String"))
}
}

pub fn as_str(&self) -> Option<&str> {
match *self {
JsonValue::String(ref value) => Some(value.as_ref()),
_ => None
}
}

#[deprecated(since="0.6.1", note="Use `as_f64` instead")]
pub fn as_number(&self) -> JsonResult<&f64> {
match *self {
JsonValue::Number(ref value) => Ok(value),
_ => Err(JsonError::wrong_type("Number"))
}
}

pub fn as_f64(&self) -> Option<f64> {
match *self {
JsonValue::Number(ref value) => Some(*value),
Expand Down Expand Up @@ -197,75 +175,6 @@ impl JsonValue {
}
}

#[deprecated(since="0.6.1", note="Use `as_bool` instead")]
pub fn as_boolean(&self) -> JsonResult<&bool> {
match *self {
JsonValue::Boolean(ref value) => Ok(value),
_ => Err(JsonError::wrong_type("Boolean"))
}
}

/// Works on `JsonValue::Object` - create or override key with value.
#[must_use]
#[deprecated(since="0.6.0", note="Use `object[key] = value.into()` instead")]
pub fn put<T>(&mut self, key: &str, value: T) -> JsonResult<()>
where T: Into<JsonValue> {
match *self {
JsonValue::Object(ref mut btree) => {
btree.insert(key.into(), value.into());
Ok(())
},
_ => Err(JsonError::wrong_type("Object"))
}
}

/// Works on `JsonValue::Object` - get a reference to a value behind key.
/// For most purposes consider using `object[key]` instead.
#[deprecated(since="0.6.0", note="Use `object[key]` instead")]
pub fn get(&self, key: &str) -> JsonResult<&JsonValue> {
match *self {
JsonValue::Object(ref btree) => match btree.get(key) {
Some(value) => Ok(value),
_ => Err(JsonError::undefined(key))
},
_ => Err(JsonError::wrong_type("Object"))
}
}

/// Works on `JsonValue::Object` - get a mutable reference to a value behind
/// the key.
#[deprecated(since="0.6.0", note="Use `object[key]` instead")]
pub fn get_mut(&mut self, key: &str) -> JsonResult<&mut JsonValue> {
match *self {
JsonValue::Object(ref mut btree) => match btree.get_mut(key) {
Some(value) => Ok(value),
_ => Err(JsonError::undefined(key))
},
_ => Err(JsonError::wrong_type("Object"))
}
}

/// Attempts to get a mutable reference to the value behind a key on an
/// object. If the reference doesn't exists, it will be created and
/// assigned a null. If `self` is not an object, an empty object with
/// null key will be created.
#[deprecated(since="0.6.0", note="Use `object[key]` instead")]
pub fn with(&mut self, key: &str) -> &mut JsonValue {
if !self.is_object() {
*self = JsonValue::new_object();
}

match *self {
JsonValue::Object(ref mut btree) => {
if !btree.contains_key(key) {
btree.insert(key.to_string(), JsonValue::Null);
}
btree.get_mut(key).unwrap()
},
_ => unreachable!()
}
}

/// Works on `JsonValue::Array` - pushes a new value to the array.
#[must_use]
pub fn push<T>(&mut self, value: T) -> JsonResult<()>
Expand All @@ -290,38 +199,6 @@ impl JsonValue {
}
}

/// Works on `JsonValue::Array` - gets a reference to a value at index.
/// For most purposes consider using `array[index]` instead.
#[deprecated(since="0.6.0", note="Use `array[index]` instead")]
pub fn at(&self, index: usize) -> JsonResult<&JsonValue> {
match *self {
JsonValue::Array(ref vec) => {
if index < vec.len() {
Ok(&vec[index])
} else {
Err(JsonError::ArrayIndexOutOfBounds)
}
},
_ => Err(JsonError::wrong_type("Array"))
}
}

/// Works on `JsonValue::Array` - gets a mutable reference to a value
/// at index.
#[deprecated(since="0.6.0", note="Use `array[index]` instead")]
pub fn at_mut(&mut self, index: usize) -> JsonResult<&mut JsonValue> {
match *self {
JsonValue::Array(ref mut vec) => {
if index < vec.len() {
Ok(&mut vec[index])
} else {
Err(JsonError::ArrayIndexOutOfBounds)
}
},
_ => Err(JsonError::wrong_type("Array"))
}
}

/// Works on `JsonValue::Array` - checks if the array contains a value
pub fn contains<T>(&self, item: T) -> bool where T: Into<JsonValue> {
match *self {
Expand Down

0 comments on commit b0f7a67

Please sign in to comment.