jacquard_api/sh_tangled/git/temp/
get_blob.rs1#[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 GetBlob<'a> {
19 #[serde(borrow)]
20 pub path: CowStr<'a>,
21 #[serde(default = "_default_ref")]
23 #[serde(skip_serializing_if = "Option::is_none")]
24 #[serde(borrow)]
25 pub r#ref: Option<CowStr<'a>>,
26 #[serde(borrow)]
27 pub repo: AtUri<'a>,
28}
29
30#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
33#[serde(rename_all = "camelCase")]
34pub struct GetBlobOutput {
35 pub body: Bytes,
36}
37
38
39#[open_union]
40#[derive(
41 Serialize,
42 Deserialize,
43 Debug,
44 Clone,
45 PartialEq,
46 Eq,
47 thiserror::Error,
48 miette::Diagnostic,
49 IntoStatic
50)]
51
52#[serde(tag = "error", content = "message")]
53#[serde(bound(deserialize = "'de: 'a"))]
54pub enum GetBlobError<'a> {
55 #[serde(rename = "RepoNotFound")]
57 RepoNotFound(Option<CowStr<'a>>),
58 #[serde(rename = "BlobNotFound")]
60 BlobNotFound(Option<CowStr<'a>>),
61 #[serde(rename = "InvalidRequest")]
63 InvalidRequest(Option<CowStr<'a>>),
64}
65
66impl core::fmt::Display for GetBlobError<'_> {
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::BlobNotFound(msg) => {
77 write!(f, "BlobNotFound")?;
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::Unknown(err) => write!(f, "Unknown error: {:?}", err),
91 }
92 }
93}
94
95pub struct GetBlobResponse;
97impl jacquard_common::xrpc::XrpcResp for GetBlobResponse {
98 const NSID: &'static str = "sh.tangled.git.temp.getBlob";
99 const ENCODING: &'static str = "*/*";
100 type Output<'de> = GetBlobOutput;
101 type Err<'de> = GetBlobError<'de>;
102 fn encode_output(
103 output: &Self::Output<'_>,
104 ) -> Result<Vec<u8>, jacquard_common::xrpc::EncodeError> {
105 Ok(output.body.to_vec())
106 }
107 fn decode_output<'de>(
108 body: &'de [u8],
109 ) -> Result<Self::Output<'de>, jacquard_common::error::DecodeError>
110 where
111 Self::Output<'de>: serde::Deserialize<'de>,
112 {
113 Ok(GetBlobOutput {
114 body: jacquard_common::deps::bytes::Bytes::copy_from_slice(body),
115 })
116 }
117}
118
119impl<'a> jacquard_common::xrpc::XrpcRequest for GetBlob<'a> {
120 const NSID: &'static str = "sh.tangled.git.temp.getBlob";
121 const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
122 type Response = GetBlobResponse;
123}
124
125pub struct GetBlobRequest;
127impl jacquard_common::xrpc::XrpcEndpoint for GetBlobRequest {
128 const PATH: &'static str = "/xrpc/sh.tangled.git.temp.getBlob";
129 const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
130 type Request<'de> = GetBlob<'de>;
131 type Response = GetBlobResponse;
132}
133
134fn _default_ref() -> Option<CowStr<'static>> {
135 Some(CowStr::from("HEAD"))
136}
137
138pub mod get_blob_state {
139
140 pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
141 #[allow(unused)]
142 use ::core::marker::PhantomData;
143 mod sealed {
144 pub trait Sealed {}
145 }
146 pub trait State: sealed::Sealed {
148 type Repo;
149 type Path;
150 }
151 pub struct Empty(());
153 impl sealed::Sealed for Empty {}
154 impl State for Empty {
155 type Repo = Unset;
156 type Path = Unset;
157 }
158 pub struct SetRepo<S: State = Empty>(PhantomData<fn() -> S>);
160 impl<S: State> sealed::Sealed for SetRepo<S> {}
161 impl<S: State> State for SetRepo<S> {
162 type Repo = Set<members::repo>;
163 type Path = S::Path;
164 }
165 pub struct SetPath<S: State = Empty>(PhantomData<fn() -> S>);
167 impl<S: State> sealed::Sealed for SetPath<S> {}
168 impl<S: State> State for SetPath<S> {
169 type Repo = S::Repo;
170 type Path = Set<members::path>;
171 }
172 #[allow(non_camel_case_types)]
174 pub mod members {
175 pub struct repo(());
177 pub struct path(());
179 }
180}
181
182pub struct GetBlobBuilder<'a, S: get_blob_state::State> {
184 _state: PhantomData<fn() -> S>,
185 _fields: (Option<CowStr<'a>>, Option<CowStr<'a>>, Option<AtUri<'a>>),
186 _lifetime: PhantomData<&'a ()>,
187}
188
189impl<'a> GetBlob<'a> {
190 pub fn new() -> GetBlobBuilder<'a, get_blob_state::Empty> {
192 GetBlobBuilder::new()
193 }
194}
195
196impl<'a> GetBlobBuilder<'a, get_blob_state::Empty> {
197 pub fn new() -> Self {
199 GetBlobBuilder {
200 _state: PhantomData,
201 _fields: (None, None, None),
202 _lifetime: PhantomData,
203 }
204 }
205}
206
207impl<'a, S> GetBlobBuilder<'a, S>
208where
209 S: get_blob_state::State,
210 S::Path: get_blob_state::IsUnset,
211{
212 pub fn path(
214 mut self,
215 value: impl Into<CowStr<'a>>,
216 ) -> GetBlobBuilder<'a, get_blob_state::SetPath<S>> {
217 self._fields.0 = Option::Some(value.into());
218 GetBlobBuilder {
219 _state: PhantomData,
220 _fields: self._fields,
221 _lifetime: PhantomData,
222 }
223 }
224}
225
226impl<'a, S: get_blob_state::State> GetBlobBuilder<'a, S> {
227 pub fn r#ref(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
229 self._fields.1 = value.into();
230 self
231 }
232 pub fn maybe_ref(mut self, value: Option<CowStr<'a>>) -> Self {
234 self._fields.1 = value;
235 self
236 }
237}
238
239impl<'a, S> GetBlobBuilder<'a, S>
240where
241 S: get_blob_state::State,
242 S::Repo: get_blob_state::IsUnset,
243{
244 pub fn repo(
246 mut self,
247 value: impl Into<AtUri<'a>>,
248 ) -> GetBlobBuilder<'a, get_blob_state::SetRepo<S>> {
249 self._fields.2 = Option::Some(value.into());
250 GetBlobBuilder {
251 _state: PhantomData,
252 _fields: self._fields,
253 _lifetime: PhantomData,
254 }
255 }
256}
257
258impl<'a, S> GetBlobBuilder<'a, S>
259where
260 S: get_blob_state::State,
261 S::Repo: get_blob_state::IsSet,
262 S::Path: get_blob_state::IsSet,
263{
264 pub fn build(self) -> GetBlob<'a> {
266 GetBlob {
267 path: self._fields.0.unwrap(),
268 r#ref: self._fields.1,
269 repo: self._fields.2.unwrap(),
270 }
271 }
272}