Mojo struct
StringRef
Represent a constant reference to a string, i.e. a sequence of characters and a length, which need not be null terminated.
Fieldsβ
- βdata (
UnsafePointer[SIMD[uint8, 1], 0, 0, alignof[::AnyType,__mlir_type.!kgen.target]() if triple_is_nvidia_cuda() else 1]
): A pointer to the beginning of the string data being referenced. - βlength (
Int
): The length of the string being referenced.
Implemented traitsβ
AnyType
,
Boolable
,
CollectionElement
,
CollectionElementNew
,
Comparable
,
Copyable
,
EqualityComparable
,
ExplicitlyCopyable
,
Formattable
,
Hashable
,
IntableRaising
,
Movable
,
Sized
,
Stringable
Methodsβ
__init__
β
__init__(inout self: Self)
Construct a StringRef value with length zero.
__init__(inout self: Self, *, other: Self)
Copy the object.
Args:
- βother (
Self
): The value to copy.
__init__(inout self: Self, str: StringLiteral)
Construct a StringRef value given a constant string.
Args:
- βstr (
StringLiteral
): The input constant string.
__init__(inout self: Self, ptr: UnsafePointer[SIMD[int8, 1], 0, 0, alignof[::AnyType,__mlir_type.!kgen.target]() if triple_is_nvidia_cuda() else 1], len: Int)
Construct a StringRef value given a (potentially non-0 terminated string).
The constructor takes a raw pointer and a length.
Note that you should use the constructor from UnsafePointer[UInt8]
instead
as we are now storing the bytes as UInt8.
See https://github.com/modularml/mojo/issues/2317 for more information.
Args:
- βptr (
UnsafePointer[SIMD[int8, 1], 0, 0, alignof[::AnyType,__mlir_type.!kgen.target]() if triple_is_nvidia_cuda() else 1]
): UnsafePointer to the string.