char8

PropertyValue
Size1 byte (8 bits)
RangeU+0000 – U+00FF
CoverageASCII and the Latin-1 supplement

char8 is a single-byte character for ASCII and the Latin-1 supplement (U+0000–U+00FF). Like all Rux character types it is an unsigned, non-nullable value type that holds a single code point or raw code unit, and is type-distinct from both integers and strings. Use it only for strict ASCII or Latin-1 data where the 1-byte constraint is a useful invariant; otherwise prefer the default char.

Literals

A character literal is written with single quotes:

let a: char8 = 'A';     // U+0041
let yen: char8 = '¥';   // U+00A5
let euro: char8 = '€';  // U+20AC — compile error: out of range for char8

Code points above U+00FF cannot be represented and produce a compile-time error.

Escape Sequences

SequenceCharacter
\nNewline (U+000A)
\rCarriage return (U+000D)
\tHorizontal tab (U+0009)
\\Backslash (U+005C)
\'Single quote (U+0027)
\"Double quote (U+0022)
\0Null (U+0000)
\u{XXXXXX}Unicode scalar value (hex)

The \u{...} escape takes 1–6 hexadecimal digits (braces mandatory); values outside the type's range are rejected at compile time.

Typical Use Cases

  • ASCII protocol parsing
  • Latin-1 text buffers
  • Byte-oriented tokenizers

Comparison

Character types are comparable for both equality and ordering. Ordering follows the numeric value of the underlying code point (code-point order, not locale-aware collation).

OperatorDescriptionResult
==Equalbool
!=Not equalbool
< <= > >=Code-point orderingbool
let a: char8 = 'a';
let b: char8 = 'b';

let eq = a == b;  // false
let lt = a < b;   // true  (U+0061 < U+0062)

Conversion

Character types are not integers, but they convert explicitly with as.

Widening to a wider char type is implicit and always safe:

let c: char8 = 'Z';
let wide: char16 = c;   // widening — always valid

Narrowing to a smaller char type is checked at runtime: a value that does not fit triggers a fatal error, so prefer the as? form, which returns null instead:

let wide: char32 = '🔥';            // U+1F525
let narrow = wide as char8;         // fatal error: value > U+00FF
let safe: char8? = wide as? char8;  // null instead

Conversions to and from the backing integer type are also explicit:

let c: char8 = 'A';
let n = c as uint32;     // 0x00000041
let back = n as char8;   // 'A'

Char types have no arithmetic operators — cast to the integer type to compute offsets, then cast back:

let c: char8 = 'a';
let next = (c as uint32 + 1) as char8;  // 'b'

String Interop

A single character converts to a one-character String with String::From() or interpolation, and String indexing returns a char by code-point position (not byte offset):

let c: char8 = 'A';
let s = String::From(c);        // "A"
let t = "{c}";                 // "A"  (interpolation)
let first: char = "Hello"[0];  // 'H'

Source files are UTF-8; in memory a char is a little-endian unsigned integer of its declared width.

See Also

  • char — the default character type
  • char16 — the next width up