atproto blogging
at main 491 lines 15 kB view raw
1// @generated by jacquard-lexicon. DO NOT EDIT. 2// 3// Lexicon: tools.ozone.setting.upsertOption 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 UpsertOption<'a> { 20 #[serde(skip_serializing_if = "std::option::Option::is_none")] 21 #[serde(borrow)] 22 pub description: std::option::Option<jacquard_common::CowStr<'a>>, 23 #[serde(borrow)] 24 pub key: jacquard_common::types::string::Nsid<'a>, 25 #[serde(skip_serializing_if = "std::option::Option::is_none")] 26 #[serde(borrow)] 27 pub manager_role: std::option::Option<UpsertOptionManagerRole<'a>>, 28 #[serde(borrow)] 29 pub scope: UpsertOptionScope<'a>, 30 #[serde(borrow)] 31 pub value: jacquard_common::types::value::Data<'a>, 32} 33 34pub mod upsert_option_state { 35 36 pub use crate::builder_types::{Set, Unset, IsSet, IsUnset}; 37 #[allow(unused)] 38 use ::core::marker::PhantomData; 39 mod sealed { 40 pub trait Sealed {} 41 } 42 /// State trait tracking which required fields have been set 43 pub trait State: sealed::Sealed { 44 type Scope; 45 type Value; 46 type Key; 47 } 48 /// Empty state - all required fields are unset 49 pub struct Empty(()); 50 impl sealed::Sealed for Empty {} 51 impl State for Empty { 52 type Scope = Unset; 53 type Value = Unset; 54 type Key = Unset; 55 } 56 ///State transition - sets the `scope` field to Set 57 pub struct SetScope<S: State = Empty>(PhantomData<fn() -> S>); 58 impl<S: State> sealed::Sealed for SetScope<S> {} 59 impl<S: State> State for SetScope<S> { 60 type Scope = Set<members::scope>; 61 type Value = S::Value; 62 type Key = S::Key; 63 } 64 ///State transition - sets the `value` field to Set 65 pub struct SetValue<S: State = Empty>(PhantomData<fn() -> S>); 66 impl<S: State> sealed::Sealed for SetValue<S> {} 67 impl<S: State> State for SetValue<S> { 68 type Scope = S::Scope; 69 type Value = Set<members::value>; 70 type Key = S::Key; 71 } 72 ///State transition - sets the `key` field to Set 73 pub struct SetKey<S: State = Empty>(PhantomData<fn() -> S>); 74 impl<S: State> sealed::Sealed for SetKey<S> {} 75 impl<S: State> State for SetKey<S> { 76 type Scope = S::Scope; 77 type Value = S::Value; 78 type Key = Set<members::key>; 79 } 80 /// Marker types for field names 81 #[allow(non_camel_case_types)] 82 pub mod members { 83 ///Marker type for the `scope` field 84 pub struct scope(()); 85 ///Marker type for the `value` field 86 pub struct value(()); 87 ///Marker type for the `key` field 88 pub struct key(()); 89 } 90} 91 92/// Builder for constructing an instance of this type 93pub struct UpsertOptionBuilder<'a, S: upsert_option_state::State> { 94 _phantom_state: ::core::marker::PhantomData<fn() -> S>, 95 __unsafe_private_named: ( 96 ::core::option::Option<jacquard_common::CowStr<'a>>, 97 ::core::option::Option<jacquard_common::types::string::Nsid<'a>>, 98 ::core::option::Option<UpsertOptionManagerRole<'a>>, 99 ::core::option::Option<UpsertOptionScope<'a>>, 100 ::core::option::Option<jacquard_common::types::value::Data<'a>>, 101 ), 102 _phantom: ::core::marker::PhantomData<&'a ()>, 103} 104 105impl<'a> UpsertOption<'a> { 106 /// Create a new builder for this type 107 pub fn new() -> UpsertOptionBuilder<'a, upsert_option_state::Empty> { 108 UpsertOptionBuilder::new() 109 } 110} 111 112impl<'a> UpsertOptionBuilder<'a, upsert_option_state::Empty> { 113 /// Create a new builder with all fields unset 114 pub fn new() -> Self { 115 UpsertOptionBuilder { 116 _phantom_state: ::core::marker::PhantomData, 117 __unsafe_private_named: (None, None, None, None, None), 118 _phantom: ::core::marker::PhantomData, 119 } 120 } 121} 122 123impl<'a, S: upsert_option_state::State> UpsertOptionBuilder<'a, S> { 124 /// Set the `description` field (optional) 125 pub fn description( 126 mut self, 127 value: impl Into<Option<jacquard_common::CowStr<'a>>>, 128 ) -> Self { 129 self.__unsafe_private_named.0 = value.into(); 130 self 131 } 132 /// Set the `description` field to an Option value (optional) 133 pub fn maybe_description( 134 mut self, 135 value: Option<jacquard_common::CowStr<'a>>, 136 ) -> Self { 137 self.__unsafe_private_named.0 = value; 138 self 139 } 140} 141 142impl<'a, S> UpsertOptionBuilder<'a, S> 143where 144 S: upsert_option_state::State, 145 S::Key: upsert_option_state::IsUnset, 146{ 147 /// Set the `key` field (required) 148 pub fn key( 149 mut self, 150 value: impl Into<jacquard_common::types::string::Nsid<'a>>, 151 ) -> UpsertOptionBuilder<'a, upsert_option_state::SetKey<S>> { 152 self.__unsafe_private_named.1 = ::core::option::Option::Some(value.into()); 153 UpsertOptionBuilder { 154 _phantom_state: ::core::marker::PhantomData, 155 __unsafe_private_named: self.__unsafe_private_named, 156 _phantom: ::core::marker::PhantomData, 157 } 158 } 159} 160 161impl<'a, S: upsert_option_state::State> UpsertOptionBuilder<'a, S> { 162 /// Set the `managerRole` field (optional) 163 pub fn manager_role( 164 mut self, 165 value: impl Into<Option<UpsertOptionManagerRole<'a>>>, 166 ) -> Self { 167 self.__unsafe_private_named.2 = value.into(); 168 self 169 } 170 /// Set the `managerRole` field to an Option value (optional) 171 pub fn maybe_manager_role( 172 mut self, 173 value: Option<UpsertOptionManagerRole<'a>>, 174 ) -> Self { 175 self.__unsafe_private_named.2 = value; 176 self 177 } 178} 179 180impl<'a, S> UpsertOptionBuilder<'a, S> 181where 182 S: upsert_option_state::State, 183 S::Scope: upsert_option_state::IsUnset, 184{ 185 /// Set the `scope` field (required) 186 pub fn scope( 187 mut self, 188 value: impl Into<UpsertOptionScope<'a>>, 189 ) -> UpsertOptionBuilder<'a, upsert_option_state::SetScope<S>> { 190 self.__unsafe_private_named.3 = ::core::option::Option::Some(value.into()); 191 UpsertOptionBuilder { 192 _phantom_state: ::core::marker::PhantomData, 193 __unsafe_private_named: self.__unsafe_private_named, 194 _phantom: ::core::marker::PhantomData, 195 } 196 } 197} 198 199impl<'a, S> UpsertOptionBuilder<'a, S> 200where 201 S: upsert_option_state::State, 202 S::Value: upsert_option_state::IsUnset, 203{ 204 /// Set the `value` field (required) 205 pub fn value( 206 mut self, 207 value: impl Into<jacquard_common::types::value::Data<'a>>, 208 ) -> UpsertOptionBuilder<'a, upsert_option_state::SetValue<S>> { 209 self.__unsafe_private_named.4 = ::core::option::Option::Some(value.into()); 210 UpsertOptionBuilder { 211 _phantom_state: ::core::marker::PhantomData, 212 __unsafe_private_named: self.__unsafe_private_named, 213 _phantom: ::core::marker::PhantomData, 214 } 215 } 216} 217 218impl<'a, S> UpsertOptionBuilder<'a, S> 219where 220 S: upsert_option_state::State, 221 S::Scope: upsert_option_state::IsSet, 222 S::Value: upsert_option_state::IsSet, 223 S::Key: upsert_option_state::IsSet, 224{ 225 /// Build the final struct 226 pub fn build(self) -> UpsertOption<'a> { 227 UpsertOption { 228 description: self.__unsafe_private_named.0, 229 key: self.__unsafe_private_named.1.unwrap(), 230 manager_role: self.__unsafe_private_named.2, 231 scope: self.__unsafe_private_named.3.unwrap(), 232 value: self.__unsafe_private_named.4.unwrap(), 233 extra_data: Default::default(), 234 } 235 } 236 /// Build the final struct with custom extra_data 237 pub fn build_with_data( 238 self, 239 extra_data: std::collections::BTreeMap< 240 jacquard_common::smol_str::SmolStr, 241 jacquard_common::types::value::Data<'a>, 242 >, 243 ) -> UpsertOption<'a> { 244 UpsertOption { 245 description: self.__unsafe_private_named.0, 246 key: self.__unsafe_private_named.1.unwrap(), 247 manager_role: self.__unsafe_private_named.2, 248 scope: self.__unsafe_private_named.3.unwrap(), 249 value: self.__unsafe_private_named.4.unwrap(), 250 extra_data: Some(extra_data), 251 } 252 } 253} 254 255#[derive(Debug, Clone, PartialEq, Eq, Hash)] 256pub enum UpsertOptionManagerRole<'a> { 257 RoleModerator, 258 RoleTriage, 259 RoleVerifier, 260 RoleAdmin, 261 Other(jacquard_common::CowStr<'a>), 262} 263 264impl<'a> UpsertOptionManagerRole<'a> { 265 pub fn as_str(&self) -> &str { 266 match self { 267 Self::RoleModerator => "tools.ozone.team.defs#roleModerator", 268 Self::RoleTriage => "tools.ozone.team.defs#roleTriage", 269 Self::RoleVerifier => "tools.ozone.team.defs#roleVerifier", 270 Self::RoleAdmin => "tools.ozone.team.defs#roleAdmin", 271 Self::Other(s) => s.as_ref(), 272 } 273 } 274} 275 276impl<'a> From<&'a str> for UpsertOptionManagerRole<'a> { 277 fn from(s: &'a str) -> Self { 278 match s { 279 "tools.ozone.team.defs#roleModerator" => Self::RoleModerator, 280 "tools.ozone.team.defs#roleTriage" => Self::RoleTriage, 281 "tools.ozone.team.defs#roleVerifier" => Self::RoleVerifier, 282 "tools.ozone.team.defs#roleAdmin" => Self::RoleAdmin, 283 _ => Self::Other(jacquard_common::CowStr::from(s)), 284 } 285 } 286} 287 288impl<'a> From<String> for UpsertOptionManagerRole<'a> { 289 fn from(s: String) -> Self { 290 match s.as_str() { 291 "tools.ozone.team.defs#roleModerator" => Self::RoleModerator, 292 "tools.ozone.team.defs#roleTriage" => Self::RoleTriage, 293 "tools.ozone.team.defs#roleVerifier" => Self::RoleVerifier, 294 "tools.ozone.team.defs#roleAdmin" => Self::RoleAdmin, 295 _ => Self::Other(jacquard_common::CowStr::from(s)), 296 } 297 } 298} 299 300impl<'a> core::fmt::Display for UpsertOptionManagerRole<'a> { 301 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { 302 write!(f, "{}", self.as_str()) 303 } 304} 305 306impl<'a> AsRef<str> for UpsertOptionManagerRole<'a> { 307 fn as_ref(&self) -> &str { 308 self.as_str() 309 } 310} 311 312impl<'a> serde::Serialize for UpsertOptionManagerRole<'a> { 313 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> 314 where 315 S: serde::Serializer, 316 { 317 serializer.serialize_str(self.as_str()) 318 } 319} 320 321impl<'de, 'a> serde::Deserialize<'de> for UpsertOptionManagerRole<'a> 322where 323 'de: 'a, 324{ 325 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> 326 where 327 D: serde::Deserializer<'de>, 328 { 329 let s = <&'de str>::deserialize(deserializer)?; 330 Ok(Self::from(s)) 331 } 332} 333 334impl<'a> Default for UpsertOptionManagerRole<'a> { 335 fn default() -> Self { 336 Self::Other(Default::default()) 337 } 338} 339 340impl jacquard_common::IntoStatic for UpsertOptionManagerRole<'_> { 341 type Output = UpsertOptionManagerRole<'static>; 342 fn into_static(self) -> Self::Output { 343 match self { 344 UpsertOptionManagerRole::RoleModerator => { 345 UpsertOptionManagerRole::RoleModerator 346 } 347 UpsertOptionManagerRole::RoleTriage => UpsertOptionManagerRole::RoleTriage, 348 UpsertOptionManagerRole::RoleVerifier => { 349 UpsertOptionManagerRole::RoleVerifier 350 } 351 UpsertOptionManagerRole::RoleAdmin => UpsertOptionManagerRole::RoleAdmin, 352 UpsertOptionManagerRole::Other(v) => { 353 UpsertOptionManagerRole::Other(v.into_static()) 354 } 355 } 356 } 357} 358 359#[derive(Debug, Clone, PartialEq, Eq, Hash)] 360pub enum UpsertOptionScope<'a> { 361 Instance, 362 Personal, 363 Other(jacquard_common::CowStr<'a>), 364} 365 366impl<'a> UpsertOptionScope<'a> { 367 pub fn as_str(&self) -> &str { 368 match self { 369 Self::Instance => "instance", 370 Self::Personal => "personal", 371 Self::Other(s) => s.as_ref(), 372 } 373 } 374} 375 376impl<'a> From<&'a str> for UpsertOptionScope<'a> { 377 fn from(s: &'a str) -> Self { 378 match s { 379 "instance" => Self::Instance, 380 "personal" => Self::Personal, 381 _ => Self::Other(jacquard_common::CowStr::from(s)), 382 } 383 } 384} 385 386impl<'a> From<String> for UpsertOptionScope<'a> { 387 fn from(s: String) -> Self { 388 match s.as_str() { 389 "instance" => Self::Instance, 390 "personal" => Self::Personal, 391 _ => Self::Other(jacquard_common::CowStr::from(s)), 392 } 393 } 394} 395 396impl<'a> core::fmt::Display for UpsertOptionScope<'a> { 397 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { 398 write!(f, "{}", self.as_str()) 399 } 400} 401 402impl<'a> AsRef<str> for UpsertOptionScope<'a> { 403 fn as_ref(&self) -> &str { 404 self.as_str() 405 } 406} 407 408impl<'a> serde::Serialize for UpsertOptionScope<'a> { 409 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> 410 where 411 S: serde::Serializer, 412 { 413 serializer.serialize_str(self.as_str()) 414 } 415} 416 417impl<'de, 'a> serde::Deserialize<'de> for UpsertOptionScope<'a> 418where 419 'de: 'a, 420{ 421 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> 422 where 423 D: serde::Deserializer<'de>, 424 { 425 let s = <&'de str>::deserialize(deserializer)?; 426 Ok(Self::from(s)) 427 } 428} 429 430impl<'a> Default for UpsertOptionScope<'a> { 431 fn default() -> Self { 432 Self::Other(Default::default()) 433 } 434} 435 436impl jacquard_common::IntoStatic for UpsertOptionScope<'_> { 437 type Output = UpsertOptionScope<'static>; 438 fn into_static(self) -> Self::Output { 439 match self { 440 UpsertOptionScope::Instance => UpsertOptionScope::Instance, 441 UpsertOptionScope::Personal => UpsertOptionScope::Personal, 442 UpsertOptionScope::Other(v) => UpsertOptionScope::Other(v.into_static()), 443 } 444 } 445} 446 447#[jacquard_derive::lexicon] 448#[derive( 449 serde::Serialize, 450 serde::Deserialize, 451 Debug, 452 Clone, 453 PartialEq, 454 Eq, 455 jacquard_derive::IntoStatic 456)] 457#[serde(rename_all = "camelCase")] 458pub struct UpsertOptionOutput<'a> { 459 #[serde(borrow)] 460 pub option: crate::tools_ozone::setting::DefsOption<'a>, 461} 462 463/// Response type for 464///tools.ozone.setting.upsertOption 465pub struct UpsertOptionResponse; 466impl jacquard_common::xrpc::XrpcResp for UpsertOptionResponse { 467 const NSID: &'static str = "tools.ozone.setting.upsertOption"; 468 const ENCODING: &'static str = "application/json"; 469 type Output<'de> = UpsertOptionOutput<'de>; 470 type Err<'de> = jacquard_common::xrpc::GenericError<'de>; 471} 472 473impl<'a> jacquard_common::xrpc::XrpcRequest for UpsertOption<'a> { 474 const NSID: &'static str = "tools.ozone.setting.upsertOption"; 475 const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure( 476 "application/json", 477 ); 478 type Response = UpsertOptionResponse; 479} 480 481/// Endpoint type for 482///tools.ozone.setting.upsertOption 483pub struct UpsertOptionRequest; 484impl jacquard_common::xrpc::XrpcEndpoint for UpsertOptionRequest { 485 const PATH: &'static str = "/xrpc/tools.ozone.setting.upsertOption"; 486 const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure( 487 "application/json", 488 ); 489 type Request<'de> = UpsertOption<'de>; 490 type Response = UpsertOptionResponse; 491}