-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsArea: Documentation for any part of the project, including the compiler, standard library, and tools
Description
Previous discussion:
#14131
#17438
Still a minor thing, so probably not worth an RFC.
as_bytes()
is a fine name, but the function is not easy to discover. I have video evidence of Rust beginners who know and use from_utf8()
, but can't find the inverse, which is as_bytes()
. The documentation provides no links between the two.
Possible mitigations (could even apply multiple of these):
- Offer
.as_utf8()
or.to_utf8()
, and.into_utf8()
and mention in the documentation that it's simply an alias. - Put "UTF-8" or "utf8" in the documentation of
.as_bytes()
and friends, so it can at least be found through search engines. Currently, queries for "rust string to utf8" or "rust utf8 bytes from string" only take you to thefrom_utf8()
function, which works the wrong way round. - Reference
.as_bytes()
and.from_utf8()
from each other and mention that they are (roughly) inverses (modulo error handling, modulo ownership stuff).
Currently, http://stackoverflow.com/questions/27195506/convert-an-ascii-string-literal-to-u8-in-rust#comment42877192_27195762 might be the hint that helps most people discover as_bytes()
.
redaready, Ixrec, jplatte, samuelhnrq, MarcelGarus and 1 more
Metadata
Metadata
Assignees
Labels
A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsArea: Documentation for any part of the project, including the compiler, standard library, and tools