jacquard_api/com_atproto/sync/
get_head.rs1#[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, 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 GetHead<'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 GetHeadOutput<'a> {
30 #[serde(borrow)]
31 pub root: Cid<'a>,
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 GetHeadError<'a> {
51 #[serde(rename = "HeadNotFound")]
52 HeadNotFound(Option<CowStr<'a>>),
53}
54
55impl core::fmt::Display for GetHeadError<'_> {
56 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
57 match self {
58 Self::HeadNotFound(msg) => {
59 write!(f, "HeadNotFound")?;
60 if let Some(msg) = msg {
61 write!(f, ": {}", msg)?;
62 }
63 Ok(())
64 }
65 Self::Unknown(err) => write!(f, "Unknown error: {:?}", err),
66 }
67 }
68}
69
70pub struct GetHeadResponse;
72impl jacquard_common::xrpc::XrpcResp for GetHeadResponse {
73 const NSID: &'static str = "com.atproto.sync.getHead";
74 const ENCODING: &'static str = "application/json";
75 type Output<'de> = GetHeadOutput<'de>;
76 type Err<'de> = GetHeadError<'de>;
77}
78
79impl<'a> jacquard_common::xrpc::XrpcRequest for GetHead<'a> {
80 const NSID: &'static str = "com.atproto.sync.getHead";
81 const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
82 type Response = GetHeadResponse;
83}
84
85pub struct GetHeadRequest;
87impl jacquard_common::xrpc::XrpcEndpoint for GetHeadRequest {
88 const PATH: &'static str = "/xrpc/com.atproto.sync.getHead";
89 const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
90 type Request<'de> = GetHead<'de>;
91 type Response = GetHeadResponse;
92}
93
94pub mod get_head_state {
95
96 pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
97 #[allow(unused)]
98 use ::core::marker::PhantomData;
99 mod sealed {
100 pub trait Sealed {}
101 }
102 pub trait State: sealed::Sealed {
104 type Did;
105 }
106 pub struct Empty(());
108 impl sealed::Sealed for Empty {}
109 impl State for Empty {
110 type Did = Unset;
111 }
112 pub struct SetDid<S: State = Empty>(PhantomData<fn() -> S>);
114 impl<S: State> sealed::Sealed for SetDid<S> {}
115 impl<S: State> State for SetDid<S> {
116 type Did = Set<members::did>;
117 }
118 #[allow(non_camel_case_types)]
120 pub mod members {
121 pub struct did(());
123 }
124}
125
126pub struct GetHeadBuilder<'a, S: get_head_state::State> {
128 _state: PhantomData<fn() -> S>,
129 _fields: (Option<Did<'a>>,),
130 _lifetime: PhantomData<&'a ()>,
131}
132
133impl<'a> GetHead<'a> {
134 pub fn new() -> GetHeadBuilder<'a, get_head_state::Empty> {
136 GetHeadBuilder::new()
137 }
138}
139
140impl<'a> GetHeadBuilder<'a, get_head_state::Empty> {
141 pub fn new() -> Self {
143 GetHeadBuilder {
144 _state: PhantomData,
145 _fields: (None,),
146 _lifetime: PhantomData,
147 }
148 }
149}
150
151impl<'a, S> GetHeadBuilder<'a, S>
152where
153 S: get_head_state::State,
154 S::Did: get_head_state::IsUnset,
155{
156 pub fn did(
158 mut self,
159 value: impl Into<Did<'a>>,
160 ) -> GetHeadBuilder<'a, get_head_state::SetDid<S>> {
161 self._fields.0 = Option::Some(value.into());
162 GetHeadBuilder {
163 _state: PhantomData,
164 _fields: self._fields,
165 _lifetime: PhantomData,
166 }
167 }
168}
169
170impl<'a, S> GetHeadBuilder<'a, S>
171where
172 S: get_head_state::State,
173 S::Did: get_head_state::IsSet,
174{
175 pub fn build(self) -> GetHead<'a> {
177 GetHead {
178 did: self._fields.0.unwrap(),
179 }
180 }
181}