jacquard_api/app_bsky/bookmark/
create_bookmark.rs

1// @generated by jacquard-lexicon. DO NOT EDIT.
2//
3// Lexicon: app.bsky.bookmark.createBookmark
4//
5// This file was automatically generated from Lexicon schemas.
6// Any manual changes will be overwritten on the next regeneration.
7
8#[jacquard_derive::lexicon]
9#[derive(
10    serde::Serialize,
11    serde::Deserialize,
12    Debug,
13    Clone,
14    PartialEq,
15    Eq,
16    jacquard_derive::IntoStatic
17)]
18#[serde(rename_all = "camelCase")]
19pub struct CreateBookmark<'a> {
20    #[serde(borrow)]
21    pub cid: jacquard_common::types::string::Cid<'a>,
22    #[serde(borrow)]
23    pub uri: jacquard_common::types::string::AtUri<'a>,
24}
25
26pub mod create_bookmark_state {
27
28    pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
29    #[allow(unused)]
30    use ::core::marker::PhantomData;
31    mod sealed {
32        pub trait Sealed {}
33    }
34    /// State trait tracking which required fields have been set
35    pub trait State: sealed::Sealed {
36        type Uri;
37        type Cid;
38    }
39    /// Empty state - all required fields are unset
40    pub struct Empty(());
41    impl sealed::Sealed for Empty {}
42    impl State for Empty {
43        type Uri = Unset;
44        type Cid = Unset;
45    }
46    ///State transition - sets the `uri` field to Set
47    pub struct SetUri<S: State = Empty>(PhantomData<fn() -> S>);
48    impl<S: State> sealed::Sealed for SetUri<S> {}
49    impl<S: State> State for SetUri<S> {
50        type Uri = Set<members::uri>;
51        type Cid = S::Cid;
52    }
53    ///State transition - sets the `cid` field to Set
54    pub struct SetCid<S: State = Empty>(PhantomData<fn() -> S>);
55    impl<S: State> sealed::Sealed for SetCid<S> {}
56    impl<S: State> State for SetCid<S> {
57        type Uri = S::Uri;
58        type Cid = Set<members::cid>;
59    }
60    /// Marker types for field names
61    #[allow(non_camel_case_types)]
62    pub mod members {
63        ///Marker type for the `uri` field
64        pub struct uri(());
65        ///Marker type for the `cid` field
66        pub struct cid(());
67    }
68}
69
70/// Builder for constructing an instance of this type
71pub struct CreateBookmarkBuilder<'a, S: create_bookmark_state::State> {
72    _phantom_state: ::core::marker::PhantomData<fn() -> S>,
73    __unsafe_private_named: (
74        ::core::option::Option<jacquard_common::types::string::Cid<'a>>,
75        ::core::option::Option<jacquard_common::types::string::AtUri<'a>>,
76    ),
77    _phantom: ::core::marker::PhantomData<&'a ()>,
78}
79
80impl<'a> CreateBookmark<'a> {
81    /// Create a new builder for this type
82    pub fn new() -> CreateBookmarkBuilder<'a, create_bookmark_state::Empty> {
83        CreateBookmarkBuilder::new()
84    }
85}
86
87impl<'a> CreateBookmarkBuilder<'a, create_bookmark_state::Empty> {
88    /// Create a new builder with all fields unset
89    pub fn new() -> Self {
90        CreateBookmarkBuilder {
91            _phantom_state: ::core::marker::PhantomData,
92            __unsafe_private_named: (None, None),
93            _phantom: ::core::marker::PhantomData,
94        }
95    }
96}
97
98impl<'a, S> CreateBookmarkBuilder<'a, S>
99where
100    S: create_bookmark_state::State,
101    S::Cid: create_bookmark_state::IsUnset,
102{
103    /// Set the `cid` field (required)
104    pub fn cid(
105        mut self,
106        value: impl Into<jacquard_common::types::string::Cid<'a>>,
107    ) -> CreateBookmarkBuilder<'a, create_bookmark_state::SetCid<S>> {
108        self.__unsafe_private_named.0 = ::core::option::Option::Some(value.into());
109        CreateBookmarkBuilder {
110            _phantom_state: ::core::marker::PhantomData,
111            __unsafe_private_named: self.__unsafe_private_named,
112            _phantom: ::core::marker::PhantomData,
113        }
114    }
115}
116
117impl<'a, S> CreateBookmarkBuilder<'a, S>
118where
119    S: create_bookmark_state::State,
120    S::Uri: create_bookmark_state::IsUnset,
121{
122    /// Set the `uri` field (required)
123    pub fn uri(
124        mut self,
125        value: impl Into<jacquard_common::types::string::AtUri<'a>>,
126    ) -> CreateBookmarkBuilder<'a, create_bookmark_state::SetUri<S>> {
127        self.__unsafe_private_named.1 = ::core::option::Option::Some(value.into());
128        CreateBookmarkBuilder {
129            _phantom_state: ::core::marker::PhantomData,
130            __unsafe_private_named: self.__unsafe_private_named,
131            _phantom: ::core::marker::PhantomData,
132        }
133    }
134}
135
136impl<'a, S> CreateBookmarkBuilder<'a, S>
137where
138    S: create_bookmark_state::State,
139    S::Uri: create_bookmark_state::IsSet,
140    S::Cid: create_bookmark_state::IsSet,
141{
142    /// Build the final struct
143    pub fn build(self) -> CreateBookmark<'a> {
144        CreateBookmark {
145            cid: self.__unsafe_private_named.0.unwrap(),
146            uri: self.__unsafe_private_named.1.unwrap(),
147            extra_data: Default::default(),
148        }
149    }
150    /// Build the final struct with custom extra_data
151    pub fn build_with_data(
152        self,
153        extra_data: std::collections::BTreeMap<
154            jacquard_common::smol_str::SmolStr,
155            jacquard_common::types::value::Data<'a>,
156        >,
157    ) -> CreateBookmark<'a> {
158        CreateBookmark {
159            cid: self.__unsafe_private_named.0.unwrap(),
160            uri: self.__unsafe_private_named.1.unwrap(),
161            extra_data: Some(extra_data),
162        }
163    }
164}
165
166#[jacquard_derive::open_union]
167#[derive(
168    serde::Serialize,
169    serde::Deserialize,
170    Debug,
171    Clone,
172    PartialEq,
173    Eq,
174    thiserror::Error,
175    miette::Diagnostic,
176    jacquard_derive::IntoStatic
177)]
178#[serde(tag = "error", content = "message")]
179#[serde(bound(deserialize = "'de: 'a"))]
180pub enum CreateBookmarkError<'a> {
181    /// The URI to be bookmarked is for an unsupported collection.
182    #[serde(rename = "UnsupportedCollection")]
183    UnsupportedCollection(std::option::Option<String>),
184}
185
186impl std::fmt::Display for CreateBookmarkError<'_> {
187    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
188        match self {
189            Self::UnsupportedCollection(msg) => {
190                write!(f, "UnsupportedCollection")?;
191                if let Some(msg) = msg {
192                    write!(f, ": {}", msg)?;
193                }
194                Ok(())
195            }
196            Self::Unknown(err) => write!(f, "Unknown error: {:?}", err),
197        }
198    }
199}
200
201/// Response type for
202///app.bsky.bookmark.createBookmark
203pub struct CreateBookmarkResponse;
204impl jacquard_common::xrpc::XrpcResp for CreateBookmarkResponse {
205    const NSID: &'static str = "app.bsky.bookmark.createBookmark";
206    const ENCODING: &'static str = "application/json";
207    type Output<'de> = ();
208    type Err<'de> = CreateBookmarkError<'de>;
209}
210
211impl<'a> jacquard_common::xrpc::XrpcRequest for CreateBookmark<'a> {
212    const NSID: &'static str = "app.bsky.bookmark.createBookmark";
213    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
214        "application/json",
215    );
216    type Response = CreateBookmarkResponse;
217}
218
219/// Endpoint type for
220///app.bsky.bookmark.createBookmark
221pub struct CreateBookmarkRequest;
222impl jacquard_common::xrpc::XrpcEndpoint for CreateBookmarkRequest {
223    const PATH: &'static str = "/xrpc/app.bsky.bookmark.createBookmark";
224    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
225        "application/json",
226    );
227    type Request<'de> = CreateBookmark<'de>;
228    type Response = CreateBookmarkResponse;
229}