String
string is Flint’s built-in immutable UTF-8 text view.
It is the normal text type for literals, API parameters, and view-returning text operations. The same source-level model is used on MCU and host targets.
Core Rules
stringvalues are always valid UTF-8.stringis immutable. You do not modify it in place.string.len()returns the UTF-8 byte length, not a character count.string.bytes()returns an immutableslice<u8>view over the underlying bytes.- Direct integer indexing into
stringis not allowed. - Read-only and view-returning methods are the default string surface.
- Portable baseline string methods must not hide allocation.
Basic Usage
let text: string = " key?=value\r\n"
let bytes: slice<u8> = text.bytes()
let len: usize = text.len()
let trimmed: string = text.trim()
let found: bool = "?=" in text
Search and Membership
String search works on UTF-8 text and returns byte indices where applicable.
let text = "mode?=auto?=backup"
let has_delimiter = text.contains("?=")
let first = text.find("?=")
let last = text.find_last("?=")
let has_a = text.contains_char('a')
let first_a = text.find_char('a')
let last_a = text.find_char_last('a')
Flint also supports string membership syntax:
let has_text = "auto" in text
let has_char = 'a' in text
let missing = "uart" not in text
Prefix, Suffix, and Trimming
These methods return booleans or narrower string views. They do not allocate.
let text = " board/pico\r\n"
let is_board = text.trim_start().starts_with("board/")
let has_suffix = text.trim_end().ends_with("pico")
let trimmed = text.trim()
Current shipped trim behavior uses ASCII whitespace semantics.
Subviews and Splitting
string.slice_bytes(start, end) creates a validated subview. The byte range must describe valid UTF-8 boundaries.
let text = "board/pico"
let head = text.slice_bytes(0, 5) // "board"
For common parsing cases, use split_once and split_once_last:
let text = "key?=value?=tail"
let split = text.split_once("?=")
let before = split.before()
let after = split.after()
let last_split = text.split_once_last("?=")
let tail = last_split.after()
These split methods take a full string delimiter, not just a char, and return text.Split. See Text for that type.
ASCII Classification
The portable baseline includes conservative ASCII-focused helpers:
let text = "UART0"
let ascii = text.is_ascii()
let letters = text.is_ascii_letters()
let digits = text.is_ascii_digits()
let alpha_num = text.is_ascii_alphanumeric()
let ws = text.is_ascii_whitespace()
The explicit ASCII naming matters. Flint’s baseline text model is UTF-8 everywhere, but richer Unicode classification and transforms are separate future work.
Mutation
Mutable text does not live on string.
Use std/text.Buffer[N] when you need explicit fixed-capacity text building or editing:
use std/text as text
let mut buffer = text.buffer(32)
let pushed = buffer.push_str("pico")
let view = buffer.as_string()
See Text for the current mutable text surface.