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

C-CONV: Uses an inadequate std example #112

Closed
TheDan64 opened this Issue Jul 21, 2017 · 1 comment

Comments

Projects
None yet
2 participants
@TheDan64
Copy link

TheDan64 commented Jul 21, 2017

Under the C-CONV section, it states that to_* methods go from borrowed -> owned and is an expensive operation (usually involving a clone)

However, in the "more examples from the std library", it references Path::to_str, which has a signature of fn to_str(&self) -> Option<&str>. This seems like this method should have actually been named as_str according to these guidelines, and is therefore a inadequate example for to_* methods.

Edit: Only thing I can think of is maybe it's costly to validate UTF8 from the inner OsStr?

@dtolnay dtolnay added edit clarification and removed edit labels Sep 18, 2017

@dtolnay

This comment has been minimized.

Copy link
Member

dtolnay commented Oct 29, 2017

Thanks for catching this! The Path::to_str pattern is indeed not covered by the table. I added an explanation in ed624db. It would not be correct to call this as_str because the method has a non-negligible cost at runtime.

@dtolnay dtolnay closed this Oct 29, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.