about summary refs log tree commit diff
path: root/src/libserialize
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-11-06 08:06:50 +0000
committerbors <bors@rust-lang.org>2014-11-06 08:06:50 +0000
commite84e7a00ddec76570bbaa9afea385d544f616814 (patch)
tree5757b1eec689ab03459c9f2518cc602284c44733 /src/libserialize
parent0e2f9b948564708085373fc28d91b4524c821fa3 (diff)
parent11f4baeafb83459befd0196b2b82cda7ed5ea2f1 (diff)
downloadrust-e84e7a00ddec76570bbaa9afea385d544f616814.tar.gz
rust-e84e7a00ddec76570bbaa9afea385d544f616814.zip
auto merge of #18467 : japaric/rust/eq, r=alexcrichton
`eq`, `ne`, `cmp`, etc methods now require one less level of indirection when dealing with `&str`/`&[T]`

``` rust
"foo".ne(&"bar") -> "foo".ne("bar")
slice.cmp(&another_slice) -> slice.cmp(another_slice)
// slice and another_slice have type `&[T]`
```

[breaking-change]
Diffstat (limited to 'src/libserialize')
-rw-r--r--src/libserialize/json.rs38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/libserialize/json.rs b/src/libserialize/json.rs
index e0d436f5e0e..dbdfa17bfc2 100644
--- a/src/libserialize/json.rs
+++ b/src/libserialize/json.rs
@@ -890,6 +890,8 @@ impl Json {
 
      /// If the Json value is an Object, returns the value associated with the provided key.
     /// Otherwise, returns None.
+    // NOTE(stage0): remove function after a snapshot
+    #[cfg(stage0)]
     pub fn find<'a>(&'a self, key: &str) -> Option<&'a Json>{
         match self {
             &Object(ref map) => map.find_with(|s| key.cmp(&s.as_slice())),
@@ -897,6 +899,16 @@ impl Json {
         }
     }
 
+     /// If the Json value is an Object, returns the value associated with the provided key.
+    /// Otherwise, returns None.
+    #[cfg(not(stage0))]  // NOTE(stage0): remove cfg after a snapshot
+    pub fn find<'a>(&'a self, key: &str) -> Option<&'a Json>{
+        match self {
+            &Object(ref map) => map.find_with(|s| key.cmp(s.as_slice())),
+            _ => None
+        }
+    }
+
     /// Attempts to get a nested Json Object for each key in `keys`.
     /// If any key is found not to exist, find_path will return None.
     /// Otherwise, it will return the Json value associated with the final key.
@@ -914,6 +926,8 @@ impl Json {
     /// If the Json 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 Json value is not an Object, returns None.
+    // NOTE(stage0): remove function after a snapshot
+    #[cfg(stage0)]
     pub fn search<'a>(&'a self, key: &str) -> Option<&'a Json> {
         match self {
             &Object(ref map) => {
@@ -934,6 +948,30 @@ impl Json {
         }
     }
 
+    /// If the Json 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 Json value is not an Object, returns None.
+    #[cfg(not(stage0))]  // NOTE(stage0): remove cfg after a snapshot
+    pub fn search<'a>(&'a self, key: &str) -> Option<&'a Json> {
+        match self {
+            &Object(ref map) => {
+                match map.find_with(|s| key.cmp(s.as_slice())) {
+                    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 Json value is an Object. Returns false otherwise.
     pub fn is_object<'a>(&'a self) -> bool {
         self.as_object().is_some()