wire/answer/listing.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//! One directory of the city, as a page walks the tree.
7//!
8//! The tree is the product: a building is a directory, a room is a
9//! directory inside it, and what a resident wrote lives beside the
10//! transcript of the run that wrote it. `BuildingView` answers with the
11//! documents at a building's root and the names of its rooms, and
12//! nothing on the wire could open a room - so the one design the
13//! interface exists to show was the one thing it could not draw.
14//!
15//! One level per question. A page opens directories as a person does,
16//! and an answer that carried the whole subtree would pay for the
17//! ledger segments and the content store every time somebody looked at
18//! a room.
19
20use kernel::Address;
21use serde::{Deserialize, Serialize};
22
23/// What one entry is. A directory has no size worth stating: the size
24/// of a directory is a question about everything under it, and this
25/// answer deliberately does not walk that far.
26#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
27#[serde(rename_all = "snake_case")]
28#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
29pub enum EntryKind {
30 Directory,
31 File { bytes: u64 },
32}
33
34/// One name inside a directory.
35#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
36#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
37pub struct Entry {
38 pub name: String,
39 pub kind: EntryKind,
40}
41
42/// One directory, one level deep: directories first, then files, each
43/// group in name order, so a tree drawn from it reads the same way on
44/// every machine.
45#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
46#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
47pub struct ListingAnswer {
48 /// The directory listed; `None` is the city root.
49 pub at: Option<Address>,
50 pub entries: Vec<Entry>,
51}