diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2015-03-21 19:33:27 -0400 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2015-03-23 16:55:43 -0400 |
| commit | b4d4daf007753dfb04d87b1ffe1c2ad2d8811d5a (patch) | |
| tree | c35d3d74c271c4ec72678d9d866bcad331a9e706 /src/libserialize | |
| parent | bc1dde468c1613743c919cb9f33923cc9916c5b4 (diff) | |
| download | rust-b4d4daf007753dfb04d87b1ffe1c2ad2d8811d5a.tar.gz rust-b4d4daf007753dfb04d87b1ffe1c2ad2d8811d5a.zip | |
Adjust Index/IndexMut impls. For generic collections, we take
references. For collections whose keys are integers, we take both references and by-value.
Diffstat (limited to 'src/libserialize')
| -rw-r--r-- | src/libserialize/json.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/libserialize/json.rs b/src/libserialize/json.rs index 096c72e6af2..abbfc82319f 100644 --- a/src/libserialize/json.rs +++ b/src/libserialize/json.rs @@ -1218,6 +1218,7 @@ impl Json { } } +#[cfg(stage0)] impl<'a> Index<&'a str> for Json { type Output = Json; @@ -1226,6 +1227,16 @@ impl<'a> Index<&'a str> for Json { } } +#[cfg(not(stage0))] +impl<'a> Index<&'a str> for Json { + type Output = Json; + + fn index(&self, idx: &'a str) -> &Json { + self.find(idx).unwrap() + } +} + +#[cfg(stage0)] impl Index<uint> for Json { type Output = Json; @@ -1237,6 +1248,18 @@ impl Index<uint> for Json { } } +#[cfg(not(stage0))] +impl Index<uint> for Json { + type Output = Json; + + fn index<'a>(&'a self, idx: uint) -> &'a Json { + match self { + &Json::Array(ref v) => &v[idx], + _ => panic!("can only index Json with uint if it is an array") + } + } +} + /// The output of the streaming parser. #[derive(PartialEq, Clone, Debug)] pub enum JsonEvent { |
