-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
[stdlib] [NFC] Fix as_bytes()
documentation
#3864
base: nightly
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -530,28 +530,28 @@ struct StringLiteral( | |
|
||
@always_inline | ||
fn as_bytes(self) -> Span[Byte, StaticConstantOrigin]: | ||
""" | ||
Returns a contiguous Span of the bytes owned by this string. | ||
"""Returns a contiguous slice of bytes. | ||
|
||
Returns: | ||
A contiguous slice pointing to the bytes owned by this string. | ||
""" | ||
A contiguous slice pointing to bytes. | ||
|
||
Notes: | ||
This does not include the trailing null terminator. | ||
""" | ||
return Span[Byte, StaticConstantOrigin]( | ||
ptr=self.unsafe_ptr(), length=self.byte_length() | ||
) | ||
|
||
@always_inline | ||
fn as_bytes(ref self) -> Span[Byte, __origin_of(self)]: | ||
"""Returns a contiguous slice of the bytes owned by this string. | ||
"""Returns a contiguous slice of bytes. | ||
|
||
Returns: | ||
A contiguous slice pointing to the bytes owned by this string. | ||
A contiguous slice pointing to bytes. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems grammatically/contextually confusing. If There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bytes is the plural of a byte (?), and a contiguous slice of bytes is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nvm, I think it will be more restraining on the API (AsBytes trait) to say explicitly UTF-8, these bytes could encode anything. Bytes is a type in Python, so this makes sense to me. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I could change just the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My point was more:
What bytes? Who owns them? What do they contain? While this may seem obvious, your change removes that context. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
UTF-8 bytes
The origin that the Span carries My main goal is to eventually abstract this API over all Stringlike types, owning and non-owning, once the compiler Origin issues are resolved (see PR #3677 files, it won't necessarily look like that but along those lines to be able to receive a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm still not seeing how this is more descriptive as a documentation line. It seems less descriptive to me. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also I'd hold off a little on string unification work until the team has time to discuss your proposal. We should definitely improve the general API surface, but we need to think as a team how we want to handle it. For example, implicit conversion into There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because I'm trying to make the documentation consistent across all |
||
|
||
Notes: | ||
This does not include the trailing null terminator. | ||
""" | ||
# Does NOT include the NUL terminator. | ||
return Span[Byte, __origin_of(self)]( | ||
ptr=self.unsafe_ptr(), length=self.byte_length() | ||
) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I see how this is better. The bytes are owned by the literal.
doesn't really describe what the bytes contain at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's to keep the documentation consistent across owning and non-owning types.
"utf-8 bytes" sounds less confusing 4u?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My point was that "owned by this string" was descriptive about ownership and this PR would make it more ambiguous.