Module string/rune

string/rune
Stability: unstable — seven of the eleven methods are ASCII-ONLY under names Rust reserves for the Unicode behaviour: `is_whitespace`, `is_digit`, `is_alphabetic`, `is_uppercase`, `is_lowercase`, `to_lowercase` and `to_uppercase` all test or shift the ASCII range and pass every other code point through unchanged. Each says so in its own doc, but the NAMES are the problem — Rust spells these `is_ascii_*` / `to_ascii_*` and keeps the unprefixed names for the table-driven versions. The audit's plan (`plans/STD_API_STABILIZATION.md` §4, "Text") is to rename them to `is_ascii_*` / `to_ascii_*` and add real Unicode versions backed by `std/string/unicode.yo`'s tables. That rename is breaking, so the module cannot be frozen before it lands. `rune` itself, `from_u32`, `to_u32`, `is_ascii` and the named constants are settled. — stable modules only change additively; this one may still change.

Unicode code point type (rune) for representing individual characters.

A rune is a newtype over u32 holding one scalar value — Go's rune, Rust's char. from_u32 is the only constructor that validates, and it rejects the surrogate range D800..=DFFF as well as anything above 10FFFF, so a rune in hand is always encodable as UTF-8. Runes are values: Eq, Ord and Send are all defined by comparing the code point.

This module gives a PRIMITIVE type its inherent methods from outside the prelude (the prelude imports nothing and has no c_include, so it cannot host them); std/math.yo follows the same pattern.

Stability

unstable — seven of the eleven methods are ASCII-ONLY under names Rust reserves for the Unicode behaviour: is_whitespace, is_digit, is_alphabetic, is_uppercase, is_lowercase, to_lowercase and to_uppercase all test or shift the ASCII range and pass every other code point through unchanged. Each says so in its own doc, but the NAMES are the problem — Rust spells these is_ascii_* / to_ascii_* and keeps the unprefixed names for the table-driven versions. The audit's plan (plans/STD_API_STABILIZATION.md §4, "Text") is to rename them to is_ascii_* / to_ascii_* and add real Unicode versions backed by std/string/unicode.yo's tables. That rename is breaking, so the module cannot be frozen before it lands. rune itself, from_u32, to_u32, is_ascii and the named constants are settled.

Types

rune newtype
rune

Unicode code point (U+0000 to U+10FFFF, excluding surrogates). Similar to Go's rune or Rust's char.

Fields

NameTypeDescription
charu32

The raw Unicode code point value.

Trait Implementations

impl(generic(T : Type), where(T <: ToString), T : (ToString))
impl(generic(T : Type), where(T <: ToString), T : (ToString), Format)
format : fn(self : Self, spec : str) -> String

Render self under spec. An unrecognised spec degrades to the plain to_string() rendering rather than failing.

Parameters

NameTypeNotes
selfSelf
specstr

Returns: String

impl(rune, ...)
from_u32 : (rune) fn(value : u32) -> Option(rune)

Create a rune from a u32 value, returning None if the value is not a valid Unicode code point.

Parameters

NameTypeNotes
valueu32

Returns: Option(rune)

to_u32 : (rune) fn(self : rune) -> u32

Return the raw u32 code point value.

Parameters

NameTypeNotes
selfrune

Returns: u32

is_ascii : (rune) fn(self : rune) -> bool

Check if this is an ASCII character (U+0000 to U+007F).

Parameters

NameTypeNotes
selfrune

Returns: bool

is_whitespace : (rune) fn(self : rune) -> bool

Check if this is a whitespace character (space, tab, newline, or carriage return).

Parameters

NameTypeNotes
selfrune

Returns: bool

is_digit : (rune) fn(self : rune) -> bool

Check if this is an ASCII digit ('0' to '9').

Parameters

NameTypeNotes
selfrune

Returns: bool

is_alphabetic : (rune) fn(self : rune) -> bool

Check if this is an ASCII letter ('A'-'Z' or 'a'-'z').

Parameters

NameTypeNotes
selfrune

Returns: bool

is_uppercase : (rune) fn(self : rune) -> bool

Check if this is an ASCII uppercase letter ('A'-'Z').

Parameters

NameTypeNotes
selfrune

Returns: bool

is_lowercase : (rune) fn(self : rune) -> bool

Check if this is an ASCII lowercase letter ('a'-'z').

Parameters

NameTypeNotes
selfrune

Returns: bool

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

Convert to lowercase. Only affects ASCII uppercase letters.

Parameters

NameTypeNotes
selfrune

Returns: rune

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

Convert to uppercase. Only affects ASCII lowercase letters.

Parameters

NameTypeNotes
selfrune

Returns: rune

NUL : Self

Null character (U+0000).

Returns: unknown

REPLACEMENT : Self

Replacement character (U+FFFD) — what a lossy decoder substitutes for an invalid byte sequence. See std/encoding/utf8's decode_lossy.

Returns: unknown

TAB : Self

Horizontal tab (U+0009).

Returns: unknown

NEWLINE : Self

Line feed / newline (U+000A).

Returns: unknown

SPACE : Self

Space (U+0020).

Returns: unknown

ZERO : Self

Digit zero '0' (U+0030).

Returns: unknown

NINE : Self

Digit nine '9' (U+0039).

Returns: unknown

UPPERCASE_A : Self

Uppercase 'A' (U+0041).

Returns: unknown

UPPERCASE_Z : Self

Uppercase 'Z' (U+005A).

Returns: unknown

LOWERCASE_A : Self

Lowercase 'a' (U+0061).

Returns: unknown

LOWERCASE_Z : Self

Lowercase 'z' (U+007A).

Returns: unknown

impl(rune, Eq(rune))
impl(rune, Ord(rune))
impl(rune, Send())
impl(rune, Default(...))
default : (rune) fn() -> rune

The default value of the type.

Returns: rune

Methods
== : (rune) fn(lhs : rune, rhs : rune) -> bool

Parameters

NameTypeNotes
lhsrune
rhsrune

Returns: bool

!= : (rune) fn(lhs : rune, rhs : rune) -> bool

Parameters

NameTypeNotes
lhsrune
rhsrune

Returns: bool

< : (rune) fn(lhs : rune, rhs : rune) -> bool

Parameters

NameTypeNotes
lhsrune
rhsrune

Returns: bool

<= : (rune) fn(lhs : rune, rhs : rune) -> bool

Parameters

NameTypeNotes
lhsrune
rhsrune

Returns: bool

> : (rune) fn(lhs : rune, rhs : rune) -> bool

Parameters

NameTypeNotes
lhsrune
rhsrune

Returns: bool

>= : (rune) fn(lhs : rune, rhs : rune) -> bool

Parameters

NameTypeNotes
lhsrune
rhsrune

Returns: bool

cmp : (rune) fn(lhs : rune, rhs : rune) -> Ordering

Parameters

NameTypeNotes
lhsrune
rhsrune

Returns: Ordering

is_prefix_of : (rune) fn(self : rune, haystack : String, position : usize) -> bool

Parameters

NameTypeNotes
selfrune
haystackString
positionusize

Returns: bool

is_suffix_of : (rune) fn(self : rune, haystack : String, end_position : usize) -> bool

Parameters

NameTypeNotes
selfrune
haystackString
end_positionusize

Returns: bool

index_in : (rune) fn(self : rune, haystack : String, from_index : usize) -> Option(usize)

Parameters

NameTypeNotes
selfrune
haystackString
from_indexusize

Returns: Option(usize)

is_contained_in : (rune) fn(self : rune, haystack : String, from_index : usize) -> bool

Parameters

NameTypeNotes
selfrune
haystackString
from_indexusize

Returns: bool

last_index_in : (rune) fn(self : rune, haystack : String, from_index : usize) -> Option(usize)

Parameters

NameTypeNotes
selfrune
haystackString
from_indexusize

Returns: Option(usize)

length_in : (rune) fn(self : rune, haystack : String, at : usize) -> usize

Parameters

NameTypeNotes
selfrune
haystackString
atusize

Returns: usize

split_of : (rune) fn(self : rune, haystack : String) -> ArrayList(String)

Parameters

NameTypeNotes
selfrune
haystackString

Returns: ArrayList(String)

to_string : (rune) fn(self : rune) -> String

Parameters

NameTypeNotes
selfrune

Returns: String

debug_string : (rune) fn(self : rune) -> String

Parameters

NameTypeNotes
selfrune

Returns: String