Skip to main content

jacquard_api/sh_tangled/git/temp/
get_diff.rs

1// @generated by jacquard-lexicon. DO NOT EDIT.
2//
3// Lexicon: sh.tangled.git.temp.getDiff
4//
5// This file was automatically generated from Lexicon schemas.
6// Any manual changes will be overwritten on the next regeneration.
7
8#[allow(unused_imports)]
9use core::marker::PhantomData;
10use jacquard_common::CowStr;
11use jacquard_common::deps::bytes::Bytes;
12use jacquard_common::types::string::AtUri;
13use jacquard_derive::{IntoStatic, open_union};
14use serde::{Serialize, Deserialize};
15
16#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
17#[serde(rename_all = "camelCase")]
18pub struct GetDiff<'a> {
19    #[serde(borrow)]
20    pub repo: AtUri<'a>,
21    #[serde(borrow)]
22    pub rev1: CowStr<'a>,
23    #[serde(borrow)]
24    pub rev2: CowStr<'a>,
25}
26
27/// Compare output in application/json
28
29#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
30#[serde(rename_all = "camelCase")]
31pub struct GetDiffOutput {
32    pub body: Bytes,
33}
34
35
36#[open_union]
37#[derive(
38    Serialize,
39    Deserialize,
40    Debug,
41    Clone,
42    PartialEq,
43    Eq,
44    thiserror::Error,
45    miette::Diagnostic,
46    IntoStatic
47)]
48
49#[serde(tag = "error", content = "message")]
50#[serde(bound(deserialize = "'de: 'a"))]
51pub enum GetDiffError<'a> {
52    /// Repository not found or access denied
53    #[serde(rename = "RepoNotFound")]
54    RepoNotFound(Option<CowStr<'a>>),
55    /// One or both revisions not found
56    #[serde(rename = "RevisionNotFound")]
57    RevisionNotFound(Option<CowStr<'a>>),
58    /// Invalid request parameters
59    #[serde(rename = "InvalidRequest")]
60    InvalidRequest(Option<CowStr<'a>>),
61    /// Failed to compare revisions
62    #[serde(rename = "CompareError")]
63    CompareError(Option<CowStr<'a>>),
64}
65
66impl core::fmt::Display for GetDiffError<'_> {
67    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
68        match self {
69            Self::RepoNotFound(msg) => {
70                write!(f, "RepoNotFound")?;
71                if let Some(msg) = msg {
72                    write!(f, ": {}", msg)?;
73                }
74                Ok(())
75            }
76            Self::RevisionNotFound(msg) => {
77                write!(f, "RevisionNotFound")?;
78                if let Some(msg) = msg {
79                    write!(f, ": {}", msg)?;
80                }
81                Ok(())
82            }
83            Self::InvalidRequest(msg) => {
84                write!(f, "InvalidRequest")?;
85                if let Some(msg) = msg {
86                    write!(f, ": {}", msg)?;
87                }
88                Ok(())
89            }
90            Self::CompareError(msg) => {
91                write!(f, "CompareError")?;
92                if let Some(msg) = msg {
93                    write!(f, ": {}", msg)?;
94                }
95                Ok(())
96            }
97            Self::Unknown(err) => write!(f, "Unknown error: {:?}", err),
98        }
99    }
100}
101
102/// Response type for sh.tangled.git.temp.getDiff
103pub struct GetDiffResponse;
104impl jacquard_common::xrpc::XrpcResp for GetDiffResponse {
105    const NSID: &'static str = "sh.tangled.git.temp.getDiff";
106    const ENCODING: &'static str = "*/*";
107    type Output<'de> = GetDiffOutput;
108    type Err<'de> = GetDiffError<'de>;
109    fn encode_output(
110        output: &Self::Output<'_>,
111    ) -> Result<Vec<u8>, jacquard_common::xrpc::EncodeError> {
112        Ok(output.body.to_vec())
113    }
114    fn decode_output<'de>(
115        body: &'de [u8],
116    ) -> Result<Self::Output<'de>, jacquard_common::error::DecodeError>
117    where
118        Self::Output<'de>: serde::Deserialize<'de>,
119    {
120        Ok(GetDiffOutput {
121            body: jacquard_common::deps::bytes::Bytes::copy_from_slice(body),
122        })
123    }
124}
125
126impl<'a> jacquard_common::xrpc::XrpcRequest for GetDiff<'a> {
127    const NSID: &'static str = "sh.tangled.git.temp.getDiff";
128    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
129    type Response = GetDiffResponse;
130}
131
132/// Endpoint type for sh.tangled.git.temp.getDiff
133pub struct GetDiffRequest;
134impl jacquard_common::xrpc::XrpcEndpoint for GetDiffRequest {
135    const PATH: &'static str = "/xrpc/sh.tangled.git.temp.getDiff";
136    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
137    type Request<'de> = GetDiff<'de>;
138    type Response = GetDiffResponse;
139}
140
141pub mod get_diff_state {
142
143    pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
144    #[allow(unused)]
145    use ::core::marker::PhantomData;
146    mod sealed {
147        pub trait Sealed {}
148    }
149    /// State trait tracking which required fields have been set
150    pub trait State: sealed::Sealed {
151        type Repo;
152        type Rev1;
153        type Rev2;
154    }
155    /// Empty state - all required fields are unset
156    pub struct Empty(());
157    impl sealed::Sealed for Empty {}
158    impl State for Empty {
159        type Repo = Unset;
160        type Rev1 = Unset;
161        type Rev2 = Unset;
162    }
163    ///State transition - sets the `repo` field to Set
164    pub struct SetRepo<S: State = Empty>(PhantomData<fn() -> S>);
165    impl<S: State> sealed::Sealed for SetRepo<S> {}
166    impl<S: State> State for SetRepo<S> {
167        type Repo = Set<members::repo>;
168        type Rev1 = S::Rev1;
169        type Rev2 = S::Rev2;
170    }
171    ///State transition - sets the `rev1` field to Set
172    pub struct SetRev1<S: State = Empty>(PhantomData<fn() -> S>);
173    impl<S: State> sealed::Sealed for SetRev1<S> {}
174    impl<S: State> State for SetRev1<S> {
175        type Repo = S::Repo;
176        type Rev1 = Set<members::rev1>;
177        type Rev2 = S::Rev2;
178    }
179    ///State transition - sets the `rev2` field to Set
180    pub struct SetRev2<S: State = Empty>(PhantomData<fn() -> S>);
181    impl<S: State> sealed::Sealed for SetRev2<S> {}
182    impl<S: State> State for SetRev2<S> {
183        type Repo = S::Repo;
184        type Rev1 = S::Rev1;
185        type Rev2 = Set<members::rev2>;
186    }
187    /// Marker types for field names
188    #[allow(non_camel_case_types)]
189    pub mod members {
190        ///Marker type for the `repo` field
191        pub struct repo(());
192        ///Marker type for the `rev1` field
193        pub struct rev1(());
194        ///Marker type for the `rev2` field
195        pub struct rev2(());
196    }
197}
198
199/// Builder for constructing an instance of this type
200pub struct GetDiffBuilder<'a, S: get_diff_state::State> {
201    _state: PhantomData<fn() -> S>,
202    _fields: (Option<AtUri<'a>>, Option<CowStr<'a>>, Option<CowStr<'a>>),
203    _lifetime: PhantomData<&'a ()>,
204}
205
206impl<'a> GetDiff<'a> {
207    /// Create a new builder for this type
208    pub fn new() -> GetDiffBuilder<'a, get_diff_state::Empty> {
209        GetDiffBuilder::new()
210    }
211}
212
213impl<'a> GetDiffBuilder<'a, get_diff_state::Empty> {
214    /// Create a new builder with all fields unset
215    pub fn new() -> Self {
216        GetDiffBuilder {
217            _state: PhantomData,
218            _fields: (None, None, None),
219            _lifetime: PhantomData,
220        }
221    }
222}
223
224impl<'a, S> GetDiffBuilder<'a, S>
225where
226    S: get_diff_state::State,
227    S::Repo: get_diff_state::IsUnset,
228{
229    /// Set the `repo` field (required)
230    pub fn repo(
231        mut self,
232        value: impl Into<AtUri<'a>>,
233    ) -> GetDiffBuilder<'a, get_diff_state::SetRepo<S>> {
234        self._fields.0 = Option::Some(value.into());
235        GetDiffBuilder {
236            _state: PhantomData,
237            _fields: self._fields,
238            _lifetime: PhantomData,
239        }
240    }
241}
242
243impl<'a, S> GetDiffBuilder<'a, S>
244where
245    S: get_diff_state::State,
246    S::Rev1: get_diff_state::IsUnset,
247{
248    /// Set the `rev1` field (required)
249    pub fn rev1(
250        mut self,
251        value: impl Into<CowStr<'a>>,
252    ) -> GetDiffBuilder<'a, get_diff_state::SetRev1<S>> {
253        self._fields.1 = Option::Some(value.into());
254        GetDiffBuilder {
255            _state: PhantomData,
256            _fields: self._fields,
257            _lifetime: PhantomData,
258        }
259    }
260}
261
262impl<'a, S> GetDiffBuilder<'a, S>
263where
264    S: get_diff_state::State,
265    S::Rev2: get_diff_state::IsUnset,
266{
267    /// Set the `rev2` field (required)
268    pub fn rev2(
269        mut self,
270        value: impl Into<CowStr<'a>>,
271    ) -> GetDiffBuilder<'a, get_diff_state::SetRev2<S>> {
272        self._fields.2 = Option::Some(value.into());
273        GetDiffBuilder {
274            _state: PhantomData,
275            _fields: self._fields,
276            _lifetime: PhantomData,
277        }
278    }
279}
280
281impl<'a, S> GetDiffBuilder<'a, S>
282where
283    S: get_diff_state::State,
284    S::Repo: get_diff_state::IsSet,
285    S::Rev1: get_diff_state::IsSet,
286    S::Rev2: get_diff_state::IsSet,
287{
288    /// Build the final struct
289    pub fn build(self) -> GetDiff<'a> {
290        GetDiff {
291            repo: self._fields.0.unwrap(),
292            rev1: self._fields.1.unwrap(),
293            rev2: self._fields.2.unwrap(),
294        }
295    }
296}