-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement PartialOrd<str> for String, PartialOrd<[T]> for Vec<T> #232
Comments
Have you tried using Borrow in your implementation? |
Requiring
And, that is exactly what I'm trying to prevent when using an "interned string" smart pointer type. The interned string type supports While you may argue about this use case, requiring a direct
In my opinion, while |
We discussed this in the libs-api meeting and are happy with this change. However this should pass a crater run to check if the new impls cause any type inference failures. |
Proposal
Problem statement
Currently,
String
andstr
implementPartialEq
for each other, but do notimplement
PartialOrd
for each other. This is also true ofVec<T>
and[T]
.I want to submit a pull request adding implementations for
PartialOrd
to roundout the trait implementations of these types.
Motivating examples or use cases
When working on a sorted vec implementation, I originally implemented
get()
lookups using
PartialOrd<SearchType>
. In effect, it looked like this:This does not compile, however, due this missing implementation.
I then looked at other standard library types that have Borrow implementations
that I'm aware of:
OsString
/OsStr
andPathBuf
/Path
. Both implementPartialOrd
in addition toPartialEq
.Solution sketch
In
alloc
, add these implementation blocks:This list of proposed implementations was gathered by looking at the
PartialEq
list of
String
/Vec
and adding the missingPartialOrd
implementations. Theimplementations for these blocks should be similar to their
PartialEq
equivalents, but calling
cmp
/partial_cmp
instead ofeq
.Alternatives
Because of foreign trait implementation rules, the main workaround is to either
use a newtype wrapper that implements these traits or introduce new
traits that serve the same purpose as PartialOrd.
Links and related work
This is my first API change proposal. I feel like this is a fairly straightforward change, to the best of my knowledge, due to foreign trait implementation rules preventing these additional implementations from being breaking changes. I personally cannot think of a reason that these shouldn't be added, but I am new to std lib development, so I may not be aware of ways that these implementations could cause issues in the ecosystem.
The text was updated successfully, but these errors were encountered: