| 92 | |
| 93 | impl PartialOrd for ScalarUDF { |
| 94 | fn partial_cmp(&self, other: &Self) -> Option<Ordering> { |
| 95 | let mut cmp = self.name().cmp(other.name()); |
| 96 | if cmp == Ordering::Equal { |
| 97 | cmp = self.signature().partial_cmp(other.signature())?; |
| 98 | } |
| 99 | if cmp == Ordering::Equal { |
| 100 | cmp = self.aliases().partial_cmp(other.aliases())?; |
| 101 | } |
| 102 | // Contract for PartialOrd and PartialEq consistency requires that |
| 103 | // a == b if and only if partial_cmp(a, b) == Some(Equal). |
| 104 | if cmp == Ordering::Equal && self != other { |
| 105 | // Functions may have other properties besides name and signature |
| 106 | // that differentiate two instances (e.g. type, or arbitrary parameters). |
| 107 | // We cannot return Some(Equal) in such case. |
| 108 | return None; |
| 109 | } |
| 110 | debug_assert!( |
| 111 | cmp == Ordering::Equal || self != other, |
| 112 | "Detected incorrect implementation of PartialEq when comparing functions: '{}' and '{}'. \ |
| 113 | The functions compare as equal, but they are not equal based on general properties that \ |
| 114 | the PartialOrd implementation observes,", |
| 115 | self.name(), |
| 116 | other.name() |
| 117 | ); |
| 118 | Some(cmp) |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | impl Eq for ScalarUDF {} |