From 56d58eb3e6fc8b49d57c6daebb89ec2d508e10af Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Mon, 23 Jan 2017 21:08:20 -0800 Subject: [PATCH] Remove crufty Value methods --- json/src/value.rs | 48 ------------------------------------- json_tests/tests/test.rs.in | 9 ------- 2 files changed, 57 deletions(-) diff --git a/json/src/value.rs b/json/src/value.rs index c284dd6..a7a005c 100644 --- a/json/src/value.rs +++ b/json/src/value.rs @@ -77,31 +77,6 @@ fn parse_index(s: &str) -> Option { } impl Value { - /// If the `Value` is an Object, returns the value associated with the provided key. - /// Otherwise, returns None. - pub fn find<'a>(&'a self, key: &str) -> Option<&'a Value> { - match *self { - Value::Object(ref map) => map.get(key), - _ => None, - } - } - - /// Attempts to get a nested Value Object for each key in `keys`. - /// If any key is found not to exist, find_path will return None. - /// Otherwise, it will return the `Value` associated with the final key. - pub fn find_path<'a>(&'a self, keys: &[&str]) -> Option<&'a Value> { - let mut target = self; - for key in keys { - match target.find(key) { - Some(t) => { - target = t; - } - None => return None, - } - } - Some(target) - } - /// Looks up a value by a JSON Pointer. /// /// JSON Pointer defines a string syntax for identifying a specific value @@ -204,29 +179,6 @@ impl Value { Some(target) } - /// If the `Value` is an Object, performs a depth-first search until - /// a value associated with the provided key is found. If no value is found - /// or the `Value` is not an Object, returns None. - pub fn search<'a>(&'a self, key: &str) -> Option<&'a Value> { - match *self { - Value::Object(ref map) => { - match map.get(key) { - Some(json_value) => Some(json_value), - None => { - for (_, v) in map.iter() { - match v.search(key) { - x if x.is_some() => return x, - _ => (), - } - } - None - } - } - } - _ => None, - } - } - /// Returns true if the `Value` is an Object. Returns false otherwise. pub fn is_object(&self) -> bool { self.as_object().is_some() diff --git a/json_tests/tests/test.rs.in b/json_tests/tests/test.rs.in index 26e811e..59ce0eb 100644 --- a/json_tests/tests/test.rs.in +++ b/json_tests/tests/test.rs.in @@ -1276,15 +1276,6 @@ fn test_missing_renamed_field() { assert_eq!(value, Foo { x: Some(5) }); } -#[test] -fn test_find_path() { - let obj: Value = from_str(r#"{"x": {"a": 1}, "y": 2}"#).unwrap(); - - assert!(obj.find_path(&["x", "a"]).unwrap() == &1.into()); - assert!(obj.find_path(&["y"]).unwrap() == &2.into()); - assert!(obj.find_path(&["z"]).is_none()); -} - #[test] fn test_serialize_seq_with_no_len() { #[derive(Clone, Debug, PartialEq)]