Skip to main content

jacquard_api/sh_tangled/repo/
diff.rs

1// @generated by jacquard-lexicon. DO NOT EDIT.
2//
3// Lexicon: sh.tangled.repo.diff
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_derive::{IntoStatic, open_union};
13use serde::{Serialize, Deserialize};
14
15#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
16#[serde(rename_all = "camelCase")]
17pub struct Diff<'a> {
18    #[serde(borrow)]
19    pub r#ref: CowStr<'a>,
20    #[serde(borrow)]
21    pub repo: CowStr<'a>,
22}
23
24
25#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
26#[serde(rename_all = "camelCase")]
27pub struct DiffOutput {
28    pub body: Bytes,
29}
30
31
32#[open_union]
33#[derive(
34    Serialize,
35    Deserialize,
36    Debug,
37    Clone,
38    PartialEq,
39    Eq,
40    thiserror::Error,
41    miette::Diagnostic,
42    IntoStatic
43)]
44
45#[serde(tag = "error", content = "message")]
46#[serde(bound(deserialize = "'de: 'a"))]
47pub enum DiffError<'a> {
48    /// Repository not found or access denied
49    #[serde(rename = "RepoNotFound")]
50    RepoNotFound(Option<CowStr<'a>>),
51    /// Git reference not found
52    #[serde(rename = "RefNotFound")]
53    RefNotFound(Option<CowStr<'a>>),
54    /// Invalid request parameters
55    #[serde(rename = "InvalidRequest")]
56    InvalidRequest(Option<CowStr<'a>>),
57}
58
59impl core::fmt::Display for DiffError<'_> {
60    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
61        match self {
62            Self::RepoNotFound(msg) => {
63                write!(f, "RepoNotFound")?;
64                if let Some(msg) = msg {
65                    write!(f, ": {}", msg)?;
66                }
67                Ok(())
68            }
69            Self::RefNotFound(msg) => {
70                write!(f, "RefNotFound")?;
71                if let Some(msg) = msg {
72                    write!(f, ": {}", msg)?;
73                }
74                Ok(())
75            }
76            Self::InvalidRequest(msg) => {
77                write!(f, "InvalidRequest")?;
78                if let Some(msg) = msg {
79                    write!(f, ": {}", msg)?;
80                }
81                Ok(())
82            }
83            Self::Unknown(err) => write!(f, "Unknown error: {:?}", err),
84        }
85    }
86}
87
88/// Response type for sh.tangled.repo.diff
89pub struct DiffResponse;
90impl jacquard_common::xrpc::XrpcResp for DiffResponse {
91    const NSID: &'static str = "sh.tangled.repo.diff";
92    const ENCODING: &'static str = "*/*";
93    type Output<'de> = DiffOutput;
94    type Err<'de> = DiffError<'de>;
95    fn encode_output(
96        output: &Self::Output<'_>,
97    ) -> Result<Vec<u8>, jacquard_common::xrpc::EncodeError> {
98        Ok(output.body.to_vec())
99    }
100    fn decode_output<'de>(
101        body: &'de [u8],
102    ) -> Result<Self::Output<'de>, jacquard_common::error::DecodeError>
103    where
104        Self::Output<'de>: serde::Deserialize<'de>,
105    {
106        Ok(DiffOutput {
107            body: jacquard_common::deps::bytes::Bytes::copy_from_slice(body),
108        })
109    }
110}
111
112impl<'a> jacquard_common::xrpc::XrpcRequest for Diff<'a> {
113    const NSID: &'static str = "sh.tangled.repo.diff";
114    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
115    type Response = DiffResponse;
116}
117
118/// Endpoint type for sh.tangled.repo.diff
119pub struct DiffRequest;
120impl jacquard_common::xrpc::XrpcEndpoint for DiffRequest {
121    const PATH: &'static str = "/xrpc/sh.tangled.repo.diff";
122    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
123    type Request<'de> = Diff<'de>;
124    type Response = DiffResponse;
125}
126
127pub mod diff_state {
128
129    pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
130    #[allow(unused)]
131    use ::core::marker::PhantomData;
132    mod sealed {
133        pub trait Sealed {}
134    }
135    /// State trait tracking which required fields have been set
136    pub trait State: sealed::Sealed {
137        type Ref;
138        type Repo;
139    }
140    /// Empty state - all required fields are unset
141    pub struct Empty(());
142    impl sealed::Sealed for Empty {}
143    impl State for Empty {
144        type Ref = Unset;
145        type Repo = Unset;
146    }
147    ///State transition - sets the `ref` field to Set
148    pub struct SetRef<S: State = Empty>(PhantomData<fn() -> S>);
149    impl<S: State> sealed::Sealed for SetRef<S> {}
150    impl<S: State> State for SetRef<S> {
151        type Ref = Set<members::r#ref>;
152        type Repo = S::Repo;
153    }
154    ///State transition - sets the `repo` field to Set
155    pub struct SetRepo<S: State = Empty>(PhantomData<fn() -> S>);
156    impl<S: State> sealed::Sealed for SetRepo<S> {}
157    impl<S: State> State for SetRepo<S> {
158        type Ref = S::Ref;
159        type Repo = Set<members::repo>;
160    }
161    /// Marker types for field names
162    #[allow(non_camel_case_types)]
163    pub mod members {
164        ///Marker type for the `ref` field
165        pub struct r#ref(());
166        ///Marker type for the `repo` field
167        pub struct repo(());
168    }
169}
170
171/// Builder for constructing an instance of this type
172pub struct DiffBuilder<'a, S: diff_state::State> {
173    _state: PhantomData<fn() -> S>,
174    _fields: (Option<CowStr<'a>>, Option<CowStr<'a>>),
175    _lifetime: PhantomData<&'a ()>,
176}
177
178impl<'a> Diff<'a> {
179    /// Create a new builder for this type
180    pub fn new() -> DiffBuilder<'a, diff_state::Empty> {
181        DiffBuilder::new()
182    }
183}
184
185impl<'a> DiffBuilder<'a, diff_state::Empty> {
186    /// Create a new builder with all fields unset
187    pub fn new() -> Self {
188        DiffBuilder {
189            _state: PhantomData,
190            _fields: (None, None),
191            _lifetime: PhantomData,
192        }
193    }
194}
195
196impl<'a, S> DiffBuilder<'a, S>
197where
198    S: diff_state::State,
199    S::Ref: diff_state::IsUnset,
200{
201    /// Set the `ref` field (required)
202    pub fn r#ref(
203        mut self,
204        value: impl Into<CowStr<'a>>,
205    ) -> DiffBuilder<'a, diff_state::SetRef<S>> {
206        self._fields.0 = Option::Some(value.into());
207        DiffBuilder {
208            _state: PhantomData,
209            _fields: self._fields,
210            _lifetime: PhantomData,
211        }
212    }
213}
214
215impl<'a, S> DiffBuilder<'a, S>
216where
217    S: diff_state::State,
218    S::Repo: diff_state::IsUnset,
219{
220    /// Set the `repo` field (required)
221    pub fn repo(
222        mut self,
223        value: impl Into<CowStr<'a>>,
224    ) -> DiffBuilder<'a, diff_state::SetRepo<S>> {
225        self._fields.1 = Option::Some(value.into());
226        DiffBuilder {
227            _state: PhantomData,
228            _fields: self._fields,
229            _lifetime: PhantomData,
230        }
231    }
232}
233
234impl<'a, S> DiffBuilder<'a, S>
235where
236    S: diff_state::State,
237    S::Ref: diff_state::IsSet,
238    S::Repo: diff_state::IsSet,
239{
240    /// Build the final struct
241    pub fn build(self) -> Diff<'a> {
242        Diff {
243            r#ref: self._fields.0.unwrap(),
244            repo: self._fields.1.unwrap(),
245        }
246    }
247}