Skip to main content

wire/answer/
cost_of.rs

1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this
3// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4// Copyright (c) 2026 2youg1 and the sprawling contributors
5
6//! What one plan node has cost so far.
7//!
8//! **Absolute money and no share.** A share needs a denominator this
9//! answer does not carry - the city's own total is `CostAnswer`'s - and
10//! a percentage with no denominator is exactly what `UnplannedProgress`
11//! refuses to spell. A reader who wants a share holds both answers and
12//! divides.
13//!
14//! A node nobody ever claimed answers zero with an empty list rather
15//! than `Unavailable`: "no run has held this node" is a true answer,
16//! while "I could not look" is what `Unavailable` means.
17
18use kernel::{NodeId, RunId, UsdMicros};
19use serde::{Deserialize, Serialize};
20
21/// What one plan node cost, and which runs spent it.
22#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
23#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
24pub struct CostOfAnswer {
25    pub node: NodeId,
26    /// The sum of `runs`, so a reader draws the figure without adding
27    /// the rows up and getting a different number.
28    pub spent: UsdMicros,
29    /// One entry per run that claimed this node, in run order.
30    pub runs: Vec<(RunId, UsdMicros)>,
31}
32
33/// How many runs one `Query::RunCosts` may name: a bound on the size of
34/// one answer on the wire, not a machine reading.
35pub const RUN_COSTS_MAX: usize = 64;
36
37/// What each run a `Query::RunCosts` named was billed.
38#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
39#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
40pub struct RunCostsAnswer {
41    /// The runs the question named, echoed so a reader files the answer
42    /// under the question it asked.
43    pub asked: Vec<RunId>,
44    /// One row per run asked, in that order and cut at
45    /// [`RUN_COSTS_MAX`]. A run whose records could not be read has no
46    /// row: a missing row means "could not look", a zero "spent nothing".
47    pub runs: Vec<(RunId, UsdMicros)>,
48}