Skip to content
📖 The Auto Programming LanguageBook contents

Appendix D: Standard Library Index ​

This appendix provides an alphabetically-organized reference of all standard library functions and types demonstrated in this book. For detailed examples and cross-language comparisons, see Chapter 21 (Standard Library Tour).

std::core ​

Core types and macros available in every Auto program without an explicit use.

NameSignatureKindDescriptionCh.
Bool--typeBoolean type with values true and false2
Float--type64-bit floating-point number type2
format!format!(template, args...) StringmacroInterpolate values into a string template2, 21
Int--type64-bit signed integer type2
panic!panic!(msg)macroHalt the program with an error message9
printprint(value)fnWrite a value to stdout without a trailing newline4, 21
printlnprintln(value)fnWrite a value to stdout with a trailing newline1, 2, 21
String--typeHeap-allocated UTF-8 text string2

std::string ​

Methods on the String type for text processing. See Listing 21-1 for a full example.

NameSignatureKindDescriptionCh.
containss.contains(needle) boolmethodReturn true if needle is a substring of s21
ends_withs.ends_with(suffix) boolmethodReturn true if s ends with suffix21
joinlist.join(sep) StringmethodConcatenate list elements separated by sep21
lens.len() intmethodReturn the byte length of s4, 18
replaces.replace(old, new) StringmethodReturn a copy of s with all occurrences of old replaced by new21
splits.split(delimiter) List<String>methodSplit s into a list of substrings4, 21
starts_withs.starts_with(prefix) boolmethodReturn true if s starts with prefix21
to_lowers.to_lower() StringmethodReturn a lowercase copy of s21
to_uppers.to_upper() StringmethodReturn an uppercase copy of s21
trims.trim() StringmethodRemove leading and trailing whitespace21

std::math ​

Mathematical functions and constants. See Listing 21-2.

NameSignatureKindDescriptionCh.
absabs(x) TfnReturn the absolute value of x21
ceilceil(x) FloatfnRound x up to the nearest integer21
clampclamp(value, lo, hi) TfnConstrain value to the range [lo, hi]21
floorfloor(x) FloatfnRound x down to the nearest integer21
maxmax(a, b) TfnReturn the larger of a and b21
minmin(a, b) TfnReturn the smaller of a and b21
powpow(base, exp) FloatfnRaise base to the power of exp21
roundround(x) FloatfnRound x to the nearest integer21
sqrtsqrt(x) FloatfnReturn the square root of x21

std::collections ​

Operations on List<T>, Map<K,V>, and Set<T>. Iterator methods (.map(), .filter(), .fold()) are covered in Chapter 19; the functions below are the additional collection helpers. See Listing 21-4.

NameSignatureKindDescriptionCh.
chunklist.chunk(size) List<List<T>>methodSplit list into sub-lists of at most size elements21
containslist.contains(value) boolmethodReturn true if value is in list4
filterlist.filter(pred) List<T>methodKeep only elements satisfying pred19
flattenlist.flatten() List<T>methodFlatten a list of lists into a single list21
foldlist.fold(init, fn) TmethodReduce the list to a single value with an accumulator19
is_emptylist.is_empty() boolmethodReturn true if the collection has no elements4
lenlist.len() intmethodReturn the number of elements4
maplist.map(fn) List<U>methodTransform each element by applying fn19
pushlist.push(value)methodAppend value to the end of list4
reverselist.reverse() List<T>methodReturn a new list with elements in reverse order21
sortlist.sort() List<T>methodReturn a new sorted copy of list (ascending by default)4, 21
uniquelist.unique() List<T>methodRemove duplicates while preserving insertion order21
ziplist.zip(other) List<(T, U)>methodCombine two lists into a list of pairs21

std::fs ​

File I/O, path manipulation, and directory operations. These functions use the !T result type for error handling. See Listing 21-3.

NameSignatureKindDescriptionCh.
copycopy(src, dst)fnCopy a file from src to dst21
existsexists(path) boolfnReturn true if the file or directory at path exists14, 21
list_dirlist_dir(path) List<String>fnList entries in the directory at path21
mkdirmkdir(path)fnCreate a directory (and parents if needed)21
path_joinpath_join(parts...) StringfnJoin path segments with the platform separator14, 21
read_fileread_file(path) !StringfnRead the entire contents of a file as a string14, 21
removeremove(path)fnDelete a file or empty directory21
write_filewrite_file(path, content)fnWrite content to a file, creating or overwriting it21

std::json ​

JSON serialization and deserialization. Works with any type that implements the Serialize and Deserialize specs. See Listing 21-6.

NameSignatureKindDescriptionCh.
from_json!from_json!(str, T) !TmacroDeserialize a JSON string into a value of type T21
to_jsonto_json(value) StringfnSerialize a value to a compact JSON string21
to_json_prettyto_json_pretty(value) StringfnSerialize a value to an indented JSON string21

std::time ​

Types and functions for working with dates, times, and durations. See Listing 21-5.

NameSignatureKindDescriptionCh.
Duration--typeA span of time (e.g., 2 hours, 30 minutes)21
Duration.hoursDuration.hours(n) DurationfnCreate a duration of n hours21
Duration.minutesDuration.minutes(n) DurationfnCreate a duration of n minutes21
Duration.secondsDuration.seconds(n) DurationfnCreate a duration of n seconds21
Time--typeA point in time (instant)21
Time.nowTime.now() TimefnReturn the current time as a Time value21
Time.parseTime.parse(str, fmt) !TimefnParse a time string using the given format specifier21
formattime.format(fmt) StringmethodFormat a Time value as a string using strftime specifiers21
total_minutesdur.total_minutes() intmethodConvert a duration to its total value in minutes21
total_secondsdur.total_seconds() intmethodConvert a duration to its total value in seconds21

std::thread ​

Concurrency primitives for spawning threads and controlling execution. See Chapter 15 and Chapter 16.

NameSignatureKindDescriptionCh.
joinhandle.join()methodWait for a spawned thread to complete15
sleepsleep(duration)fnBlock the current thread for the given duration15
spawnspawn fnkeywordStart executing a function as a new actor/thread15
yieldyieldkeywordReturn control to the runtime scheduler15

std::testing ​

Assertions and test infrastructure. See Chapter 18.

NameSignatureKindDescriptionCh.
#\[test\]#[test]attributeMark a function as a test to be run by automan test18
assertassert(cond)fnPanic if cond is false18
assert_eqassert_eq(a, b)fnPanic if a does not equal b; prints both values on failure18
assert_neassert_ne(a, b)fnPanic if a equals b; prints both values on failure18
test_maintest_main()fnRun all functions annotated with #[test]18

Released under the MIT License.