]> git.lizzy.rs Git - rust.git/commitdiff
serialize: fix fallout
authorJorge Aparicio <japaricious@gmail.com>
Sat, 3 Jan 2015 15:40:26 +0000 (10:40 -0500)
committerJorge Aparicio <japaricious@gmail.com>
Sat, 3 Jan 2015 21:30:49 +0000 (16:30 -0500)
src/libserialize/json.rs

index 83badb0c57c82f8928ebd20f7de803849209892a..71117c7fe128fe2cb28e715cd79b45c1ba1289b4 100644 (file)
@@ -1123,12 +1123,25 @@ pub fn as_null(&self) -> Option<()> {
     }
 }
 
+// NOTE(stage0): remove impl after a snapshot
+#[cfg(stage0)]
 impl<'a> ops::Index<&'a str, Json>  for Json {
     fn index(&self, idx: & &str) -> &Json {
         self.find(*idx).unwrap()
     }
 }
 
+#[cfg(not(stage0))]  // NOTE(stage0): remove cfg after a snapshot
+impl<'a> ops::Index<&'a str>  for Json {
+    type Output = Json;
+
+    fn index(&self, idx: & &str) -> &Json {
+        self.find(*idx).unwrap()
+    }
+}
+
+// NOTE(stage0): remove impl after a snapshot
+#[cfg(stage0)]
 impl ops::Index<uint, Json> for Json {
     fn index<'a>(&'a self, idx: &uint) -> &'a Json {
         match self {
@@ -1138,6 +1151,18 @@ fn index<'a>(&'a self, idx: &uint) -> &'a Json {
     }
 }
 
+#[cfg(not(stage0))]  // NOTE(stage0): remove cfg after a snapshot
+impl ops::Index<uint> for Json {
+    type Output = Json;
+
+    fn index<'a>(&'a self, idx: &uint) -> &'a Json {
+        match self {
+            &Json::Array(ref v) => v.index(idx),
+            _ => panic!("can only index Json with uint if it is an array")
+        }
+    }
+}
+
 /// The output of the streaming parser.
 #[deriving(PartialEq, Clone, Show)]
 pub enum JsonEvent {