diff options
| author | Steven Fackler <sfackler@gmail.com> | 2014-06-17 23:25:51 -0700 |
|---|---|---|
| committer | Steven Fackler <sfackler@gmail.com> | 2014-06-29 21:42:09 -0700 |
| commit | 55cae0a094bbdcd0e9d5e697ce4f38cbd783bbc7 (patch) | |
| tree | 3385d84daae977e0d2bf08decdaf807e1d03337d /src/libserialize | |
| parent | bb5695b95c288c442dbe528f7e1c1b08f79f033d (diff) | |
| download | rust-55cae0a094bbdcd0e9d5e697ce4f38cbd783bbc7.tar.gz rust-55cae0a094bbdcd0e9d5e697ce4f38cbd783bbc7.zip | |
Implement RFC#28: Add PartialOrd::partial_cmp
I ended up altering the semantics of Json's PartialOrd implementation. It used to be the case that Null < Null, but I can't think of any reason for an ordering other than the default one so I just switched it over to using the derived implementation. This also fixes broken `PartialOrd` implementations for `Vec` and `TreeMap`. RFC: 0028-partial-cmp
Diffstat (limited to 'src/libserialize')
| -rw-r--r-- | src/libserialize/json.rs | 58 |
1 files changed, 1 insertions, 57 deletions
diff --git a/src/libserialize/json.rs b/src/libserialize/json.rs index d8dd2938b34..9f5f020152f 100644 --- a/src/libserialize/json.rs +++ b/src/libserialize/json.rs @@ -244,7 +244,7 @@ use std::vec::Vec; use Encodable; /// Represents a json value -#[deriving(Clone, PartialEq)] +#[deriving(Clone, PartialEq, PartialOrd)] pub enum Json { Number(f64), String(String), @@ -2087,62 +2087,6 @@ impl ::Decoder<DecoderError> for Decoder { } } -/// Test if two json values are less than one another -impl PartialOrd for Json { - fn lt(&self, other: &Json) -> bool { - match *self { - Number(f0) => { - match *other { - Number(f1) => f0 < f1, - String(_) | Boolean(_) | List(_) | Object(_) | - Null => true - } - } - - String(ref s0) => { - match *other { - Number(_) => false, - String(ref s1) => s0 < s1, - Boolean(_) | List(_) | Object(_) | Null => true - } - } - - Boolean(b0) => { - match *other { - Number(_) | String(_) => false, - Boolean(b1) => b0 < b1, - List(_) | Object(_) | Null => true - } - } - - List(ref l0) => { - match *other { - Number(_) | String(_) | Boolean(_) => false, - List(ref l1) => (*l0) < (*l1), - Object(_) | Null => true - } - } - - Object(ref d0) => { - match *other { - Number(_) | String(_) | Boolean(_) | List(_) => false, - Object(ref d1) => d0 < d1, - Null => true - } - } - - Null => { - match *other { - Number(_) | String(_) | Boolean(_) | List(_) | - Object(_) => - false, - Null => true - } - } - } - } -} - /// A trait for converting values to JSON pub trait ToJson { /// Converts the value of `self` to an instance of JSON |
