Skip to content

Commit 06a737a

Browse files
committed
Refactor Ord impl
1 parent bbd1d32 commit 06a737a

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

src/c_string.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -319,18 +319,6 @@ impl<const N: usize, T: AsRef<CStr>> PartialOrd<T> for CString<N> {
319319
}
320320
}
321321

322-
impl<const N: usize> PartialOrd<CString<N>> for CStr {
323-
fn partial_cmp(&self, rhs: &CString<N>) -> Option<Ordering> {
324-
self.as_ref().partial_cmp(rhs.as_c_str())
325-
}
326-
}
327-
328-
impl<const N: usize> PartialOrd<CString<N>> for &CStr {
329-
fn partial_cmp(&self, rhs: &CString<N>) -> Option<Ordering> {
330-
self.as_ref().partial_cmp(rhs.as_c_str())
331-
}
332-
}
333-
334322
impl<const N: usize> Ord for CString<N> {
335323
fn cmp(&self, rhs: &Self) -> Ordering {
336324
self.as_c_str().cmp(rhs.as_c_str())
@@ -569,6 +557,16 @@ mod tests {
569557
.partial_cmp(&c"a"),
570558
Some(Ordering::Greater)
571559
);
560+
561+
assert_eq!(c"".partial_cmp(&CString::<1>::new()), Some(Ordering::Equal));
562+
assert_eq!(
563+
c"a".partial_cmp(&CString::<2>::from_bytes_with_nul(b"b\0").unwrap()),
564+
Some(Ordering::Less)
565+
);
566+
assert_eq!(
567+
c"b".partial_cmp(&CString::<2>::from_bytes_with_nul(b"a\0").unwrap()),
568+
Some(Ordering::Greater)
569+
);
572570
}
573571
}
574572
}

0 commit comments

Comments
 (0)