> module
std
overview of Xur's standard library
The std module is Xur's standard library, registered automatically at startup. Its submodules are brought in with use, and each has its own page, such as xur.std.io(7). A few functions live at the top level of std itself, and the prelude adds Option and Result to every program.
Some modules depend on Cargo features of xur-std and are missing from builds without them; they are all on in the xur command-line tool.
> functions
The program's command line. The first item is Some(path) with the script's path, or None when the script was read from stdin; the rest are the arguments that followed it, as strings. The list is empty when the host didn't set the arguments (for example inside a stub).
Loads the Xur file at path and returns it as a module value. A relative path is relative to the file of the code that calls it; a directory loads its lib.xur. With a string-literal path the file is loaded before the program runs, so its items resolve at compile time and the language server can follow them. Any other argument is loaded when the call runs. A file that can't be read or has errors is a runtime error.
Stops the program with a runtime error whose message is format formatted with args as by fmt::format.
> functions
These are called by their full path, std::import(..), without a use.
> modules
std::any — runtime type information
std::assert — test assertions
std::bytes — byte buffer operations
std::cell — shared mutable values
std::cli — argument parsing and interactive prompts
std::datetime — date and time
std::decimal — arbitrary-precision decimal numbers
std::env — environment variables and process paths
std::fmt — format strings
std::fs — filesystem access
std::gui — desktop GUI with egui
std::hash — checksums and hashes
std::http — HTTP client
std::io — console I/O, and std::io::c for ANSI colours
std::json — JSON serialisation
std::list — list methods
std::log — structured logging
std::map — map methods
std::math — mathematical functions
std::mem — struct layout, raw memory and page allocation
std::net — TCP, UDP and Unix-domain sockets
std::num — integer and float methods
std::path — path manipulation
std::process — spawning and controlling child processes
std::ptr — raw pointer utilities
std::random — random number generation
std::re — reverse engineering: executables, processes, .NET
std::record — record methods
std::reflect — runtime reflection and binary layout, and std::reflect::func for functions
std::regex — regular expressions
std::str — string methods
std::stub — scripting inside another process, injected with xur stub
std::sync — channels for sending values between threads
std::thread — running code in parallel
std::time — timing, durations and sleep
std::xur — how the program was started
> prelude
The prelude is loaded into every program. It defines Option and Result, and brings Some, None, Ok and Err into scope.
enum Option<T> { Some(T), None }
is_some() -> bool
is_none() -> bool
unwrap() -> T // panics on None
expect(message: str) -> T // panics with message on None
unwrap_or(default: T) -> T
unwrap_or_else(f: fn() -> T) -> T
map(f: fn(T) -> U) -> Option<U>
ok_or(error: E) -> Result<T, E>
enum Result<T, E = str> { Ok(T), Err(E) }
is_ok() -> bool
is_err() -> bool
unwrap() -> T // panics with the error on Err
expect(message: str) -> T // panics with "message: error" on Err
unwrap_or(default: T) -> T
unwrap_or_else(f: fn(E) -> T) -> T
ok() -> Option<T>
map(f: fn(T) -> U) -> Result<U, E>
map_err(f: fn(E) -> F) -> Result<T, F>The ? operator works on both: it returns early with the None or Err, and otherwise unwraps the value.
> examples
use std::io;
use std::fs;
fn main() {
match fs::read_to_string("hello.txt") {
Ok(text) => io::println("contents: {}", text),
Err(e) => std::panic("couldn't read hello.txt: {}", e),
}
}