diff --git a/src/array_string.rs b/src/array_string.rs index 750c1ef9..fb85cce5 100644 --- a/src/array_string.rs +++ b/src/array_string.rs @@ -1,4 +1,5 @@ use std::borrow::Borrow; +use std::cmp; use std::fmt; use std::hash::{Hash, Hasher}; use std::mem; @@ -281,10 +282,45 @@ impl + Copy> Clone for ArrayString { fn clone(&self) -> ArrayString { *self } - fn clone_from(&mut self, rhs: &Self) { // guaranteed to fit due to types matching. self.clear(); self.push_str(rhs).ok(); } } + +impl> PartialOrd for ArrayString { + fn partial_cmp(&self, rhs: &Self) -> Option { + (**self).partial_cmp(&**rhs) + } + fn lt(&self, rhs: &Self) -> bool { **self < **rhs } + fn le(&self, rhs: &Self) -> bool { **self <= **rhs } + fn gt(&self, rhs: &Self) -> bool { **self > **rhs } + fn ge(&self, rhs: &Self) -> bool { **self >= **rhs } +} + +impl> PartialOrd for ArrayString { + fn partial_cmp(&self, rhs: &str) -> Option { + (**self).partial_cmp(rhs) + } + fn lt(&self, rhs: &str) -> bool { &**self < rhs } + fn le(&self, rhs: &str) -> bool { &**self <= rhs } + fn gt(&self, rhs: &str) -> bool { &**self > rhs } + fn ge(&self, rhs: &str) -> bool { &**self >= rhs } +} + +impl> PartialOrd> for str { + fn partial_cmp(&self, rhs: &ArrayString) -> Option { + self.partial_cmp(&**rhs) + } + fn lt(&self, rhs: &ArrayString) -> bool { self < &**rhs } + fn le(&self, rhs: &ArrayString) -> bool { self <= &**rhs } + fn gt(&self, rhs: &ArrayString) -> bool { self > &**rhs } + fn ge(&self, rhs: &ArrayString) -> bool { self >= &**rhs } +} + +impl> Ord for ArrayString { + fn cmp(&self, rhs: &Self) -> cmp::Ordering { + (**self).cmp(&**rhs) + } +}