jacquard_api/sh_tangled/git/temp/
get_branch.rs1#[allow(unused_imports)]
9use alloc::collections::BTreeMap;
10
11#[allow(unused_imports)]
12use core::marker::PhantomData;
13use jacquard_common::CowStr;
14use jacquard_common::types::string::{AtUri, Datetime};
15use jacquard_derive::{IntoStatic, lexicon, open_union};
16use serde::{Serialize, Deserialize};
17use crate::sh_tangled::git::temp::Signature;
18
19#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
20#[serde(rename_all = "camelCase")]
21pub struct GetBranch<'a> {
22 #[serde(borrow)]
23 pub name: CowStr<'a>,
24 #[serde(borrow)]
25 pub repo: AtUri<'a>,
26}
27
28
29#[lexicon]
30#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
31#[serde(rename_all = "camelCase")]
32pub struct GetBranchOutput<'a> {
33 #[serde(skip_serializing_if = "Option::is_none")]
34 #[serde(borrow)]
35 pub author: Option<Signature<'a>>,
36 #[serde(borrow)]
38 pub hash: CowStr<'a>,
39 #[serde(skip_serializing_if = "Option::is_none")]
41 #[serde(borrow)]
42 pub message: Option<CowStr<'a>>,
43 #[serde(borrow)]
45 pub name: CowStr<'a>,
46 pub when: Datetime,
48}
49
50
51#[open_union]
52#[derive(
53 Serialize,
54 Deserialize,
55 Debug,
56 Clone,
57 PartialEq,
58 Eq,
59 thiserror::Error,
60 miette::Diagnostic,
61 IntoStatic
62)]
63
64#[serde(tag = "error", content = "message")]
65#[serde(bound(deserialize = "'de: 'a"))]
66pub enum GetBranchError<'a> {
67 #[serde(rename = "RepoNotFound")]
69 RepoNotFound(Option<CowStr<'a>>),
70 #[serde(rename = "BranchNotFound")]
72 BranchNotFound(Option<CowStr<'a>>),
73 #[serde(rename = "InvalidRequest")]
75 InvalidRequest(Option<CowStr<'a>>),
76}
77
78impl core::fmt::Display for GetBranchError<'_> {
79 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
80 match self {
81 Self::RepoNotFound(msg) => {
82 write!(f, "RepoNotFound")?;
83 if let Some(msg) = msg {
84 write!(f, ": {}", msg)?;
85 }
86 Ok(())
87 }
88 Self::BranchNotFound(msg) => {
89 write!(f, "BranchNotFound")?;
90 if let Some(msg) = msg {
91 write!(f, ": {}", msg)?;
92 }
93 Ok(())
94 }
95 Self::InvalidRequest(msg) => {
96 write!(f, "InvalidRequest")?;
97 if let Some(msg) = msg {
98 write!(f, ": {}", msg)?;
99 }
100 Ok(())
101 }
102 Self::Unknown(err) => write!(f, "Unknown error: {:?}", err),
103 }
104 }
105}
106
107pub struct GetBranchResponse;
109impl jacquard_common::xrpc::XrpcResp for GetBranchResponse {
110 const NSID: &'static str = "sh.tangled.git.temp.getBranch";
111 const ENCODING: &'static str = "application/json";
112 type Output<'de> = GetBranchOutput<'de>;
113 type Err<'de> = GetBranchError<'de>;
114}
115
116impl<'a> jacquard_common::xrpc::XrpcRequest for GetBranch<'a> {
117 const NSID: &'static str = "sh.tangled.git.temp.getBranch";
118 const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
119 type Response = GetBranchResponse;
120}
121
122pub struct GetBranchRequest;
124impl jacquard_common::xrpc::XrpcEndpoint for GetBranchRequest {
125 const PATH: &'static str = "/xrpc/sh.tangled.git.temp.getBranch";
126 const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
127 type Request<'de> = GetBranch<'de>;
128 type Response = GetBranchResponse;
129}
130
131pub mod get_branch_state {
132
133 pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
134 #[allow(unused)]
135 use ::core::marker::PhantomData;
136 mod sealed {
137 pub trait Sealed {}
138 }
139 pub trait State: sealed::Sealed {
141 type Repo;
142 type Name;
143 }
144 pub struct Empty(());
146 impl sealed::Sealed for Empty {}
147 impl State for Empty {
148 type Repo = Unset;
149 type Name = Unset;
150 }
151 pub struct SetRepo<S: State = Empty>(PhantomData<fn() -> S>);
153 impl<S: State> sealed::Sealed for SetRepo<S> {}
154 impl<S: State> State for SetRepo<S> {
155 type Repo = Set<members::repo>;
156 type Name = S::Name;
157 }
158 pub struct SetName<S: State = Empty>(PhantomData<fn() -> S>);
160 impl<S: State> sealed::Sealed for SetName<S> {}
161 impl<S: State> State for SetName<S> {
162 type Repo = S::Repo;
163 type Name = Set<members::name>;
164 }
165 #[allow(non_camel_case_types)]
167 pub mod members {
168 pub struct repo(());
170 pub struct name(());
172 }
173}
174
175pub struct GetBranchBuilder<'a, S: get_branch_state::State> {
177 _state: PhantomData<fn() -> S>,
178 _fields: (Option<CowStr<'a>>, Option<AtUri<'a>>),
179 _lifetime: PhantomData<&'a ()>,
180}
181
182impl<'a> GetBranch<'a> {
183 pub fn new() -> GetBranchBuilder<'a, get_branch_state::Empty> {
185 GetBranchBuilder::new()
186 }
187}
188
189impl<'a> GetBranchBuilder<'a, get_branch_state::Empty> {
190 pub fn new() -> Self {
192 GetBranchBuilder {
193 _state: PhantomData,
194 _fields: (None, None),
195 _lifetime: PhantomData,
196 }
197 }
198}
199
200impl<'a, S> GetBranchBuilder<'a, S>
201where
202 S: get_branch_state::State,
203 S::Name: get_branch_state::IsUnset,
204{
205 pub fn name(
207 mut self,
208 value: impl Into<CowStr<'a>>,
209 ) -> GetBranchBuilder<'a, get_branch_state::SetName<S>> {
210 self._fields.0 = Option::Some(value.into());
211 GetBranchBuilder {
212 _state: PhantomData,
213 _fields: self._fields,
214 _lifetime: PhantomData,
215 }
216 }
217}
218
219impl<'a, S> GetBranchBuilder<'a, S>
220where
221 S: get_branch_state::State,
222 S::Repo: get_branch_state::IsUnset,
223{
224 pub fn repo(
226 mut self,
227 value: impl Into<AtUri<'a>>,
228 ) -> GetBranchBuilder<'a, get_branch_state::SetRepo<S>> {
229 self._fields.1 = Option::Some(value.into());
230 GetBranchBuilder {
231 _state: PhantomData,
232 _fields: self._fields,
233 _lifetime: PhantomData,
234 }
235 }
236}
237
238impl<'a, S> GetBranchBuilder<'a, S>
239where
240 S: get_branch_state::State,
241 S::Repo: get_branch_state::IsSet,
242 S::Name: get_branch_state::IsSet,
243{
244 pub fn build(self) -> GetBranch<'a> {
246 GetBranch {
247 name: self._fields.0.unwrap(),
248 repo: self._fields.1.unwrap(),
249 }
250 }
251}