diff --git a/stdlib/src/builtin/string_literal.mojo b/stdlib/src/builtin/string_literal.mojo index 727ac65555..8b15397381 100644 --- a/stdlib/src/builtin/string_literal.mojo +++ b/stdlib/src/builtin/string_literal.mojo @@ -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. 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() ) diff --git a/stdlib/src/collections/string.mojo b/stdlib/src/collections/string.mojo index 7e09a482ff..39c0521bf3 100644 --- a/stdlib/src/collections/string.mojo +++ b/stdlib/src/collections/string.mojo @@ -1620,18 +1620,16 @@ struct String( @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. Notes: This does not include the trailing null terminator. """ - - # Does NOT include the NUL terminator. return Span[Byte, __origin_of(self)]( - ptr=self._buffer.unsafe_ptr(), length=self.byte_length() + ptr=self.unsafe_ptr(), length=self.byte_length() ) @always_inline diff --git a/stdlib/src/memory/span.mojo b/stdlib/src/memory/span.mojo index 03f860f899..178902408c 100644 --- a/stdlib/src/memory/span.mojo +++ b/stdlib/src/memory/span.mojo @@ -26,16 +26,14 @@ from memory import Pointer, UnsafePointer trait AsBytes: - """ - The `AsBytes` trait denotes a type that can be returned as a immutable byte - span. + """The `AsBytes` trait denotes a type that can be returned as a byte span. """ 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. Notes: This does not include the trailing null terminator. diff --git a/stdlib/src/utils/string_slice.mojo b/stdlib/src/utils/string_slice.mojo index 09372e41e1..f7ec32f508 100644 --- a/stdlib/src/utils/string_slice.mojo +++ b/stdlib/src/utils/string_slice.mojo @@ -755,10 +755,13 @@ struct StringSlice[is_mutable: Bool, //, origin: Origin[is_mutable]]( @always_inline fn as_bytes(self) -> Span[Byte, origin]: - """Get the sequence of encoded bytes of the underlying string. + """Returns a contiguous slice of bytes. Returns: - A slice containing the underlying sequence of encoded bytes. + A contiguous slice pointing to bytes. + + Notes: + This does not include the trailing null terminator. """ return self._slice