Skip to content

std: Rename the ToStr trait to ToString, and to_str to to_string #15493

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 1 commit into from
Jul 8, 2014

Conversation

brson
Copy link
Contributor

@brson brson commented Jul 7, 2014

This updates #15075.

Rename ToStr::to_str to ToString::to_string. The naive renaming ends up with two to_string functions defined on strings in the prelude (the other defined via collections::str::StrAllocating). To remedy this I removed StrAllocating::to_string, making all conversions from &str to String go through Show. This has a measurable impact on the speed of this conversion, but the sense I get from others is that it's best to go ahead and unify to_string and address performance for all to_string conversions in core::fmt. String::from_str(...) still works as a manual fast-path.

Note that the patch was done with a script, and ended up renaming a number of other *_to_str functions, particularly inside of rustc. All the ones I saw looked correct, and I didn't notice any additional API breakage.

Closes #15046.

@brson
Copy link
Contributor Author

brson commented Jul 7, 2014

I haven't actually seen this pass make check yet, but I've been rebasing it for days.

@brson brson mentioned this pull request Jul 7, 2014
@richo
Copy link
Contributor

richo commented Jul 7, 2014

Amazing, thanks for picking up my slack :)

bors added a commit that referenced this pull request Jul 8, 2014
This updates #15075.

Rename `ToStr::to_str` to `ToString::to_string`. The naive renaming ends up with two `to_string` functions defined on strings in the prelude (the other defined via `collections::str::StrAllocating`). To remedy this I removed `StrAllocating::to_string`, making all conversions from `&str` to `String` go through `Show`. This has a measurable impact on the speed of this conversion, but the sense I get from others is that it's best to go ahead and unify `to_string` and address performance for all `to_string` conversions in `core::fmt`. `String::from_str(...)` still works as a manual fast-path.

Note that the patch was done with a script, and ended up renaming a number of other `*_to_str` functions, particularly inside of rustc. All the ones I saw looked correct, and I didn't notice any additional API breakage.

Closes #15046.
@bors bors closed this Jul 8, 2014
@bors bors merged commit 12c334a into rust-lang:master Jul 8, 2014
@richo
Copy link
Contributor

richo commented Jul 9, 2014

\o/ Thanks so much for landing this.

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.

Rename ToStr/to_str to ToString/to_string
3 participants