From 03e034795d3f19e082c0bacb3ad8e8661f298319 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Mon, 5 May 2025 11:33:33 -0700 Subject: [PATCH] Implement Ord and PartialOrd for Utf8CStr familiy --- native/src/base/cstr.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/native/src/base/cstr.rs b/native/src/base/cstr.rs index e35e44256..5f3a78c01 100644 --- a/native/src/base/cstr.rs +++ b/native/src/base/cstr.rs @@ -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 { + Some(self.cmp(other)) + } + } + impl<$($g)*> Ord for $t { + fn cmp(&self, other: &Self) -> Ordering { + self.as_str().cmp(other.as_str()) + } + } )*} }