Skip to main content

onetaskgraph_plugin_api/
visibility.rs

1//! What a source's backend really is: who can read what is written there.
2
3use schemars::JsonSchema;
4use serde::{Deserialize, Serialize};
5
6use crate::{NativeId, Repository};
7
8/// Who can read a destination, as its backend reports it on a live read.
9///
10/// Only [`Public`](Self::Public) is public. [`Unknown`](Self::Unknown) is the answer of a
11/// source that cannot say — a stdio plugin, whose protocol has no such read — and a
12/// destination answering it is never treated as private: an item that may only be written
13/// somewhere private is refused there.
14#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
15#[serde(rename_all = "kebab-case")]
16pub enum Visibility {
17    /// Anybody can read it.
18    Public,
19    /// Only those its backend admits can read it.
20    Private,
21    /// The source cannot say.
22    Unknown,
23}
24
25impl Visibility {
26    /// The value as the wire spells it.
27    #[must_use]
28    pub const fn as_str(self) -> &'static str {
29        match self {
30            Self::Public => "public",
31            Self::Private => "private",
32            Self::Unknown => "unknown",
33        }
34    }
35}
36
37impl std::fmt::Display for Visibility {
38    fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
39        formatter.write_str(self.as_str())
40    }
41}
42
43/// The item a write is about to reach, so a source can say who can read where it lands.
44///
45/// A backend may keep different items in places of different visibility — a GitHub board
46/// creates each issue in a repository decided per item, and keeps an existing issue where
47/// it is — so [`TaskSource::visibility`](crate::TaskSource::visibility) is asked about the
48/// item rather than about the source as a whole.
49#[derive(Debug, Clone, Copy, PartialEq, Eq)]
50pub enum WriteTarget<'a> {
51    /// An item the write creates.
52    New {
53        /// The repositories it names.
54        repositories: &'a [Repository],
55        /// The project it is filed under in this source, when it is filed under one.
56        project: Option<&'a NativeId>,
57    },
58    /// An item this source already holds.
59    Existing(&'a NativeId),
60}