Skip to main content

jacquard_api/com_atproto/sync/
get_record.rs

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