FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

str::to_string -> str::to_owned by youknowone · Pull Request #1734 · RustPython/RustPython · GitHub

Repository navigation

str::to_string -> str::to_owned - #1734

Merged
youknowone merged 2 commits into
RustPython:masterfrom
youknowone:to-owned
Feb 5, 2020
Merged

youknowone merged 2 commits into
RustPython:masterfrom
youknowone:to-owned

Conversation

Copy link
Copy Markdown
Member

please reject this PR if it is out of our preference or rust community convention.

coolreader18 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I prefer this version, I'm not sure what others' thoughts are though.

Copy link
Copy Markdown
Contributor

@youknowone could you explain a bit what your motivation is for this specific change? Reading this blog post, it looks like there is no difference in the two methods.

Copy link
Copy Markdown
Member Author

There is a reddit link in the post you linked and I think this is my reason: https://www.reddit.com/r/rust/comments/4l71qw/how_do_i_convert_a_str_to_string_the_beginning_in/d3l23vf/

Derived pros: For most of this call, we just want to create String from &str. But, because .to_string() is defined to Display trait, we accidently can put a ToString object instead of &str object - which is not mostly intended. For to_owned(), if any object not a &str called with this method, it mostly will not return String. Which means no mistake.

Probably .into() and String::from() can be a better choice for this reason. I think every other option except for to_string() is better then that.

This is a kind of human engineering. Here is another PR I made with similar motivation. #1654

Copy link
Copy Markdown
Contributor

@youknowone thank you for your detailed explanation!

youknowone merged commit 78180ff into RustPython:master Feb 5, 2020
youknowone deleted the to-owned branch February 5, 2020 14:27
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

3 participants


Back | FazBrowse Home | New Git URL