Skip to main content

jacquard_api/sh_tangled/git/temp/
get_head.rs

1// @generated by jacquard-lexicon. DO NOT EDIT.
2//
3// Lexicon: sh.tangled.git.temp.getHead
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::types::string::AtUri;
12use jacquard_derive::{IntoStatic, open_union};
13use serde::{Serialize, Deserialize};
14use crate::sh_tangled::git::temp::Branch;
15
16#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
17#[serde(rename_all = "camelCase")]
18pub struct GetHead<'a> {
19    #[serde(borrow)]
20    pub repo: AtUri<'a>,
21}
22
23
24#[jacquard_derive::lexicon]
25#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
26#[serde(rename_all = "camelCase")]
27pub struct GetHeadOutput<'a> {
28    #[serde(flatten)]
29    #[serde(borrow)]
30    pub value: Branch<'a>,
31}
32
33
34#[open_union]
35#[derive(
36    Serialize,
37    Deserialize,
38    Debug,
39    Clone,
40    PartialEq,
41    Eq,
42    thiserror::Error,
43    miette::Diagnostic,
44    IntoStatic
45)]
46
47#[serde(tag = "error", content = "message")]
48#[serde(bound(deserialize = "'de: 'a"))]
49pub enum GetHeadError<'a> {
50    /// Repository not found or access denied
51    #[serde(rename = "RepoNotFound")]
52    RepoNotFound(Option<CowStr<'a>>),
53    /// Invalid request parameters
54    #[serde(rename = "InvalidRequest")]
55    InvalidRequest(Option<CowStr<'a>>),
56}
57
58impl core::fmt::Display for GetHeadError<'_> {
59    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
60        match self {
61            Self::RepoNotFound(msg) => {
62                write!(f, "RepoNotFound")?;
63                if let Some(msg) = msg {
64                    write!(f, ": {}", msg)?;
65                }
66                Ok(())
67            }
68            Self::InvalidRequest(msg) => {
69                write!(f, "InvalidRequest")?;
70                if let Some(msg) = msg {
71                    write!(f, ": {}", msg)?;
72                }
73                Ok(())
74            }
75            Self::Unknown(err) => write!(f, "Unknown error: {:?}", err),
76        }
77    }
78}
79
80/// Response type for sh.tangled.git.temp.getHead
81pub struct GetHeadResponse;
82impl jacquard_common::xrpc::XrpcResp for GetHeadResponse {
83    const NSID: &'static str = "sh.tangled.git.temp.getHead";
84    const ENCODING: &'static str = "application/json";
85    type Output<'de> = GetHeadOutput<'de>;
86    type Err<'de> = GetHeadError<'de>;
87}
88
89impl<'a> jacquard_common::xrpc::XrpcRequest for GetHead<'a> {
90    const NSID: &'static str = "sh.tangled.git.temp.getHead";
91    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
92    type Response = GetHeadResponse;
93}
94
95/// Endpoint type for sh.tangled.git.temp.getHead
96pub struct GetHeadRequest;
97impl jacquard_common::xrpc::XrpcEndpoint for GetHeadRequest {
98    const PATH: &'static str = "/xrpc/sh.tangled.git.temp.getHead";
99    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
100    type Request<'de> = GetHead<'de>;
101    type Response = GetHeadResponse;
102}
103
104pub mod get_head_state {
105
106    pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
107    #[allow(unused)]
108    use ::core::marker::PhantomData;
109    mod sealed {
110        pub trait Sealed {}
111    }
112    /// State trait tracking which required fields have been set
113    pub trait State: sealed::Sealed {
114        type Repo;
115    }
116    /// Empty state - all required fields are unset
117    pub struct Empty(());
118    impl sealed::Sealed for Empty {}
119    impl State for Empty {
120        type Repo = Unset;
121    }
122    ///State transition - sets the `repo` field to Set
123    pub struct SetRepo<S: State = Empty>(PhantomData<fn() -> S>);
124    impl<S: State> sealed::Sealed for SetRepo<S> {}
125    impl<S: State> State for SetRepo<S> {
126        type Repo = Set<members::repo>;
127    }
128    /// Marker types for field names
129    #[allow(non_camel_case_types)]
130    pub mod members {
131        ///Marker type for the `repo` field
132        pub struct repo(());
133    }
134}
135
136/// Builder for constructing an instance of this type
137pub struct GetHeadBuilder<'a, S: get_head_state::State> {
138    _state: PhantomData<fn() -> S>,
139    _fields: (Option<AtUri<'a>>,),
140    _lifetime: PhantomData<&'a ()>,
141}
142
143impl<'a> GetHead<'a> {
144    /// Create a new builder for this type
145    pub fn new() -> GetHeadBuilder<'a, get_head_state::Empty> {
146        GetHeadBuilder::new()
147    }
148}
149
150impl<'a> GetHeadBuilder<'a, get_head_state::Empty> {
151    /// Create a new builder with all fields unset
152    pub fn new() -> Self {
153        GetHeadBuilder {
154            _state: PhantomData,
155            _fields: (None,),
156            _lifetime: PhantomData,
157        }
158    }
159}
160
161impl<'a, S> GetHeadBuilder<'a, S>
162where
163    S: get_head_state::State,
164    S::Repo: get_head_state::IsUnset,
165{
166    /// Set the `repo` field (required)
167    pub fn repo(
168        mut self,
169        value: impl Into<AtUri<'a>>,
170    ) -> GetHeadBuilder<'a, get_head_state::SetRepo<S>> {
171        self._fields.0 = Option::Some(value.into());
172        GetHeadBuilder {
173            _state: PhantomData,
174            _fields: self._fields,
175            _lifetime: PhantomData,
176        }
177    }
178}
179
180impl<'a, S> GetHeadBuilder<'a, S>
181where
182    S: get_head_state::State,
183    S::Repo: get_head_state::IsSet,
184{
185    /// Build the final struct
186    pub fn build(self) -> GetHead<'a> {
187        GetHead {
188            repo: self._fields.0.unwrap(),
189        }
190    }
191}