For the complete Mojo documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /docs/manual/basics.md).
string_span
Implements the StringSpan type and related utilities for efficient string operations.
comptime values
ImmStringSlice
comptime ImmStringSlice[origin: ImmOrigin] = ImmStringSpan
Provides a compatibility alias for ImmStringSpan.
Parameters
- origin (
ImmOrigin):
ImmStringSpan
comptime ImmStringSpan[origin: ImmOrigin] = StringSpan[origin]
Provides read-only access to the string data it views.
Parameters
- origin (
ImmOrigin): The origin of the string data.
MutStringSlice
comptime MutStringSlice[origin: MutOrigin] = MutStringSpan
Provides a compatibility alias for MutStringSpan.
Parameters
- origin (
MutOrigin):
MutStringSpan
comptime MutStringSpan[origin: MutOrigin] = StringSpan[origin]
Provides mutable access to the string data it views.
Parameters
- origin (
MutOrigin): The origin of the string data.
StaticString
comptime StaticString = StringSpan[ImmStaticOrigin]
An immutable static string span.
This is a type of
StringSpan
that's immutable and statically allocated. You might use this for situations
that could also be done with a String type, but when you want to
optimize memory usage with zero heap allocations.
The key difference from StringSpan is that a StaticString is guaranteed
to point to data (string literals, constants) that will never be deallocated
(a regular StringSpan may point to any string data that might be freed).
This makes StaticString safe to store long-term without lifetime concerns.
Although you can reassign a StaticString-typed variable with a new value,
you can't modify the underlying data of a StaticString after it's created
the way you can with a String, such as using += to append to it.
Because this is still a StringSpan type, you can do all the same things
with it, such as format a string:
var format_string = StaticString("{}: {}")
print(format_string.format("bats", 6)) # => bats: 6
StringSlice
comptime StringSlice = StringSpan[_]
Provides a compatibility alias for StringSpan.
Structs
-
StringSpan: A non-owning view into encoded string data.
Functions
-
get_static_string: Form a StaticString from compile-time StringSpan values. This guarantees that the returned string is compile-time constant in static memory. It also guarantees that there is a 'nul' zero byte at the end, which is not included in the returned range.