Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Standard Library

Cross-target helpers live under the std:: namespace. Like msg:: and sys::, std:: is always in scope — no import is required.

Ready-to-deploy token and vault entities, plus extra integer helpers, live in the separate Contract Standard Library (stdlib/ in cambrian-lang). Those are ordinary .cam files you import or list in project.yaml; they are not std:: names.

Bare legacy names such as min(a, b) or sha256(data) are rejected (V49). Always write the qualified form.

std::math

All functions are pure. Operand types must match unless the signature documents widening (same rules as binary arithmetic).

FunctionRole
std::math::min(a, b)Smaller of two values
std::math::max(a, b)Larger of two values
std::math::abs(x)Absolute value (signed)
std::math::clamp(x, lo, hi)Clamp to [lo, hi]
std::math::muldiv(x, y, z)(x * y) / z with a wide intermediate
std::math::muldivmod(x, y, z)Quotient and remainder, wide intermediate
std::math::divmod(x, y)(quotient, remainder)
std::math::divc(x, y)Division rounding up
std::math::divr(x, y)Division rounding to nearest
std::math::sign(x)-1, 0, or 1 (signed)
std::math::minmax(a, b)(min, max) pair
std::math::modpow2(x, n)x % 2^n (mask semantics)
std::math::pow(x, n)Exponentiation (n: u64)

Numeric types: supported integer widths (u8…u128, i8…i128, U256) where the operation is defined. Unsupported combinations fail at transpile time.

A user pure fn min(...) does not replace std::math::min — call the std symbol with the prefix.

std::str

Parsing

std::str::parse_u64(s: String, radix: u64) -> Option<u64>
std::str::parse_u8(s, radix) -> Option<u8>
std::str::parse_i64(s, radix) -> Option<i64>
std::str::parse_uint(s, radix) -> Option<u64>   // alias
std::str::parse_int(s, radix) -> Option<i64>    // alias

Parse all characters of s with radix in 2..=36. Leading 0x / 0X forces base 16 (radix must be 16 or 0). Overflow, empty string, bad digit, or bad radix yields none.

match std::str::parse_u64(s, 10) {
    some(n) => n,
    none => 0,
}

Formatting

std::str::format(fmt: String, ...) -> String

Phase-1 format specs:

SpecMeaning
{}Default display
{:w}Minimum width w
{:0w}Zero-pad to width w (for example {:06} → 000042)

Arguments may be integers or strings.

std::crypto

FunctionSignatureSemantics
std::crypto::sha256(bytes) -> [u8; 32]SHA-256 digest

Prefer std::crypto::sha256 for portable digests. On EVM-only call sites, evm::sha256 remains available for explicit platform intent — see EVM Intrinsics.

Strict typing (V50)

There is no implicit string↔number coercion in member transforms, returns, or sends:

  • String → numeric member without std::str::parse_* → V50
  • numeric expression assigned / returned as String without std::str::format → V50

Collection helpers (len, map, fold, …) stay method syntax on Vec, HashMap, and Option — they are not bare global functions.

See also