Skip to main content

jacquard_api/com_atproto/sync/
get_latest_commit.rs

1// @generated by jacquard-lexicon. DO NOT EDIT.
2//
3// Lexicon: com.atproto.sync.getLatestCommit
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 alloc::collections::BTreeMap;
10
11#[allow(unused_imports)]
12use core::marker::PhantomData;
13use jacquard_common::CowStr;
14use jacquard_common::types::string::{Did, Tid, Cid};
15use jacquard_derive::{IntoStatic, lexicon, open_union};
16use serde::{Serialize, Deserialize};
17
18#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
19#[serde(rename_all = "camelCase")]
20pub struct GetLatestCommit<'a> {
21    #[serde(borrow)]
22    pub did: Did<'a>,
23}
24
25
26#[lexicon]
27#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
28#[serde(rename_all = "camelCase")]
29pub struct GetLatestCommitOutput<'a> {
30    #[serde(borrow)]
31    pub cid: Cid<'a>,
32    pub rev: Tid,
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 GetLatestCommitError<'a> {
52    #[serde(rename = "RepoNotFound")]
53    RepoNotFound(Option<CowStr<'a>>),
54    #[serde(rename = "RepoTakendown")]
55    RepoTakendown(Option<CowStr<'a>>),
56    #[serde(rename = "RepoSuspended")]
57    RepoSuspended(Option<CowStr<'a>>),
58    #[serde(rename = "RepoDeactivated")]
59    RepoDeactivated(Option<CowStr<'a>>),
60}
61
62impl core::fmt::Display for GetLatestCommitError<'_> {
63    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
64        match self {
65            Self::RepoNotFound(msg) => {
66                write!(f, "RepoNotFound")?;
67                if let Some(msg) = msg {
68                    write!(f, ": {}", msg)?;
69                }
70                Ok(())
71            }
72            Self::RepoTakendown(msg) => {
73                write!(f, "RepoTakendown")?;
74                if let Some(msg) = msg {
75                    write!(f, ": {}", msg)?;
76                }
77                Ok(())
78            }
79            Self::RepoSuspended(msg) => {
80                write!(f, "RepoSuspended")?;
81                if let Some(msg) = msg {
82                    write!(f, ": {}", msg)?;
83                }
84                Ok(())
85            }
86            Self::RepoDeactivated(msg) => {
87                write!(f, "RepoDeactivated")?;
88                if let Some(msg) = msg {
89                    write!(f, ": {}", msg)?;
90                }
91                Ok(())
92            }
93            Self::Unknown(err) => write!(f, "Unknown error: {:?}", err),
94        }
95    }
96}
97
98/// Response type for com.atproto.sync.getLatestCommit
99pub struct GetLatestCommitResponse;
100impl jacquard_common::xrpc::XrpcResp for GetLatestCommitResponse {
101    const NSID: &'static str = "com.atproto.sync.getLatestCommit";
102    const ENCODING: &'static str = "application/json";
103    type Output<'de> = GetLatestCommitOutput<'de>;
104    type Err<'de> = GetLatestCommitError<'de>;
105}
106
107impl<'a> jacquard_common::xrpc::XrpcRequest for GetLatestCommit<'a> {
108    const NSID: &'static str = "com.atproto.sync.getLatestCommit";
109    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
110    type Response = GetLatestCommitResponse;
111}
112
113/// Endpoint type for com.atproto.sync.getLatestCommit
114pub struct GetLatestCommitRequest;
115impl jacquard_common::xrpc::XrpcEndpoint for GetLatestCommitRequest {
116    const PATH: &'static str = "/xrpc/com.atproto.sync.getLatestCommit";
117    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
118    type Request<'de> = GetLatestCommit<'de>;
119    type Response = GetLatestCommitResponse;
120}
121
122pub mod get_latest_commit_state {
123
124    pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
125    #[allow(unused)]
126    use ::core::marker::PhantomData;
127    mod sealed {
128        pub trait Sealed {}
129    }
130    /// State trait tracking which required fields have been set
131    pub trait State: sealed::Sealed {
132        type Did;
133    }
134    /// Empty state - all required fields are unset
135    pub struct Empty(());
136    impl sealed::Sealed for Empty {}
137    impl State for Empty {
138        type Did = Unset;
139    }
140    ///State transition - sets the `did` field to Set
141    pub struct SetDid<S: State = Empty>(PhantomData<fn() -> S>);
142    impl<S: State> sealed::Sealed for SetDid<S> {}
143    impl<S: State> State for SetDid<S> {
144        type Did = Set<members::did>;
145    }
146    /// Marker types for field names
147    #[allow(non_camel_case_types)]
148    pub mod members {
149        ///Marker type for the `did` field
150        pub struct did(());
151    }
152}
153
154/// Builder for constructing an instance of this type
155pub struct GetLatestCommitBuilder<'a, S: get_latest_commit_state::State> {
156    _state: PhantomData<fn() -> S>,
157    _fields: (Option<Did<'a>>,),
158    _lifetime: PhantomData<&'a ()>,
159}
160
161impl<'a> GetLatestCommit<'a> {
162    /// Create a new builder for this type
163    pub fn new() -> GetLatestCommitBuilder<'a, get_latest_commit_state::Empty> {
164        GetLatestCommitBuilder::new()
165    }
166}
167
168impl<'a> GetLatestCommitBuilder<'a, get_latest_commit_state::Empty> {
169    /// Create a new builder with all fields unset
170    pub fn new() -> Self {
171        GetLatestCommitBuilder {
172            _state: PhantomData,
173            _fields: (None,),
174            _lifetime: PhantomData,
175        }
176    }
177}
178
179impl<'a, S> GetLatestCommitBuilder<'a, S>
180where
181    S: get_latest_commit_state::State,
182    S::Did: get_latest_commit_state::IsUnset,
183{
184    /// Set the `did` field (required)
185    pub fn did(
186        mut self,
187        value: impl Into<Did<'a>>,
188    ) -> GetLatestCommitBuilder<'a, get_latest_commit_state::SetDid<S>> {
189        self._fields.0 = Option::Some(value.into());
190        GetLatestCommitBuilder {
191            _state: PhantomData,
192            _fields: self._fields,
193            _lifetime: PhantomData,
194        }
195    }
196}
197
198impl<'a, S> GetLatestCommitBuilder<'a, S>
199where
200    S: get_latest_commit_state::State,
201    S::Did: get_latest_commit_state::IsSet,
202{
203    /// Build the final struct
204    pub fn build(self) -> GetLatestCommit<'a> {
205        GetLatestCommit {
206            did: self._fields.0.unwrap(),
207        }
208    }
209}