atproto blogging
at main 354 lines 12 kB view raw
1// @generated by jacquard-lexicon. DO NOT EDIT. 2// 3// Lexicon: sh.weaver.notebook.updateReadingProgress 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 UpdateReadingProgress<'a> { 20 /// The entry the user is currently on. 21 #[serde(skip_serializing_if = "std::option::Option::is_none")] 22 #[serde(borrow)] 23 pub current_entry: std::option::Option<jacquard_common::types::string::AtUri<'a>>, 24 #[serde(borrow)] 25 pub notebook: jacquard_common::types::string::AtUri<'a>, 26 #[serde(skip_serializing_if = "std::option::Option::is_none")] 27 pub percent_complete: std::option::Option<i64>, 28 #[serde(skip_serializing_if = "std::option::Option::is_none")] 29 #[serde(borrow)] 30 pub status: std::option::Option<UpdateReadingProgressStatus<'a>>, 31} 32 33pub mod update_reading_progress_state { 34 35 pub use crate::builder_types::{Set, Unset, IsSet, IsUnset}; 36 #[allow(unused)] 37 use ::core::marker::PhantomData; 38 mod sealed { 39 pub trait Sealed {} 40 } 41 /// State trait tracking which required fields have been set 42 pub trait State: sealed::Sealed { 43 type Notebook; 44 } 45 /// Empty state - all required fields are unset 46 pub struct Empty(()); 47 impl sealed::Sealed for Empty {} 48 impl State for Empty { 49 type Notebook = Unset; 50 } 51 ///State transition - sets the `notebook` field to Set 52 pub struct SetNotebook<S: State = Empty>(PhantomData<fn() -> S>); 53 impl<S: State> sealed::Sealed for SetNotebook<S> {} 54 impl<S: State> State for SetNotebook<S> { 55 type Notebook = Set<members::notebook>; 56 } 57 /// Marker types for field names 58 #[allow(non_camel_case_types)] 59 pub mod members { 60 ///Marker type for the `notebook` field 61 pub struct notebook(()); 62 } 63} 64 65/// Builder for constructing an instance of this type 66pub struct UpdateReadingProgressBuilder<'a, S: update_reading_progress_state::State> { 67 _phantom_state: ::core::marker::PhantomData<fn() -> S>, 68 __unsafe_private_named: ( 69 ::core::option::Option<jacquard_common::types::string::AtUri<'a>>, 70 ::core::option::Option<jacquard_common::types::string::AtUri<'a>>, 71 ::core::option::Option<i64>, 72 ::core::option::Option<UpdateReadingProgressStatus<'a>>, 73 ), 74 _phantom: ::core::marker::PhantomData<&'a ()>, 75} 76 77impl<'a> UpdateReadingProgress<'a> { 78 /// Create a new builder for this type 79 pub fn new() -> UpdateReadingProgressBuilder< 80 'a, 81 update_reading_progress_state::Empty, 82 > { 83 UpdateReadingProgressBuilder::new() 84 } 85} 86 87impl<'a> UpdateReadingProgressBuilder<'a, update_reading_progress_state::Empty> { 88 /// Create a new builder with all fields unset 89 pub fn new() -> Self { 90 UpdateReadingProgressBuilder { 91 _phantom_state: ::core::marker::PhantomData, 92 __unsafe_private_named: (None, None, None, None), 93 _phantom: ::core::marker::PhantomData, 94 } 95 } 96} 97 98impl<'a, S: update_reading_progress_state::State> UpdateReadingProgressBuilder<'a, S> { 99 /// Set the `currentEntry` field (optional) 100 pub fn current_entry( 101 mut self, 102 value: impl Into<Option<jacquard_common::types::string::AtUri<'a>>>, 103 ) -> Self { 104 self.__unsafe_private_named.0 = value.into(); 105 self 106 } 107 /// Set the `currentEntry` field to an Option value (optional) 108 pub fn maybe_current_entry( 109 mut self, 110 value: Option<jacquard_common::types::string::AtUri<'a>>, 111 ) -> Self { 112 self.__unsafe_private_named.0 = value; 113 self 114 } 115} 116 117impl<'a, S> UpdateReadingProgressBuilder<'a, S> 118where 119 S: update_reading_progress_state::State, 120 S::Notebook: update_reading_progress_state::IsUnset, 121{ 122 /// Set the `notebook` field (required) 123 pub fn notebook( 124 mut self, 125 value: impl Into<jacquard_common::types::string::AtUri<'a>>, 126 ) -> UpdateReadingProgressBuilder< 127 'a, 128 update_reading_progress_state::SetNotebook<S>, 129 > { 130 self.__unsafe_private_named.1 = ::core::option::Option::Some(value.into()); 131 UpdateReadingProgressBuilder { 132 _phantom_state: ::core::marker::PhantomData, 133 __unsafe_private_named: self.__unsafe_private_named, 134 _phantom: ::core::marker::PhantomData, 135 } 136 } 137} 138 139impl<'a, S: update_reading_progress_state::State> UpdateReadingProgressBuilder<'a, S> { 140 /// Set the `percentComplete` field (optional) 141 pub fn percent_complete(mut self, value: impl Into<Option<i64>>) -> Self { 142 self.__unsafe_private_named.2 = value.into(); 143 self 144 } 145 /// Set the `percentComplete` field to an Option value (optional) 146 pub fn maybe_percent_complete(mut self, value: Option<i64>) -> Self { 147 self.__unsafe_private_named.2 = value; 148 self 149 } 150} 151 152impl<'a, S: update_reading_progress_state::State> UpdateReadingProgressBuilder<'a, S> { 153 /// Set the `status` field (optional) 154 pub fn status( 155 mut self, 156 value: impl Into<Option<UpdateReadingProgressStatus<'a>>>, 157 ) -> Self { 158 self.__unsafe_private_named.3 = value.into(); 159 self 160 } 161 /// Set the `status` field to an Option value (optional) 162 pub fn maybe_status( 163 mut self, 164 value: Option<UpdateReadingProgressStatus<'a>>, 165 ) -> Self { 166 self.__unsafe_private_named.3 = value; 167 self 168 } 169} 170 171impl<'a, S> UpdateReadingProgressBuilder<'a, S> 172where 173 S: update_reading_progress_state::State, 174 S::Notebook: update_reading_progress_state::IsSet, 175{ 176 /// Build the final struct 177 pub fn build(self) -> UpdateReadingProgress<'a> { 178 UpdateReadingProgress { 179 current_entry: self.__unsafe_private_named.0, 180 notebook: self.__unsafe_private_named.1.unwrap(), 181 percent_complete: self.__unsafe_private_named.2, 182 status: self.__unsafe_private_named.3, 183 extra_data: Default::default(), 184 } 185 } 186 /// Build the final struct with custom extra_data 187 pub fn build_with_data( 188 self, 189 extra_data: std::collections::BTreeMap< 190 jacquard_common::smol_str::SmolStr, 191 jacquard_common::types::value::Data<'a>, 192 >, 193 ) -> UpdateReadingProgress<'a> { 194 UpdateReadingProgress { 195 current_entry: self.__unsafe_private_named.0, 196 notebook: self.__unsafe_private_named.1.unwrap(), 197 percent_complete: self.__unsafe_private_named.2, 198 status: self.__unsafe_private_named.3, 199 extra_data: Some(extra_data), 200 } 201 } 202} 203 204#[derive(Debug, Clone, PartialEq, Eq, Hash)] 205pub enum UpdateReadingProgressStatus<'a> { 206 Reading, 207 Finished, 208 Abandoned, 209 WantToRead, 210 Other(jacquard_common::CowStr<'a>), 211} 212 213impl<'a> UpdateReadingProgressStatus<'a> { 214 pub fn as_str(&self) -> &str { 215 match self { 216 Self::Reading => "reading", 217 Self::Finished => "finished", 218 Self::Abandoned => "abandoned", 219 Self::WantToRead => "want-to-read", 220 Self::Other(s) => s.as_ref(), 221 } 222 } 223} 224 225impl<'a> From<&'a str> for UpdateReadingProgressStatus<'a> { 226 fn from(s: &'a str) -> Self { 227 match s { 228 "reading" => Self::Reading, 229 "finished" => Self::Finished, 230 "abandoned" => Self::Abandoned, 231 "want-to-read" => Self::WantToRead, 232 _ => Self::Other(jacquard_common::CowStr::from(s)), 233 } 234 } 235} 236 237impl<'a> From<String> for UpdateReadingProgressStatus<'a> { 238 fn from(s: String) -> Self { 239 match s.as_str() { 240 "reading" => Self::Reading, 241 "finished" => Self::Finished, 242 "abandoned" => Self::Abandoned, 243 "want-to-read" => Self::WantToRead, 244 _ => Self::Other(jacquard_common::CowStr::from(s)), 245 } 246 } 247} 248 249impl<'a> core::fmt::Display for UpdateReadingProgressStatus<'a> { 250 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { 251 write!(f, "{}", self.as_str()) 252 } 253} 254 255impl<'a> AsRef<str> for UpdateReadingProgressStatus<'a> { 256 fn as_ref(&self) -> &str { 257 self.as_str() 258 } 259} 260 261impl<'a> serde::Serialize for UpdateReadingProgressStatus<'a> { 262 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> 263 where 264 S: serde::Serializer, 265 { 266 serializer.serialize_str(self.as_str()) 267 } 268} 269 270impl<'de, 'a> serde::Deserialize<'de> for UpdateReadingProgressStatus<'a> 271where 272 'de: 'a, 273{ 274 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> 275 where 276 D: serde::Deserializer<'de>, 277 { 278 let s = <&'de str>::deserialize(deserializer)?; 279 Ok(Self::from(s)) 280 } 281} 282 283impl<'a> Default for UpdateReadingProgressStatus<'a> { 284 fn default() -> Self { 285 Self::Other(Default::default()) 286 } 287} 288 289impl jacquard_common::IntoStatic for UpdateReadingProgressStatus<'_> { 290 type Output = UpdateReadingProgressStatus<'static>; 291 fn into_static(self) -> Self::Output { 292 match self { 293 UpdateReadingProgressStatus::Reading => UpdateReadingProgressStatus::Reading, 294 UpdateReadingProgressStatus::Finished => { 295 UpdateReadingProgressStatus::Finished 296 } 297 UpdateReadingProgressStatus::Abandoned => { 298 UpdateReadingProgressStatus::Abandoned 299 } 300 UpdateReadingProgressStatus::WantToRead => { 301 UpdateReadingProgressStatus::WantToRead 302 } 303 UpdateReadingProgressStatus::Other(v) => { 304 UpdateReadingProgressStatus::Other(v.into_static()) 305 } 306 } 307 } 308} 309 310#[jacquard_derive::lexicon] 311#[derive( 312 serde::Serialize, 313 serde::Deserialize, 314 Debug, 315 Clone, 316 PartialEq, 317 Eq, 318 jacquard_derive::IntoStatic 319)] 320#[serde(rename_all = "camelCase")] 321pub struct UpdateReadingProgressOutput<'a> { 322 #[serde(borrow)] 323 pub progress: crate::sh_weaver::notebook::ReadingProgress<'a>, 324} 325 326/// Response type for 327///sh.weaver.notebook.updateReadingProgress 328pub struct UpdateReadingProgressResponse; 329impl jacquard_common::xrpc::XrpcResp for UpdateReadingProgressResponse { 330 const NSID: &'static str = "sh.weaver.notebook.updateReadingProgress"; 331 const ENCODING: &'static str = "application/json"; 332 type Output<'de> = UpdateReadingProgressOutput<'de>; 333 type Err<'de> = jacquard_common::xrpc::GenericError<'de>; 334} 335 336impl<'a> jacquard_common::xrpc::XrpcRequest for UpdateReadingProgress<'a> { 337 const NSID: &'static str = "sh.weaver.notebook.updateReadingProgress"; 338 const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure( 339 "application/json", 340 ); 341 type Response = UpdateReadingProgressResponse; 342} 343 344/// Endpoint type for 345///sh.weaver.notebook.updateReadingProgress 346pub struct UpdateReadingProgressRequest; 347impl jacquard_common::xrpc::XrpcEndpoint for UpdateReadingProgressRequest { 348 const PATH: &'static str = "/xrpc/sh.weaver.notebook.updateReadingProgress"; 349 const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure( 350 "application/json", 351 ); 352 type Request<'de> = UpdateReadingProgress<'de>; 353 type Response = UpdateReadingProgressResponse; 354}