git_bug/entities/issue/
mod.rs

1// git-bug-rs - A rust library for interfacing with git-bug repositories
2//
3// Copyright (C) 2025 Benedikt Peetz <benedikt.peetz@b-peetz.de>
4// SPDX-License-Identifier: GPL-3.0-or-later
5//
6// This file is part of git-bug-rs/git-gub.
7//
8// You should have received a copy of the License along with this program.
9// If not, see <https://www.gnu.org/licenses/agpl.txt>.
10
11//! Handling of the actual issues.
12//!
13//! # Note
14//! Git-bug calls these `Bugs`.
15//! See the documentation at the crate root for an explanation on this name
16//! difference.
17
18use serde::{Deserialize, Serialize};
19
20use self::{
21    issue_operation::IssueOperationData,
22    snapshot::{history_step::IssueHistoryStep, timeline::IssueTimeline},
23};
24use crate::replica::entity::{self, Entity, EntityRead, operation::operations::Operations};
25
26pub mod data;
27pub mod issue_operation;
28pub mod query;
29pub mod snapshot;
30
31/// The representation of an issue in it's DAG form.
32/// This means that this issue can be modified (i.e., operations added) and than
33/// re-commited to disk.
34#[derive(Debug, Serialize, Deserialize)]
35pub struct Issue {
36    operations: Operations<Self>,
37    create_time: entity::lamport::Time,
38    edit_time: entity::lamport::Time,
39    current_head: gix::ObjectId,
40}
41
42impl Entity for Issue {
43    type HistoryStep = IssueHistoryStep;
44    type OperationData = IssueOperationData;
45    type Timeline = IssueTimeline;
46
47    const FORMAT_VERSION: usize = 4;
48    const NAMESPACE: &str = "bugs";
49    const TYPENAME: &str = "Issue";
50
51    fn operations(&self) -> &Operations<Self>
52    where
53        Self: Sized,
54    {
55        &self.operations
56    }
57
58    unsafe fn from_parts(
59        operations: Operations<Self>,
60        create_time: entity::lamport::Time,
61        edit_time: entity::lamport::Time,
62        current_head: gix::ObjectId,
63    ) -> Self {
64        Self {
65            operations,
66            create_time,
67            edit_time,
68            current_head,
69        }
70    }
71
72    fn create_time(&self) -> &entity::lamport::Time
73    where
74        Self: Sized,
75    {
76        &self.create_time
77    }
78
79    fn edit_time(&self) -> &entity::lamport::Time
80    where
81        Self: Sized,
82    {
83        &self.edit_time
84    }
85
86    fn current_head(&self) -> &gix::oid
87    where
88        Self: Sized,
89    {
90        &self.current_head
91    }
92}
93
94impl EntityRead for Issue {
95    // TODO(@bpeetz): Ideally, this would be the default. But alas, defaults for
96    // associated types are not yet stable. <2025-04-21>
97    type CustomReadError = std::convert::Infallible;
98}