@@ -298,6 +298,30 @@ impl<const N: usize, const M: usize> PartialEq<CString<M>> for CString<N> {
298
298
}
299
299
}
300
300
301
+ impl < const N : usize > PartialEq < CStr > for CString < N > {
302
+ fn eq ( & self , rhs : & CStr ) -> bool {
303
+ self . as_c_str ( ) == rhs
304
+ }
305
+ }
306
+
307
+ impl < const N : usize > PartialEq < & CStr > for CString < N > {
308
+ fn eq ( & self , rhs : & & CStr ) -> bool {
309
+ self . as_c_str ( ) == * rhs
310
+ }
311
+ }
312
+
313
+ impl < const N : usize > PartialEq < CString < N > > for CStr {
314
+ fn eq ( & self , rhs : & CString < N > ) -> bool {
315
+ self == rhs. as_c_str ( )
316
+ }
317
+ }
318
+
319
+ impl < const N : usize > PartialEq < CString < N > > for & CStr {
320
+ fn eq ( & self , rhs : & CString < N > ) -> bool {
321
+ * self == rhs. as_c_str ( )
322
+ }
323
+ }
324
+
301
325
impl < const N : usize > Eq for CString < N > { }
302
326
303
327
/// An error to extend [`CString`] with bytes.
@@ -474,4 +498,19 @@ mod tests {
474
498
!= CString :: <4 >:: from_bytes_with_nul( b"abc\0 " ) . unwrap( )
475
499
) ;
476
500
}
501
+
502
+ #[ test]
503
+ fn equal_with_c_str ( ) {
504
+ // Empty strings
505
+ assert ! ( CString :: <1 >:: new( ) == c"" ) ;
506
+ assert ! ( c"" == CString :: <1 >:: new( ) ) ;
507
+
508
+ // Single character
509
+ assert ! ( CString :: <2 >:: from_bytes_with_nul( b"a\0 " ) . unwrap( ) == c"a" ) ;
510
+ assert ! ( c"a" == CString :: <2 >:: from_bytes_with_nul( b"a\0 " ) . unwrap( ) ) ;
511
+
512
+ // Multiple characters
513
+ assert ! ( CString :: <4 >:: from_bytes_with_nul( b"abc\0 " ) . unwrap( ) == c"abc" ) ;
514
+ assert ! ( c"abc" == CString :: <4 >:: from_bytes_with_nul( b"abc\0 " ) . unwrap( ) ) ;
515
+ }
477
516
}
0 commit comments