Implement Ord and PartialOrd for Utf8CStr familiy

This commit is contained in:
topjohnwu 2025-05-05 11:33:33 -07:00
parent 79c0fafe43
commit 03e034795d

View File

@ -1,7 +1,7 @@
use cxx::{ExternType, type_id};
use libc::c_char;
use std::borrow::Borrow;
use std::cmp::min;
use std::cmp::{Ordering, min};
use std::ffi::{CStr, FromBytesWithNulError, OsStr};
use std::fmt::{Debug, Display, Formatter, Write};
use std::ops::Deref;
@ -467,6 +467,17 @@ macro_rules! impl_cstr_misc {
self.as_bytes_with_nul() == other.as_ref().as_bytes_with_nul()
}
}
impl<$($g)*> Eq for $t {}
impl<$($g)*> PartialOrd for $t {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl<$($g)*> Ord for $t {
fn cmp(&self, other: &Self) -> Ordering {
self.as_str().cmp(other.as_str())
}
}
)*}
}