ACP: Allow comparisons between CString
and CStr
.
#517
Labels
ACP-accepted
API Change Proposal is accepted (seconded with no objections)
api-change-proposal
A proposal to add or alter unstable APIs in the standard libraries
T-libs-api
Proposal
Problem statement
alloc::ffi::CString
is very similar toalloc::string::String
, and the same goes forcore::ffi::CStr
when compared tostr
. But the FFI types do differ a bit with regard to the relationship between the owned and borrowed types.Currently,
str
,String
, andalloc::borrow::Cow<'a, str>
all implementPartialEq
in the following variants:PartialEq<str>
PartialEq<&'b str>
PartialEq<String>
PartialEq<Cow<'b, str>>
CString
andCStr
, on the other hand, only implement the defaultPartialEq<Self>
.Motivating examples or use cases
Comparing a
CString
with aCStr
currently requires converting either of the objects to the other's type:Implementing this proposal would eliminate the need for the
ToOwned::to_owned
orAsRef::as_ref
call, as well as increase the overall parity withString
/str
.Solution sketch
Add the following implementations to the standard library:
The text was updated successfully, but these errors were encountered: