Skip to main content

struct

StringSlice

A non-owning view to encoded string data.

TODO: The underlying string data is guaranteed to be encoded using UTF-8.

Parameters

  • is_mutable (Bool): Whether the slice is mutable.
  • lifetime (lifetime<#lit.struct.extract<:_stdlib::_builtin::_bool::_Bool is_mutable, "value">>): The lifetime of the underlying string data.

Implemented traits

AnyType, Stringable

Methods

__init__

__init__(inout self: Self, *, owned unsafe_from_utf8: Span[SIMD[uint8, 1], is_mutable, lifetime])

Construct a new StringSlice from a sequence of UTF-8 encoded bytes.

Safety: unsafe_from_utf8 MUST be valid UTF-8 encoded data.

Args:

  • unsafe_from_utf8 (Span[SIMD[uint8, 1], is_mutable, lifetime]): A slice of bytes encoded in UTF-8.

__init__(inout self: Self, *, unsafe_from_utf8_strref: StringRef)

Construct a new StringSlice from a StringRef pointing to UTF-8 encoded bytes.

Safety: - unsafe_from_utf8_strref MUST point to data that is valid for lifetime. - unsafe_from_utf8_strref MUST be valid UTF-8 encoded data.

Args:

  • unsafe_from_utf8_strref (StringRef): A StringRef of bytes encoded in UTF-8.

__init__(inout self: Self, *, unsafe_from_utf8_ptr: UnsafePointer[SIMD[uint8, 1], 0], len: Int)

Construct a StringSlice from a pointer to a sequence of UTF-8 encoded bytes and a length.

Safety: - unsafe_from_utf8_ptr MUST point to at least len bytes of valid UTF-8 encoded data. - unsafe_from_utf8_ptr must point to data that is live for the duration of lifetime.

Args:

  • unsafe_from_utf8_ptr (UnsafePointer[SIMD[uint8, 1], 0]): A pointer to a sequence of bytes encoded in UTF-8.
  • len (Int): The number of bytes of encoded data.

as_bytes_slice

as_bytes_slice(self: Self) -> Span[SIMD[uint8, 1], is_mutable, lifetime]

Get the sequence of encoded bytes as a slice of the underlying string.

Returns:

A slice containing the underlying sequence of encoded bytes.

unsafe_ptr

unsafe_ptr(self: Self) -> UnsafePointer[SIMD[uint8, 1], 0]

Gets a pointer to the first element of this string slice.

Returns:

A pointer pointing at the first element of this string slice.