API reference: std
std::alloc: Allocators over storage the program owns:FixedBufferservesAllocfrom a byte buffer (no heap, usable inrealtimecode), andbump_allocis the step to build your own bump allocator handler.std::buf:Buf<T>, the growable buffer (Rust'sVec), and its algorithms: sort, search, retain, dedup. Growing asks forAllocand destroying elements forFree; the index formsv[i],v[lo..hi],v.remove(i)require their index fact or use the_checkedmethods (Panic).std::bytes: Byte strings: searching, splitting, trimming and bounds-checked ranges over&[u8], the ASCII classes and case mappings of a byte and of&[u8], and decimal integers parsed from bytes and formatted into them. Reach for it on paths, protocol fields and aString's bytes (as_bytes) before or without UTF-8 validation. Nothing here panics: a bad range isNone; only the copying case mappings allocate.std::cell: Cells for sharing between threads:OnceCell, set once and then read from any thread without a lock, andCachePadded, which keeps a value on cache lines of its own so threads writing neighbouring values do not slow each other down (false sharing).std::clone: Duplicating values:Clone. Acopyvalue is duplicated by naming it;cloneis for the rest, a value that owns memory (String,Box<T>), whose clone owns fresh memory of its own. Allocating is an effect, socloneasks forAlloc, which serves the regionselfis in: the clone lives where the original does.Buf,DequeandHashMaphave noCloneyet: a loop of element clones is refused (R-Loan, decision 4488).std::cmp: Equality, ordering and hashing:Eq,OrdandHash, the traitsstd::mapand the sorted collections bound their keys by, with impls for the scalars,Box,Option,Buf,Strand&[u8], and named derives (impl Eq for Key = DeriveEq;) for your own types.std::deque:Deque, a double-ended queue: push and pop at both ends in amortised O(1), and index from the front. Pushing askswith Allocbecause the ring may grow; nothing else allocates.std::env: The program's arguments and environment variables, read from the root'sEnvintoBuf<u8>s (hencewith Env, Alloc). They are bytes, as passed: an argument need not be UTF-8, and itsas_bytes()is a path as it is. The environment is a snapshot taken at process start. In the simulated world (the library default, the playground) there are no arguments and no variables; a test installs its ownEnvhandler with the ones it wants.std::errno: The errnostd::fs,std::netandstd::envanswer in theirErrs, named and formatted. They answer the kernel's word, a bareInt, so amatchtakesErr(2); wrapping it,Errno::new(e), gives itsDisplay:strerror's text as glibc words it (No such file or directory), andUnknown error <n>for a number outside the table.std::fs: Files as an effect: code reaches the file system only through anFscapability in its row, and only beneath the directory descriptors it is handed: every path is resolved beneath adir: &Fd, and an absolute one or a..that would leave it failsEXDEV(18). The root hands a program its first directory,cwd, and the program hands it on. Paths are bytes (&[u8]). Errors are the kernel's errno values (Err(Int)).std::fun: The closure traits, one per arity. A closure passed where a boundF: Fn(A) -> Ris expected implementsFn1<A, R>; its body runs with no capabilities.std::heap:BinaryHeap, a priority queue: the greatest element byOrd(seestd::cmp) is read in O(1) and removed in O(log n). Pushing askswith Allocbecause the buffer may grow; nothing else allocates.std::io: Byte input by the line. Standard input is read through the root'sStdin(a prelude effect, besideStdoutandStderr):Stdin.read(&mut b)copies the next bytes there are intob, andStdin.read_line(&mut b)those up to and including the next\n, each answering the count, 0 at the end of the input.read_lineandread_to_endappend to aBuf<u8>instead (hencewith Stdin, Alloc); the root buffers standard input, so a line is no system call. A socket or a file has no such buffer: aLineReaderis one, for any source of bytes. The input is bytes, as given: a line need not be UTF-8, andString::from_utf8validates one. In the simulated world (the library default, the playground,weir exploreandweir test) standard input is empty; a test scripts it withstd::sim::SimStdin.std::iter: Iteration: theIteratorpull trait, its adaptors and consumers, and integer ranges.std::lockfree:LockFreeMap, a fixed-size hash map many threads read and write at once without a lock. Every access goes throughLockFreeMap::pinand theMapGuardit lends; removed entries are freed later, byLockFreeMap::collect, once no pinned thread can still see them.std::map: A hash map,HashMap, keyed by anyK: Hash + Eq(seestd::cmp). Methods that may grow the table ask forAlloc(new,with_capacity,insert); those that destroy entries ask forFree(remove,clear); lookups need no capability.std::memfs: An in-memory file system for tests:MemFsservesstd::fs::Fsover the root'sLoopback, whose file ops reach the simulated tree on every backend, interpreted and native, whatever the run's world. A#[test]installs it and runs a tool'swith Fscode against files it made, the same way every time. The tree is empty when the run starts.std::net: Networking as an effect: code reaches sockets only through aNetcapability in its row, so its caller's executor decides how each operation waits.Netincludesstd::task::Tasks(soClock) andstd::fs::Fs: one executor parks sleepers, tasks, socket ops and file ops in one table, and code writtenwith Tasks,with Clockorwith Fsruns in aNettask unchanged.closeisFs's, the one close of every descriptor. InstallEventedorBlockinginmain(they need the root'sReactor,SysandThreads); a test usesstd::sim::net_world.std::option:Option<T>'s methods.Optionis the prelude's enum; its inherent methods are this module's, which every program loads, soo.is_none()needs nouse.unwrapandexpectare built-ins, not methods here; no method here can panic. The combinators take closures asstd::iter's adapters do (F: Fn(T) -> U,std::fun): a closure literal there may borrow the enclosing locals, and its body runs with no capabilities, so these methods' rows are empty too.std::stringprints an option as it is written,Some(3)orNone.std::panic: Recovering from a panic:catch_panicruns a function and turns a panic inside it into anErrcarrying the panic's message, after unwinding (destructors and guards run). Without it the root'sPanichandler isterminaland a panic ends the program.std::rand: Randomness as an effect: code draws random numbers only through aRandomcapability, and fault points only throughDraw, so its caller decides where the answers come from. The root supplies noRandom:OsRandomdraws the operating system's entropy through the root'sSys,std::sim::SimRandomis a seeded generator, andCalmanswers everyDrawthe common way.std::result:Result<T, E>'s methods.Resultis the prelude's enum; its inherent methods are this module's, which every program loads, sor.is_ok()needs nouse. Onlyunwrapandexpectcan panic: their rows ask forPanic. The combinators take closures asstd::iter's adapters do (F: Fn(T) -> U,std::fun), whose bodies run with no capabilities, so their rows are empty.std::stringprints a result as it is written,Ok(3)orErr(e).std::retire: Retiring elements of aBufinto a caller's reclamation budget (Budget{Free}): the functions install aretire_fromblock over the budget, and its reclaimer destroys what they retire when the budget's owner destroys it. A budget with too few slots aborts the process.std::set: A hash set,HashSet, of anyK: Hash + Eq(seestd::cmp): the keys of astd::map::HashMapwith no values. As there, methods that may grow the table ask forAlloc(new,with_capacity,insert), those that destroy keys ask forFree(remove,clear), and lookups need no capability.std::sim: Deterministic simulation for tests: handlers forstd::time::Clock,std::rand::Random,std::rand::Draw,std::task::Tasks,std::net::Net,std::memfs::MemTreeand the prelude'sStdinwhose answers depend only on their arguments, so code that reaches time, randomness, tasks, the network, the disk and its input only through its row runs the same way every time. Start withworld(tasks),net_world(network) ordisk_world(disk).std::slice: Views ofTslots: aSlice<T>islenslots of storage lent by its owner (Buf::slice,Buf::slice_mut), always behind&or&mut. The formss[i],&mut s[i],s[i] = x,&s[lo..hi]andfor x in scall these: the plain ones require the index fact, the_checkedones raisePanicinstead.std::string: Text:String, an owned, growable UTF-8 string whose borrowed view is its bytes,&[u8];Display, the trait a value formats itself into aStringby; andprint/println. Appending asks forAlloc(the string may grow), printing forStdout; nothing here panics.std::sync: Waiting between tasks, over the executor's keys (std::task::Tasks'swaker,parkandwake): a task that waits is parked in its executor's table, never polling, and the task that wakes it readies it there. Both work under every executor (std::task::Pool,std::net'sEventedandBlocking,std::sim's worlds). Underweir exploreof a searched world every park is a scheduling point, and so is the start of every wait (Tasks.preempt()), where a wake-up from another thread can land between a check and the wait that depends on it.std::task: Concurrent tasks as an effect: code starts tasks only through aTaskscapability in its row, so its caller's executor decides where and when they run. ATaskscapability is also astd::time::Clock, so code writtenwith Clockruns in a task unchanged. UsePoolin a program andstd::sim::world(deterministic, one seed one schedule) in a test.std::test: Assertions for#[test]s and for any code that checks itself. Each failure is aPanic(raise), which fails the test.assert_eqandassert_neformat the two values by theirDisplayimpls into aString(henceAllocin their rows; equal values allocate nothing) and panic throughpanic_detail: a handler of thePanicseesassert_eq failed, and the root's halt readsassert_eq failed: left 3, right 4. They take the values, as a call takes its arguments: a scalar, aStror a byte view&[u8]is copied, and a value that owns memory is moved and dropped. Rust's#[should_panic]is written as a test that callsexpect_panic.std::time: Time as an effect: code reads the clock and waits on it only through aClockcapability in its row, so its caller decides which clock it reads. Every executor (std::task::Pool,std::net::Evented) handles it with the monotonic clock in nanoseconds; a test usesstd::sim::SimClockor the virtual time ofstd::sim::world.std::tuple: Tuples. The type(A, B)is [Tuple2<A, B>], up to(A, B, C, D, E, F),Tuple6: the surface writes(a, b)for a literal,t.0for a field and(x, y)for a pattern, and every program loads this module, so none of those needs ause. A tuple iscopy,forgetor linear as its components are, and compares, orders and hashes field by field where its components do (std::cmp's derives), clones where they clone (std::clone), andstd::stringprints it as(a, b).
Reading the reference
Each entry shows a declaration as weir fmt writes it, then its doc comment. An effect's op has a
control kind, which says what a handler's clause may do with the code that performed it:
tail(an op written without a kind): the clause's result is the op's; the performer is never aborted or suspended.fallible: the clause resumes at once or aborts thewith(abort(v)).raise: the clause never resumes; the perform unwinds to the handler'swith.terminal: the clause halts the process; nothing is cleaned up.linear: the clause takes the continuation (cont k) and resumes it exactly once: a suspension.once: the clause takes the continuation and resumes or cancels it: a suspension and an abort edge.
A function of a package lists its committed interface: the lines of its entry in the module's
.iface, which every caller outside the module is checked against (and its body must stay
within). bound C: … lines give each capability parameter's bound (what the function may do
through it); fact lines say what a call may do beyond its signature (aborts: the ops it may
abort at, may diverge, scheduling point: where it may suspend, writes through, reads
regions, destroys values of, holds, loan of); callback lines give each callback
parameter's envelope (the capabilities it may use) and what the function does with it.