Skip to main content

wire/answer/
find.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//! The files under one address whose name holds a text
7//! (`crates/wire/spec/Answer/Find.lean` ยง8-82).
8//!
9//! A page that wants one name cannot ask `Listing` level by level: a
10//! deep tree is dozens of round trips before it can say "none", and a
11//! directory the page never asked is one it cannot speak for. The city
12//! walks the tree once and says whether that walk reached the end.
13
14use kernel::Address;
15use serde::{Deserialize, Serialize};
16
17/// How many files one answer lists: a bound on the answer's size on
18/// the wire, and as many as a list a person picks one file from needs.
19pub const FIND_MAX: usize = 50;
20
21/// How many entries one walk looks at before it stops: the cost of one
22/// question, paid on every key the person types.
23pub const FIND_WALK_MAX: usize = 20_000;
24
25/// Whether the walk looked at everything under the address.
26#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
27#[serde(rename_all = "snake_case")]
28#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
29pub enum Walked {
30    /// Every entry was looked at: a file not listed has no such name.
31    Whole,
32    /// The walk stopped at [`FIND_MAX`] files or [`FIND_WALK_MAX`]
33    /// entries with the tree not finished, so more may match.
34    Cut,
35}
36
37/// The files found, shallow first and in name order within one level,
38/// each relative to `under`. `under` and `text` echo the question,
39/// which the wire carries no id for.
40#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
41#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
42pub struct FindAnswer {
43    pub under: Address,
44    pub text: String,
45    pub paths: Vec<Address>,
46    pub walked: Walked,
47}