diff --git a/edn/src/types.rs b/edn/src/types.rs index cfcfafd3..1c845b60 100644 --- a/edn/src/types.rs +++ b/edn/src/types.rs @@ -224,7 +224,7 @@ macro_rules! to_keyword { /// Implements multiple is*, as*, into* and from* methods common to /// both Value and SpannedValue. macro_rules! def_common_value_methods { - ( $t:tt, $tchild:tt ) => { + ( $t:tt<$tchild:tt> ) => { def_is!(is_nil, $t::Nil); def_is!(is_boolean, $t::Boolean(_)); def_is!(is_integer, $t::Integer(_)); @@ -394,13 +394,34 @@ macro_rules! def_common_value_display { } } -impl Value { - def_common_value_methods!(Value, Value); +macro_rules! def_common_value_impl { + ( $t:tt<$tchild:tt> ) => { + impl $t { + def_common_value_methods!($t<$tchild>); + } + + impl PartialOrd for $t { + fn partial_cmp(&self, other: &$t) -> Option { + Some(self.cmp(other)) + } + } + + impl Ord for $t { + fn cmp(&self, other: &$t) -> Ordering { + def_common_value_ord!($t, self, other) + } + } + + impl Display for $t { + fn fmt(&self, f: &mut Formatter) -> ::std::fmt::Result { + def_common_value_display!($t, self, f) + } + } + } } -impl SpannedValue { - def_common_value_methods!(SpannedValue, ValueAndSpan); -} +def_common_value_impl!(Value); +def_common_value_impl!(SpannedValue); impl ValueAndSpan { pub fn without_spans(self) -> Value { @@ -408,54 +429,18 @@ impl ValueAndSpan { } } -impl PartialOrd for Value { - fn partial_cmp(&self, other: &Value) -> Option { - Some(self.cmp(other)) - } -} - -impl PartialOrd for SpannedValue { - fn partial_cmp(&self, other: &SpannedValue) -> Option { - Some(self.cmp(other)) - } -} - impl PartialOrd for ValueAndSpan { fn partial_cmp(&self, other: &ValueAndSpan) -> Option { Some(self.cmp(other)) } } -impl Ord for Value { - fn cmp(&self, other: &Value) -> Ordering { - def_common_value_ord!(Value, self, other) - } -} - -impl Ord for SpannedValue { - fn cmp(&self, other: &SpannedValue) -> Ordering { - def_common_value_ord!(SpannedValue, self, other) - } -} - impl Ord for ValueAndSpan { fn cmp(&self, other: &ValueAndSpan) -> Ordering { self.inner.cmp(&other.inner) } } -impl Display for Value { - fn fmt(&self, f: &mut Formatter) -> ::std::fmt::Result { - def_common_value_display!(Value, self, f) - } -} - -impl Display for SpannedValue { - fn fmt(&self, f: &mut Formatter) -> ::std::fmt::Result { - def_common_value_display!(SpannedValue, self, f) - } -} - impl Display for ValueAndSpan { fn fmt(&self, f: &mut Formatter) -> ::std::fmt::Result { self.inner.fmt(f)