Skip to content

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

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

Merged
merged 2 commits into from
Feb 5, 2020
Merged

Conversation

youknowone
Copy link
Member

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

Copy link
Member

@coolreader18 coolreader18 left a comment

Choose a reason for hiding this comment

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

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

@windelbouwman
Copy link
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.

@youknowone
Copy link
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

@windelbouwman
Copy link
Contributor

@youknowone thank you for your detailed explanation!

@youknowone youknowone merged commit 78180ff into RustPython:master Feb 5, 2020
@youknowone youknowone deleted the to-owned branch February 5, 2020 14:27
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