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

Implement a to_string method for Encoding enum #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

zhengAnBin
Copy link

I'm not sure if we can use this way, if we can, we can delete the parse.rs file,but using an unstable feature(fmt_internals), maybe we can wait until it is stable before merging the code

image

Copy link

@madsmtm madsmtm left a comment

Choose a reason for hiding this comment

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

You just have to bring the ToString trait into scope, then the method is already implemented - so no need for unstable functionality.

But the reason that Encoding's use a function to compare encodings instead of comparing strings is twofold:

  1. For performance, since it avoids an allocation (an possible re-allocations) inherent in creating the encoding string.
  2. Just because two encodings don't have the same encoding doesn't mean they shouldn't "compare equal" (which you would see if you had kept the tests in parse.rs, e.g. "Vv" == Encoding::Void should pass).
  • At least in the one place which this is really used, which is in objc, it is crucial that qualifiers are ignored, since otherwise the "verify_message" feature would basically be useless.

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.

2 participants