Skip to content
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

Make types eagerly implement common traits #53

Merged
merged 1 commit into from
Oct 31, 2017
Merged

Make types eagerly implement common traits #53

merged 1 commit into from
Oct 31, 2017

Conversation

@@ -1,6 +1,7 @@
use std::io::{Error, ErrorKind, Read, Result, Write};
use std::cmp::min;

#[derive(Copy, Clone, Debug, Eq, Ord, PartialEq, PartialOrd, Hash)]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MockStream is not exposed outside the crate, and there's no reason for it to derive these traits.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, MockStream cannot implement Copy, since it contains Vecs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed the wrong Copy derivation. I tested locally but apparently something went wrong, sorry!

Copy link
Contributor Author

@sanmai-NL sanmai-NL Oct 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get your point but, these traits should be implemented eagerly, the point of the recommendation is to avoid needless discussion and abitrary decisions on what traits are and aren't ‘useful’. If I want to debug tests I could well have a use for many of these traits.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I read the recommendation as being about the crate's API (and hence, about the types that are public). The reason I am hesitant about eagerly adding these derives to internal types is that it unnecessarily limits what we can put inside them for very little gain. For externally exposed types, I totally see the advantage of eagerly implementing these traits, since the overhead for users for adding impls is very high. However, for internal types, it's trivial to add derives on-demand.

@@ -16,6 +16,7 @@ const CR: u8 = 0x0d;
const LF: u8 = 0x0a;

/// Stream to interface with the IMAP server. This interface is only for the command stream.
#[derive(Debug)]
Copy link
Collaborator

@jonhoo jonhoo Oct 19, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems fine, though I'm unsure why having the client implement Debug is useful?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One other advantage of implementing traits eagerly, i.e. if there is no deliberate reason or cause not to, is that a compile time error will occur if the type is extended to include elements/fields that do not implement that common trait. Then the breaking change is pointed out and it can be reconsidered.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems fine.

@@ -1,6 +1,6 @@
use std::fmt;

#[derive(Eq, PartialEq)]
#[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd, Hash)]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's meaningful to implement Ord or PartialOrd for Mailbox.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See previous comments.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree in general (again, since this is an externally expose type). However, I don't think we want to commit to Mailbox being Ord. That seems like a strong, but ultimately not particularly useful guarantee. And eagerly adopting it would mean that we are committing to continuing to support Mailbox: Ord unless we bump the major version number.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No you wouldn't commit to anything yet, see SemVer.

Copy link
Contributor Author

@sanmai-NL sanmai-NL Oct 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implementing common traits should be done eagerly and we will be done with it. I see where you're coming from that you have reasons not to implement Ord but those should then be made explicit. Can you give a reasonable example where the type could not be Ord anymore? As I motivated in my earlier comment, adding constraints to types by implementing common traits is not just a potential disadvantage, it's an advantage since you will are forced to modify the type more carefully. The proper strategy IMO:

  1. Before 1.0.0: eagerly implementing traits for all types as the Rust API Guidelines prescribe.
  2. At 1.0.0: making final decisions on what traits to unimplement, based on an explicit motivation and considering the actual downstream effects.

Please, go ahead and make any changes to this branch as you see fit. This PR is holding up potential further contributions I wanted to make.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess I consider this crate stable enough that it should really be 1.0.0, at which point these would be committing. I can absolutely see Mailbox gaining fields that are not Ord, such as pointers back to the Client for further operations on the selected mailbox, which is why I'm hesitant for that to be added. Again though , the other traits seem fine to derive.

I think we'll need @mattnenterprise to look at this.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 62.425% when pulling bc020fa on sanmai-NL:C-COMMON-TRAITS into eb73207 on mattnenterprise:master.

@sanmai-NL
Copy link
Contributor Author

@jonhoo: do you have time to adapt/merge this, is something else blocking a merge?

@jonhoo
Copy link
Collaborator

jonhoo commented Oct 30, 2017

As I mentioned in #53 (comment), I think Ord and PartialOrd should be removed from Mailbox, and arguably also from MockStream. I see your arguments the other way too, but disagree with them. Which is why I'd like @mattnenterprise's input on this. Alternatively, if you remove those derives (which I don't think should matter for any other changes you have pending), I'd be happy to merge.

@jonhoo
Copy link
Collaborator

jonhoo commented Oct 30, 2017

I still disagree with some of the other derives (especially for MockStream), but those I'm less adamant about.

@sanmai-NL
Copy link
Contributor Author

sanmai-NL commented Oct 30, 2017 via email

@jonhoo jonhoo merged commit bc020fa into mattnenterprise:master Oct 31, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants