flow-abi 0.1.0-rc.5

The host boundary's value encoding: the binary encoding and the JSON form, the canonical form and its hash, JSON Schemas, Tool signatures, and the answers a Tool call passes.
Documentation
//! The limits a decoded value is held to (`execution.md`, *Limits*).

/// How large a decoded value may be.
///
/// Every host decodes within [`Limits::LANGUAGE`]; other values exist only
/// so that tests can reach a limit with a small value.
///
/// A value past any of these does not decode, like any other value that does
/// not match its type: in a Tool reply that is no answer, so the call stays
/// open and the run stops, never a fault (`abi.md`, *Decoding*).
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub struct Limits {
    /// How deeply the decoded value may nest: a scalar is 0 deep, and a
    /// list, set, dictionary, tuple, record or enum value one deeper than its
    /// deepest part, as the evaluator counts.
    pub depth: usize,
    /// How many bits an `Int` may take, sign excluded, and so the integer
    /// any number's significant digits make, which bounds a `Decimal`'s
    /// coefficient.
    pub int_bits: u64,
    /// How many bytes one `Text` or `Bytes` may hold, how many digits a
    /// number may take written in plain decimal notation, and how many
    /// elements written in no bytes, such as `Unit`s, one binary value may
    /// hold in all its collections together.
    pub text_bytes: usize,
}

impl Limits {
    /// The language's limits, which every conforming implementation holds a
    /// program to exactly: no host raises or lowers them.
    pub const LANGUAGE: Limits = Limits {
        depth: 256,
        int_bits: 4096,
        text_bytes: 16 * 1024 * 1024,
    };

    /// No limit at all: for bytes this implementation wrote itself, such as
    /// a value already held, or type metadata, whose nesting no program
    /// value's limit bounds.
    pub const UNBOUNDED: Limits = Limits {
        depth: usize::MAX,
        int_bits: u64::MAX,
        text_bytes: usize::MAX,
    };

    /// The reply limit: the most bytes one Tool reply may take.
    pub const REPLY_BYTES: usize = 16 * 1024 * 1024;

    /// How deeply JSON arrays and objects may nest before decoding refuses
    /// the text unread.
    ///
    /// A JSON level makes at least half a level of value — an enum with a
    /// named payload is two objects around one value — so text nested deeper
    /// than this could not decode within [`Limits::depth`] in any case.
    pub(crate) fn json_depth(&self) -> usize {
        self.depth.saturating_mul(2).saturating_add(1)
    }
}

impl Default for Limits {
    fn default() -> Self {
        Limits::LANGUAGE
    }
}