Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upAdd some additional utility methods to OsString and OsStr #1307
Conversation
This comment has been minimized.
This comment has been minimized.
wthrowe
commented
Oct 5, 2015
|
I've actually been thinking about OsStr(ing) interfaces recently and was thinking about writing something up, but hadn't gotten around to it yet. In terms of this proposal, It isn't clear to me what the length and capacity related methods would do, though. The internal representation of OsString on Windows is not very meaningful and most of the details of it are intentionally not exposed by the interface. Would these methods give values related to the internal WTF-8 representation (which should be useless, because all consequences of that encoding should be hidden), or of the system ill-formed UTF-16 representation (which would require some kind of conversion)? |
This comment has been minimized.
This comment has been minimized.
Granted, they don't really have any semantic meaning, but they still have uses. Actually, come to think of it I forgot to add |
This comment has been minimized.
This comment has been minimized.
wthrowe
commented
Oct 5, 2015
|
Good points. I can see why we'd want those, now. So I think I now like everything here except |
This comment has been minimized.
This comment has been minimized.
|
We usually add specific conversion methods for conversions that are expected to be done commonly (e.g. str → String). I don’t see people using OsString oftenly, let alone its conversion methods. I’d vote for leaving
|
alexcrichton
added
the
T-libs
label
Oct 5, 2015
eefriedman
force-pushed the
eefriedman:osstring-simple
branch
from
ba84aa9
to
736bfce
Oct 5, 2015
This comment has been minimized.
This comment has been minimized.
|
Updated: removed |
This comment has been minimized.
This comment has been minimized.
|
Looks good. I had a look through and there weren't any other methods on However, it may be worthwhile (although out of scope for this RFC) defining an Substring operations can then be defined in terms of iterators over |
This comment has been minimized.
This comment has been minimized.
|
For I feel like these methods won't be used that often, but if you need to use I think this looks good to me. |
BurntSushi
self-assigned this
Oct 7, 2015
This comment has been minimized.
This comment has been minimized.
wthrowe
commented
Oct 7, 2015
|
There's also the stable |
This comment has been minimized.
This comment has been minimized.
|
I feel that these methods are quite conventional among collections, so the only particular question in my mind would be whether we want them at all. I originally thought that they're not useful because the length of an OS string doesn't actually mean anything in terms of decoding it, but it does mean something in terms of performance (a key insight here), which I feel is justification enough for their inclusion. |
alexcrichton
added
the
final-comment-period
label
Oct 15, 2015
This comment has been minimized.
This comment has been minimized.
|
I feel a bit iffy with the naming choice of |
This comment has been minimized.
This comment has been minimized.
|
@sfackler Isn't that the case for |
This comment has been minimized.
This comment has been minimized.
|
Well, |
This comment has been minimized.
This comment has been minimized.
|
@sfackler Working with strings with Windows API is already a minefield. If someone doesn't understand what |
This comment has been minimized.
This comment has been minimized.
arthurprs
commented
Oct 27, 2015
|
I believe len should stick to the existing semantics (string, vec, all collections) and return the number of underlying items, in this case the utf16ish words. |
This comment has been minimized.
This comment has been minimized.
|
@arthurprs |
This comment has been minimized.
This comment has been minimized.
That would require iterating the OsString to calculate, when the Returning a byte count is portable, consistent and has practical usefulness for when building OsStrings. Without it, there's no direct relation between I don't think this breaks the encapsulation of the WTF8 encoding because len() is a lower level operation: it's the same reason that having |
This comment has been minimized.
This comment has been minimized.
arthurprs
commented
Oct 27, 2015
|
Yeah, I believe you guys are right since the underlying data is actually wtf8. |
alexcrichton
referenced this pull request
Oct 29, 2015
Closed
Add Capacity/length methods for OsString #29453
This comment has been minimized.
This comment has been minimized.
|
The libs team discussed this during triage yesterday and the decision was to merge, thanks again for the RFC @eefriedman! Tracking issue: rust-lang/rust#29453 |
eefriedman commentedOct 4, 2015
Rendered