1use serde::{Deserialize, Serialize};
15
16macro_rules! opaque_id {
17 ($name:ident, $doc:literal) => {
18 #[doc = $doc]
19 #[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
20 #[serde(transparent)]
21 pub struct $name(String);
22
23 impl $name {
24 pub fn as_str(&self) -> &str {
26 &self.0
27 }
28 }
29
30 impl std::fmt::Display for $name {
31 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
32 f.write_str(&self.0)
33 }
34 }
35
36 impl From<String> for $name {
37 fn from(value: String) -> Self {
38 $name(value)
39 }
40 }
41
42 impl From<&str> for $name {
43 fn from(value: &str) -> Self {
44 $name(value.to_string())
45 }
46 }
47
48 impl AsRef<str> for $name {
49 fn as_ref(&self) -> &str {
50 &self.0
51 }
52 }
53 };
54}
55
56opaque_id!(
57 RepoId,
58 "Opaque `\"group/project\"` repo identity (protocol: the UI never\n\
59 parses it; each backend owns its grammar)."
60);
61
62opaque_id!(
63 Sha,
64 "Opaque content id: MUST change when content changes (the cache\n\
65 is content-keyed and immutable). A commit sha on backends that\n\
66 have them; whatever the adapter guarantees otherwise."
67);
68
69opaque_id!(
70 GitRef,
71 "A resolvable revision name — branch, tag, or commit sha — as the\n\
72 backend interprets it (`repo/tree`'s `ref` param). `None` at a\n\
73 call site means the default branch; this type never encodes it."
74);
75
76opaque_id!(
77 RepoPath,
78 "An opaque repository-relative path, not a host filesystem path."
79);
80opaque_id!(
81 OrgId,
82 "An opaque organization or group identity, independent of its displayed caption."
83);
84opaque_id!(
85 OwnerId,
86 "An opaque repository namespace; it does not imply a personal account or organization."
87);
88
89impl Sha {
90 pub fn short(&self) -> String {
91 self.as_str().chars().take(7).collect()
92 }
93}