1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
use crate::{ marker::{EqTransparent, OrdTransparent, PartialEqTransparent, PartialOrdTransparent}, Strong, StrongBuf, Validator }; use std::{borrow::Cow, cmp, cmp::Ordering}; impl<Ctx> PartialEq for Strong<Ctx> where Ctx: Validator + PartialEqTransparent { #[inline] fn eq(&self, other: &Strong<Ctx>) -> bool { self.as_str() == other.as_str() } } impl<Ctx> PartialEq for StrongBuf<Ctx> where Ctx: Validator + PartialEqTransparent { #[inline] fn eq(&self, other: &StrongBuf<Ctx>) -> bool { <Strong<Ctx> as PartialEq>::eq(self, other) } } impl<Ctx> PartialOrd for Strong<Ctx> where Ctx: Validator + PartialEqTransparent + PartialOrdTransparent { #[inline] fn partial_cmp(&self, other: &Strong<Ctx>) -> Option<Ordering> { self.as_str().partial_cmp(other.as_str()) } } impl<Ctx> PartialOrd for StrongBuf<Ctx> where Ctx: Validator + PartialEqTransparent + PartialOrdTransparent { #[inline] fn partial_cmp(&self, other: &StrongBuf<Ctx>) -> Option<Ordering> { <Strong<Ctx> as PartialOrd>::partial_cmp(self, other) } } macro_rules! impl_cmp { ($lhs:ty, $rhs: ty) => { impl<'a, 'b, Ctx> PartialEq<$rhs> for $lhs where Ctx: Validator + PartialEqTransparent { #[inline] fn eq(&self, other: &$rhs) -> bool { <Strong<Ctx> as PartialEq>::eq(self, other) } } impl<'a, 'b, Ctx> PartialEq<$lhs> for $rhs where Ctx: Validator + PartialEqTransparent { #[inline] fn eq(&self, other: &$lhs) -> bool { <Strong<Ctx> as PartialEq>::eq(self, other) } } impl<'a, 'b, Ctx> PartialOrd<$rhs> for $lhs where Ctx: Validator + PartialEqTransparent + PartialOrdTransparent { #[inline] fn partial_cmp(&self, other: &$rhs) -> Option<cmp::Ordering> { <Strong<Ctx> as PartialOrd>::partial_cmp(self, other) } } impl<'a, 'b, Ctx> PartialOrd<$lhs> for $rhs where Ctx: Validator + PartialEqTransparent + PartialOrdTransparent { #[inline] fn partial_cmp(&self, other: &$lhs) -> Option<cmp::Ordering> { <Strong<Ctx> as PartialOrd>::partial_cmp(self, other) } } }; } impl_cmp!(StrongBuf<Ctx>, Strong<Ctx>); impl_cmp!(StrongBuf<Ctx>, &'a Strong<Ctx>); impl_cmp!(Cow<'a, Strong<Ctx>>, Strong<Ctx>); impl_cmp!(Cow<'a, Strong<Ctx>>, &'b Strong<Ctx>); impl_cmp!(Cow<'a, Strong<Ctx>>, StrongBuf<Ctx>); impl<Ctx> Eq for Strong<Ctx> where Ctx: Validator + PartialEqTransparent + EqTransparent {} impl<Ctx> Ord for Strong<Ctx> where Ctx: Validator + PartialEqTransparent + EqTransparent + PartialOrdTransparent + OrdTransparent { #[inline] fn cmp(&self, other: &Strong<Ctx>) -> Ordering { self.as_str().cmp(other.as_str()) } } impl<Ctx> Eq for StrongBuf<Ctx> where Ctx: Validator + PartialEqTransparent + EqTransparent {} impl<Ctx> Ord for StrongBuf<Ctx> where Ctx: Validator + PartialEqTransparent + EqTransparent + PartialOrdTransparent + OrdTransparent { #[inline] fn cmp(&self, other: &StrongBuf<Ctx>) -> Ordering { self.as_str().cmp(other.as_str()) } }