-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Pick over the standard libraries for types that don't (but can) implement common traits #15294
Comments
cc me |
Also things like |
I’m imagining a tool which produces a massive table where each column is a trait and each row is a struct or enum, with each cell shaded appropriately for whether there is an implementation (under any constraints) of the trait for the type. |
Allows use cases like this one: ``` rust use std::io::Command; fn main() { let mut cmd = Command::new("ls"); cmd.arg("-l"); for &dir in ["a", "b", "c"].iter() { println!("{}", cmd.clone().arg(dir)); } } ``` Output: ``` ls '-l' 'a' ls '-l' 'b' ls '-l' 'c' ``` Without the `clone()`, you'll end up with: ``` ls '-l' 'a' ls '-l' 'a' 'b' ls '-l' 'a' 'b' 'c' ``` cc #15294
Implements PartialEq/Eq/Clone/Hash/FromIterator/Extendable for SmallIntMap and Clone/Show for TrieMap/TrieSet. cc #15294
For items in
|
…hton This implements: - Eq and Ord for DList, RingBuf, TreeMap and TreeSet - FromIterator and Extendable for BitvSet cc #15294
I'm not entirely sold on the usefulness of a semi-polished, but slightly manual, and still non-lossy middle ground between full-on serialization and debugging. Do we know of what examples we have today would fall in this category? I believe there are also some competing concerns with
I personally would tend to err on the side of saying "to_string is lossy" and "Show should be implementing on all primitives", but I also can't shake the feeling that there's likely a better middle ground. |
I don’t understand how serialization is applicable here. How can I use |
I would imagine that if you know that your type can be perfectly encoded as a string then you invoke |
It would also be useful to have a "debugging" serialization (e.g. used in |
We have BTreeMap and BTreeSet impling all the common things. So I think this issue in now just "do #17534". Can be closed? |
What about |
What's it missing? Ord/PartialOrd? |
Ok. EnumSet is Ord+PartialOrd now. Anything else? |
I think this is all and this can be closed. |
Almost no iterators ( |
Iterators like |
It would be completely unsound for Can you provide some concrete usecases? |
It's not possible to provide |
@thestinger I was only suggesting adding |
No, double-ended doesn't imply the ability to move the iterator in the reverse direction. A vector iterator has a pointer to either end of the remaining range and would need 4 pointers if it could be expanded again via |
Move-iterators are safe to clone, e.g. (I'm sure it would be difficult to write clone implementations for some move-iterators, but the common ones probably aren't so bad.) |
@thestinger Ah, I mistakenly assumed the Vec iterator had a reference to the source slice. |
Note: I've created a discuss topic to address the questions around |
closes rust-lang#12677 (cc @Valloric) cc rust-lang#15294 r? @aturon / @alexcrichton (Because of rust-lang#19358 I had to move the struct bounds from the `where` clause into the parameter list)
closes rust-lang#21402 cc rust-lang#15294 r? @alexcrichton or @aturon cc @ExpHP (btw, this only covers arrays with arity up to 32)
Given that this issue is vague, and it seems like all of the specific things mentioned here have been done, I'm giving this a close. If anyone knows of any other things that are missing, let's add them, but I don't find this ticket to be super actionable right now. |
... and implement/derive them.
Traits like
Eq
,Hash
,Ord
,Clone
are sometimes forgotten (or have been missed, in the various library changes that have happened), and this is annoying for downstream users. To paper over the deeper issue (how to make adding these impls more natural/harder to forget), impls for all the various traits can be added to types.List of types missing things just from a basic scan:
collections
(only implement thePartial
comparison traits, and pretty much none of them implementHash
)semver::Version
num
are missingHash
url::Path
,url::UserInfo
uuid::UuidVariant
,uuid::UuidVersion
The text was updated successfully, but these errors were encountered: