Module imm/string

imm/string

Immutable, thread-safe UTF-8 string type.

Uses atomic reference counting for safe sharing across threads. All "modification" operations return a new string; the original is unchanged.

Types

String atomic object
String

Immutable, thread-safe UTF-8 string.

Uses atomic RC — cheap to clone, safe to share across threads. No mutable operations. All "modification" methods return a new String.

Empty strings are zero-allocation (null pointer, zero length).

Fields

NameTypeDescription
_ptrOption(*(u8))
_lenusize
_capacityusize

Trait Implementations

impl(String, Dispose(...))
dispose : (fn(self: Self) -> unit)

Returns: unit

impl(String, ...)
new : (String) fn() -> String

Create a new empty string (zero allocation).

Returns: String

from : (String) fn(s : str) -> String

Create a string from a str slice (copies the bytes).

Parameters

NameTypeNotes
sstr

Returns: String

from_string : (String) fn(s : String) -> String

Create a string from a standard (mutable) String by copying its bytes.

Parameters

NameTypeNotes
sString

Returns: String

bytes_len : (String) fn(self : String) -> usize

Byte length of the string.

Parameters

NameTypeNotes
selfString

Returns: usize

len : (String) fn(self : String) -> usize

Number of Unicode characters (runes) in the string.

Parameters

NameTypeNotes
selfString

Returns: usize

is_empty : (String) fn(self : String) -> bool

Check if the string is empty.

Parameters

NameTypeNotes
selfString

Returns: bool

as_str : (String) fn(self : String) -> str

Get a str view of the string's bytes (zero-copy borrow).

Parameters

NameTypeNotes
selfString

Returns: str

byte_at : (String) fn(self : String, index : usize) -> Option(u8)

Get the byte at a given index, or .None if out of bounds.

Parameters

NameTypeNotes
selfString
indexusize

Returns: Option(u8)

concat : (String) fn(self : String, other : String) -> String

Concatenate two strings, returning a new string. Uses COW: if this string has a unique reference and enough capacity, appends in-place.

Parameters

NameTypeNotes
selfString
otherString

Returns: String

slice : (String) fn(self : String, start : usize, end : usize) -> String

Extract a byte-range substring [start, end). Returns a new string. If indices are out of bounds, clamps to valid range.

Parameters

NameTypeNotes
selfString
startusize
endusize

Returns: String

starts_with : (String) fn(self : String, prefix : String) -> bool

Check if the string starts with a given prefix.

Parameters

NameTypeNotes
selfString
prefixString

Returns: bool

ends_with : (String) fn(self : String, suffix : String) -> bool

Check if the string ends with a given suffix.

Parameters

NameTypeNotes
selfString
suffixString

Returns: bool

index_of : (String) fn(self : String, needle : String, from_index : usize) -> Option(usize)

Find the first occurrence of needle starting at from_index. Returns byte index or .None.

Parameters

NameTypeNotes
selfString
needleString
from_indexusize

Returns: Option(usize)

contains : (String) fn(self : String, needle : String) -> bool

Check if the string contains a given substring.

Parameters

NameTypeNotes
selfString
needleString

Returns: bool

split : (String) fn(self : String, sep : String) -> List(String)

Split the string by a separator, returning an immutable List of Strings.

Parameters

NameTypeNotes
selfString
sepString

Returns: List(String)

_is_whitespace : (String) fn(b : u8) -> bool

Check if a byte is ASCII whitespace.

Parameters

NameTypeNotes
bu8

Returns: bool

trim : (String) fn(self : String) -> String

Trim leading and trailing ASCII whitespace.

Parameters

NameTypeNotes
selfString

Returns: String

trim_start : (String) fn(self : String) -> String

Trim leading ASCII whitespace.

Parameters

NameTypeNotes
selfString

Returns: String

trim_end : (String) fn(self : String) -> String

Trim trailing ASCII whitespace.

Parameters

NameTypeNotes
selfString

Returns: String

to_lowercase : (String) fn(self : String) -> String

Convert all ASCII uppercase letters to lowercase. Uses COW: if this string has a unique reference, modifies bytes in-place.

Parameters

NameTypeNotes
selfString

Returns: String

to_uppercase : (String) fn(self : String) -> String

Convert all ASCII lowercase letters to uppercase. Uses COW: if this string has a unique reference, modifies bytes in-place.

Parameters

NameTypeNotes
selfString

Returns: String

replace : (String) fn(self : String, search : String, replacement : String) -> String

Replace the first occurrence of search with replacement.

Parameters

NameTypeNotes
selfString
searchString
replacementString

Returns: String

replace_all : (String) fn(self : String, search : String, replacement : String) -> String

Replace all occurrences of search with replacement.

Parameters

NameTypeNotes
selfString
searchString
replacementString

Returns: String

repeat : (String) fn(self : String, n : usize) -> String

Repeat the string n times.

Parameters

NameTypeNotes
selfString
nusize

Returns: String

_decode_rune_at : (String) fn(self : String, byte_index : usize) -> Option(rune)

Decode a single UTF-8 rune starting at byte index.

Parameters

NameTypeNotes
selfString
byte_indexusize

Returns: Option(rune)

at : (String) fn(self : String, index : usize) -> Option(rune)

Get the Unicode character (rune) at a given character index.

Parameters

NameTypeNotes
selfString
indexusize

Returns: Option(rune)

impl(String, Eq(String)(...))
impl(String, ...)
eq_str : (String) fn(self : String, other : str) -> bool

Compare with a str for equality.

Parameters

NameTypeNotes
selfString
otherstr

Returns: bool

impl(String, Ord(String)(...))
impl(String, Hash(...))
impl(String, ToString(...))
to_string : (fn(self: *(Self)) -> std_string.String)

Returns: std_string.String