The snippet library.
Small, practical examples. Search by task or narrow things down below.
Accept different types with a generic function
Accept different types with a generic function in a complete Rust program using the standard library.
Rust✓ Tested
Accumulate a result with fold
Accumulate a result with fold in a complete Rust program using the standard library.
Rust✓ Tested
Add context to a parsing failure
Add context to a parsing failure in a complete Rust program using the standard library.
Rust✓ Tested
Append several values to a vector
Append several values to a vector in a complete Rust program using the standard library.
Rust✓ Tested
Append to a file without truncating it
Append to a file without truncating it in a complete Rust program using the standard library.
Rust✓ Tested
Assert approximate floating-point equality
Assert approximate floating-point equality in a complete Rust program using the standard library.
Rust✓ Tested
Bind a value with let
Bind a value with let in a complete Rust program using the standard library.
Rust✓ Tested
Borrow local data in a scoped thread
Borrow local data in a scoped thread in a complete Rust program using the standard library.
Rust✓ Tested
Borrow text until a modification is needed
Borrow text until a modification is needed in a complete Rust program using the standard library.
Rust✓ Tested
Borrow text without transferring ownership
Borrow text without transferring ownership in a complete Rust program using the standard library.
Rust✓ Tested
Calculate an order subtotal
Calculate an order subtotal in a complete Rust program using the standard library.
Rust✓ Tested
Call a typed function
Call a typed function in a complete Rust program using the standard library.
Rust✓ Tested