1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
// Copyright (c) 2026 2youg1 and the sprawling contributors
//! Money and quantities as integers (15.3-6), and what a piece of work
//! turned out to cost.
//! The part `crates/kernel/spec/Budget.lean` specifies this module.
//!
//! There is no ceiling here and no decision that reads one. Nobody can
//! price a piece of work before it runs, so the only brake this city has
//! is `Halt`: it shuts a scope to new work and stops the background
//! members inside it. What survives is the reporting half — `BudgetUse`
//! is a payload field of `Progress::Unplanned` and of the evidence a
//! finished run carries, which is how a person is told what was spent
//! rather than told in advance what may be.
use serde::{Deserialize, Serialize};
/// One micro-USD. Decimal price lists convert at the single accounting
/// entry point (gateway::cost); decisions never touch floats.
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct UsdMicros(u64);
/// Whole tokens.
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct Tokens(u64);
/// Whole bytes.
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
pub struct ByteLen(u64);
macro_rules! quantity {
($name:ident) => {
impl $name {
pub const fn new(value: u64) -> $name {
$name(value)
}
pub const fn get(self) -> u64 {
self.0
}
/// Overflow is `None`; the caller owns the verdict, which is
/// `E_INVALID_ARGS` at every site that has one. Choosing an
/// error story here would force it on every caller.
pub fn checked_add(self, other: $name) -> Option<$name> {
self.0.checked_add(other.0).map($name)
}
}
};
}
quantity!(UsdMicros);
quantity!(Tokens);
quantity!(ByteLen);
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct BudgetUse {
pub usd: UsdMicros,
pub tokens: Tokens,
}