Lang ships a compact standard library through two layers:
- a tiny prelude imported into generated project modules
- explicit modules under
std.*
The compiler emits Python facade modules for std, then those facades call the native Rust lang_std_native runtime through PyO3.
These names are available in project code without an import:
value = Some("spark")
print(value.unwrap())
print(Ok(3).unwrap())
print(len(range(1, 4)))
print(" lamp ".strip().upper())
Prelude exports:
Some,Nothing,Ok,ErrIterator,iter,range,lenStr,Num,Bool,Vec,Map,Set,wrap,unwrapprint,input,str,int,float,bool
The std package is always available as a global object in compiled projects:
print(std.text.upper("lamp"))
print(std.fs.exists("notes.txt"))
print(std.term.bold("hot"))
This is the preferred style for short scripts and toy programs.
Explicit imports still work when a shorter local name reads better:
from std.text import upper, contains
from std.random import choice
from std.term import color
print(upper("lamp"))
print(contains("lamp", "am"))
print(choice(range(1, 1)).__class__.__name__)
print(color("hot", "red"))
Available modules:
std.core:Some,Nothing,Ok,Err,panic,type_name,debugstd.iter:Iterator,iter,range,enumerate,zip,map,filter,fold,collect,any,allstd.text:upper,lower,title,strip,split,join,replace,contains,starts_with,ends_withstd.collections:Vec,Map,Set,Counterstd.math:min,max,abs,round,floor,ceil,sqrt,clampstd.random:rand,randint,choice,shufflestd.path:Path,cwd,homestd.fs:read_text,write_text,exists,is_file,is_dir,list_dirstd.env:argsstd.io:read_line,read_to_end,print,printlnstd.time:now,sleep,millisstd.term:color,bold,clear,promptstd.primitives:Str,Num,Bool,Vec,Map,Set,wrap,unwrap
Primitive values are Lang-owned runtime values with methods:
text = std.fs.read_text("notes.txt")
.expect("Failed to read notes.txt")
.strip()
lines = text.lines()
words = text.words()
print(lines.len)
print(words.len)
print(text.len)
Every primitive supports tap(fn) and pipe(fn):
word_count = "small bright language"
.tap((text) => print(text))
.words()
.pipe((words) => words.len)
Use tap for side effects while keeping the original value. Use pipe when the callback result should become the next value.
Fallible APIs return result-like values:
from std.fs import read_text
text = read_text("notes.txt")
print(text.unwrap_or("missing"))
Use unwrap() when failure should stop the program, and unwrap_or(default) when a fallback is clearer.
Result values also expose is_ok() and is_err() for branches:
file = std.fs.read_text("notes.txt")
if file.is_ok() {
print(file.unwrap())
}
name = std.io.read_line()
args = std.env.args()
std.io.println("hello " + name)
print(len(args))
std.io.print(value) writes without adding a newline. std.io.println(value) adds one. Global print stays available for brief scripts.
Standard modules are compiler-owned. They do not need files in the user project:
import std.fs as fs
print(fs.exists("notes.txt"))
Unknown std exports fail during project build:
from std.text import screaming // build error