From 55cae0a094bbdcd0e9d5e697ce4f38cbd783bbc7 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Tue, 17 Jun 2014 23:25:51 -0700 Subject: 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 --- src/libserialize/json.rs | 58 +----------------------------------------------- 1 file changed, 1 insertion(+), 57 deletions(-) (limited to 'src/libserialize') 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 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 -- cgit 1.4.1-3-g733a5