Sign in

    moonrockz/gleam-parser/fuel does not have a README file

    FuelExhausted

    pub(all) suberror FuelExhausted {
    FuelExhausted(budget~ : Budget, spent~ : Array[Spent])
    } derive(Eq,
    Debug
    )

    The budget ran out: spent is the stack at that moment, outermost first.

    Budget

    pub struct Budget(Int) derive(Compare, Eq,
    Debug
    )

    Units of fuel, at least 1.

    test {
    debug_inspect(@fuel.Budget::new(100).map(b => b.units()), content="Some(100)")
    debug_inspect(@fuel.Budget::new(0), content="None")
    }

    Budget::new

    fn Budget::new(units : Int) -> Budget?

    A budget of units; None below 1.

    Budget::units

    fn Budget::units(self : Budget) -> Int

    The number of units.

    Fuel

    pub struct Fuel {
    budget : Budget
    left : Int
    ops :
    List
    [Operation]
    } derive(Eq,
    Debug
    )

    An immutable fuel value: the budget, the units not yet spent, and the operations on the stack (innermost first). spend gives a new value; there is no restore: the enclosing operation keeps its own Fuel.

    test {
    let f = @fuel.Fuel::new(budget=@fuel.Budget::new(2).unwrap())
    let inner = f.spend(@fuel.Operation::new("expression"))
    inspect(inner.left(), content="1")
    inspect(f.left(), content="2")
    }

    Fuel::budget

    fn Fuel::budget(self : Fuel) -> Budget

    The budget this fuel started with.

    Fuel::left

    fn Fuel::left(self : Fuel) -> Int

    The units not yet spent.

    Fuel::new

    fn Fuel::new(budget? : Budget) -> Fuel

    A full budget (default_budget when none is given).

    Fuel::spend

    fn Fuel::spend(self : Fuel, op : Operation) -> Fuel raise FuelExhausted

    Enter a nested operation: one unit less, op on the stack. Raises FuelExhausted with the budget and the stack when no unit is left.

    Fuel::spent

    fn Fuel::spent(self : Fuel) -> Array[Spent]

    The distinct operations on the stack, outermost first, each with the number of levels it holds.

    Operation

    pub struct Operation(String) derive(Eq, Hash,
    Debug
    )

    The name of a fuel-checked operation (expression, pattern, ...). Each package that spends fuel defines its operations as constants.

    Operation::name

    fn Operation::name(self : Operation) -> String

    The operation's name.

    Operation::new

    fn Operation::new(name : String) -> Operation

    An operation with this name; the name appears in FuelExhausted.

    Spent

    pub(all) struct Spent {
    operation : Operation
    levels : Int
    } derive(Eq,
    Debug
    )

    One operation on the stack with the number of nested levels it holds.

    default_budget

    let default_budget : Budget

    The default budget, 100 units: measured safe on wasm, the smallest stack (it overflows at about 140 nested lists). Raise it only on native or js.

    Source Files

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io