Skip to main content

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