Skip to main content

kernel/event/record/
discard.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 a building let go of: files a settlement found deleted, the
7//! restoration of those files, and entries a run filed on the shelf.
8
9use serde::{Deserialize, Deserializer, Serialize};
10
11use crate::discard::Restoration;
12
13/// `file_discarded`: the paths one sweep found deleted, and the way back.
14///
15/// `paths` stay the strings the writer spelled (`file:<path>`) rather
16/// than [`Address`](crate::Address)es, because git keeps names an
17/// address refuses and a discard of such a file is still a discard.
18#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
19#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
20pub struct FileDiscarded {
21    pub paths: Vec<String>,
22    /// Absent, or spelled in a scheme this build cannot name, reads as
23    /// `None` and the paths still read: a row without its way back is
24    /// still a file that is gone.
25    #[serde(
26        default,
27        deserialize_with = "restoration_if_named",
28        skip_serializing_if = "Option::is_none"
29    )]
30    pub restoration: Option<Restoration>,
31}
32
33/// `discard_restored`: the paths a restoration put back.
34#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
35#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
36pub struct DiscardRestored {
37    pub paths: Vec<String>,
38}
39
40/// `asset_archived`: one entry a run filed in its building's archive.
41#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
42#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
43pub struct AssetArchived {
44    /// The archive kind's word. A record that names none is a fact,
45    /// the kind an unmarked entry has always been shown as.
46    #[serde(default = "fact")]
47    pub kind: String,
48    /// The day the entry was filed, as the archive counts days.
49    #[serde(default)]
50    pub day: u64,
51    #[serde(default)]
52    pub subject: String,
53}
54
55fn fact() -> String {
56    "fact".to_owned()
57}
58
59fn restoration_if_named<'de, D: Deserializer<'de>>(
60    deserializer: D,
61) -> Result<Option<Restoration>, D::Error> {
62    let raw = serde_json::Value::deserialize(deserializer)?;
63    Ok(serde_json::from_value(raw).ok())
64}
65
66#[cfg(test)]
67#[allow(clippy::unwrap_used, clippy::expect_used, reason = "test code")]
68mod tests;