jacquard_api/com_atproto/identity/
resolve_handle.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, Handle};
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 ResolveHandle<'a> {
21 #[serde(borrow)]
22 pub handle: Handle<'a>,
23}
24
25
26#[lexicon]
27#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
28#[serde(rename_all = "camelCase")]
29pub struct ResolveHandleOutput<'a> {
30 #[serde(borrow)]
31 pub did: Did<'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 ResolveHandleError<'a> {
51 #[serde(rename = "HandleNotFound")]
53 HandleNotFound(Option<CowStr<'a>>),
54}
55
56impl core::fmt::Display for ResolveHandleError<'_> {
57 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
58 match self {
59 Self::HandleNotFound(msg) => {
60 write!(f, "HandleNotFound")?;
61 if let Some(msg) = msg {
62 write!(f, ": {}", msg)?;
63 }
64 Ok(())
65 }
66 Self::Unknown(err) => write!(f, "Unknown error: {:?}", err),
67 }
68 }
69}
70
71pub struct ResolveHandleResponse;
73impl jacquard_common::xrpc::XrpcResp for ResolveHandleResponse {
74 const NSID: &'static str = "com.atproto.identity.resolveHandle";
75 const ENCODING: &'static str = "application/json";
76 type Output<'de> = ResolveHandleOutput<'de>;
77 type Err<'de> = ResolveHandleError<'de>;
78}
79
80impl<'a> jacquard_common::xrpc::XrpcRequest for ResolveHandle<'a> {
81 const NSID: &'static str = "com.atproto.identity.resolveHandle";
82 const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
83 type Response = ResolveHandleResponse;
84}
85
86pub struct ResolveHandleRequest;
88impl jacquard_common::xrpc::XrpcEndpoint for ResolveHandleRequest {
89 const PATH: &'static str = "/xrpc/com.atproto.identity.resolveHandle";
90 const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
91 type Request<'de> = ResolveHandle<'de>;
92 type Response = ResolveHandleResponse;
93}
94
95pub mod resolve_handle_state {
96
97 pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
98 #[allow(unused)]
99 use ::core::marker::PhantomData;
100 mod sealed {
101 pub trait Sealed {}
102 }
103 pub trait State: sealed::Sealed {
105 type Handle;
106 }
107 pub struct Empty(());
109 impl sealed::Sealed for Empty {}
110 impl State for Empty {
111 type Handle = Unset;
112 }
113 pub struct SetHandle<S: State = Empty>(PhantomData<fn() -> S>);
115 impl<S: State> sealed::Sealed for SetHandle<S> {}
116 impl<S: State> State for SetHandle<S> {
117 type Handle = Set<members::handle>;
118 }
119 #[allow(non_camel_case_types)]
121 pub mod members {
122 pub struct handle(());
124 }
125}
126
127pub struct ResolveHandleBuilder<'a, S: resolve_handle_state::State> {
129 _state: PhantomData<fn() -> S>,
130 _fields: (Option<Handle<'a>>,),
131 _lifetime: PhantomData<&'a ()>,
132}
133
134impl<'a> ResolveHandle<'a> {
135 pub fn new() -> ResolveHandleBuilder<'a, resolve_handle_state::Empty> {
137 ResolveHandleBuilder::new()
138 }
139}
140
141impl<'a> ResolveHandleBuilder<'a, resolve_handle_state::Empty> {
142 pub fn new() -> Self {
144 ResolveHandleBuilder {
145 _state: PhantomData,
146 _fields: (None,),
147 _lifetime: PhantomData,
148 }
149 }
150}
151
152impl<'a, S> ResolveHandleBuilder<'a, S>
153where
154 S: resolve_handle_state::State,
155 S::Handle: resolve_handle_state::IsUnset,
156{
157 pub fn handle(
159 mut self,
160 value: impl Into<Handle<'a>>,
161 ) -> ResolveHandleBuilder<'a, resolve_handle_state::SetHandle<S>> {
162 self._fields.0 = Option::Some(value.into());
163 ResolveHandleBuilder {
164 _state: PhantomData,
165 _fields: self._fields,
166 _lifetime: PhantomData,
167 }
168 }
169}
170
171impl<'a, S> ResolveHandleBuilder<'a, S>
172where
173 S: resolve_handle_state::State,
174 S::Handle: resolve_handle_state::IsSet,
175{
176 pub fn build(self) -> ResolveHandle<'a> {
178 ResolveHandle {
179 handle: self._fields.0.unwrap(),
180 }
181 }
182}