atproto blogging
at main 313 lines 11 kB view raw
1// @generated by jacquard-lexicon. DO NOT EDIT. 2// 3// Lexicon: pub.leaflet.poll.vote 4// 5// This file was automatically generated from Lexicon schemas. 6// Any manual changes will be overwritten on the next regeneration. 7 8/// Record declaring a vote on a poll 9#[jacquard_derive::lexicon] 10#[derive( 11 serde::Serialize, 12 serde::Deserialize, 13 Debug, 14 Clone, 15 PartialEq, 16 Eq, 17 jacquard_derive::IntoStatic 18)] 19#[serde(rename_all = "camelCase")] 20pub struct Vote<'a> { 21 #[serde(borrow)] 22 pub option: Vec<jacquard_common::CowStr<'a>>, 23 #[serde(borrow)] 24 pub poll: crate::com_atproto::repo::strong_ref::StrongRef<'a>, 25} 26 27pub mod vote_state { 28 29 pub use crate::builder_types::{Set, Unset, IsSet, IsUnset}; 30 #[allow(unused)] 31 use ::core::marker::PhantomData; 32 mod sealed { 33 pub trait Sealed {} 34 } 35 /// State trait tracking which required fields have been set 36 pub trait State: sealed::Sealed { 37 type Poll; 38 type Option; 39 } 40 /// Empty state - all required fields are unset 41 pub struct Empty(()); 42 impl sealed::Sealed for Empty {} 43 impl State for Empty { 44 type Poll = Unset; 45 type Option = Unset; 46 } 47 ///State transition - sets the `poll` field to Set 48 pub struct SetPoll<S: State = Empty>(PhantomData<fn() -> S>); 49 impl<S: State> sealed::Sealed for SetPoll<S> {} 50 impl<S: State> State for SetPoll<S> { 51 type Poll = Set<members::poll>; 52 type Option = S::Option; 53 } 54 ///State transition - sets the `option` field to Set 55 pub struct SetOption<S: State = Empty>(PhantomData<fn() -> S>); 56 impl<S: State> sealed::Sealed for SetOption<S> {} 57 impl<S: State> State for SetOption<S> { 58 type Poll = S::Poll; 59 type Option = Set<members::option>; 60 } 61 /// Marker types for field names 62 #[allow(non_camel_case_types)] 63 pub mod members { 64 ///Marker type for the `poll` field 65 pub struct poll(()); 66 ///Marker type for the `option` field 67 pub struct option(()); 68 } 69} 70 71/// Builder for constructing an instance of this type 72pub struct VoteBuilder<'a, S: vote_state::State> { 73 _phantom_state: ::core::marker::PhantomData<fn() -> S>, 74 __unsafe_private_named: ( 75 ::core::option::Option<Vec<jacquard_common::CowStr<'a>>>, 76 ::core::option::Option<crate::com_atproto::repo::strong_ref::StrongRef<'a>>, 77 ), 78 _phantom: ::core::marker::PhantomData<&'a ()>, 79} 80 81impl<'a> Vote<'a> { 82 /// Create a new builder for this type 83 pub fn new() -> VoteBuilder<'a, vote_state::Empty> { 84 VoteBuilder::new() 85 } 86} 87 88impl<'a> VoteBuilder<'a, vote_state::Empty> { 89 /// Create a new builder with all fields unset 90 pub fn new() -> Self { 91 VoteBuilder { 92 _phantom_state: ::core::marker::PhantomData, 93 __unsafe_private_named: (None, None), 94 _phantom: ::core::marker::PhantomData, 95 } 96 } 97} 98 99impl<'a, S> VoteBuilder<'a, S> 100where 101 S: vote_state::State, 102 S::Option: vote_state::IsUnset, 103{ 104 /// Set the `option` field (required) 105 pub fn option( 106 mut self, 107 value: impl Into<Vec<jacquard_common::CowStr<'a>>>, 108 ) -> VoteBuilder<'a, vote_state::SetOption<S>> { 109 self.__unsafe_private_named.0 = ::core::option::Option::Some(value.into()); 110 VoteBuilder { 111 _phantom_state: ::core::marker::PhantomData, 112 __unsafe_private_named: self.__unsafe_private_named, 113 _phantom: ::core::marker::PhantomData, 114 } 115 } 116} 117 118impl<'a, S> VoteBuilder<'a, S> 119where 120 S: vote_state::State, 121 S::Poll: vote_state::IsUnset, 122{ 123 /// Set the `poll` field (required) 124 pub fn poll( 125 mut self, 126 value: impl Into<crate::com_atproto::repo::strong_ref::StrongRef<'a>>, 127 ) -> VoteBuilder<'a, vote_state::SetPoll<S>> { 128 self.__unsafe_private_named.1 = ::core::option::Option::Some(value.into()); 129 VoteBuilder { 130 _phantom_state: ::core::marker::PhantomData, 131 __unsafe_private_named: self.__unsafe_private_named, 132 _phantom: ::core::marker::PhantomData, 133 } 134 } 135} 136 137impl<'a, S> VoteBuilder<'a, S> 138where 139 S: vote_state::State, 140 S::Poll: vote_state::IsSet, 141 S::Option: vote_state::IsSet, 142{ 143 /// Build the final struct 144 pub fn build(self) -> Vote<'a> { 145 Vote { 146 option: self.__unsafe_private_named.0.unwrap(), 147 poll: self.__unsafe_private_named.1.unwrap(), 148 extra_data: Default::default(), 149 } 150 } 151 /// Build the final struct with custom extra_data 152 pub fn build_with_data( 153 self, 154 extra_data: std::collections::BTreeMap< 155 jacquard_common::smol_str::SmolStr, 156 jacquard_common::types::value::Data<'a>, 157 >, 158 ) -> Vote<'a> { 159 Vote { 160 option: self.__unsafe_private_named.0.unwrap(), 161 poll: self.__unsafe_private_named.1.unwrap(), 162 extra_data: Some(extra_data), 163 } 164 } 165} 166 167impl<'a> Vote<'a> { 168 pub fn uri( 169 uri: impl Into<jacquard_common::CowStr<'a>>, 170 ) -> Result< 171 jacquard_common::types::uri::RecordUri<'a, VoteRecord>, 172 jacquard_common::types::uri::UriError, 173 > { 174 jacquard_common::types::uri::RecordUri::try_from_uri( 175 jacquard_common::types::string::AtUri::new_cow(uri.into())?, 176 ) 177 } 178} 179 180/// Typed wrapper for GetRecord response with this collection's record type. 181#[derive( 182 serde::Serialize, 183 serde::Deserialize, 184 Debug, 185 Clone, 186 PartialEq, 187 Eq, 188 jacquard_derive::IntoStatic 189)] 190#[serde(rename_all = "camelCase")] 191pub struct VoteGetRecordOutput<'a> { 192 #[serde(skip_serializing_if = "std::option::Option::is_none")] 193 #[serde(borrow)] 194 pub cid: std::option::Option<jacquard_common::types::string::Cid<'a>>, 195 #[serde(borrow)] 196 pub uri: jacquard_common::types::string::AtUri<'a>, 197 #[serde(borrow)] 198 pub value: Vote<'a>, 199} 200 201impl From<VoteGetRecordOutput<'_>> for Vote<'_> { 202 fn from(output: VoteGetRecordOutput<'_>) -> Self { 203 use jacquard_common::IntoStatic; 204 output.value.into_static() 205 } 206} 207 208impl jacquard_common::types::collection::Collection for Vote<'_> { 209 const NSID: &'static str = "pub.leaflet.poll.vote"; 210 type Record = VoteRecord; 211} 212 213/// Marker type for deserializing records from this collection. 214#[derive(Debug, serde::Serialize, serde::Deserialize)] 215pub struct VoteRecord; 216impl jacquard_common::xrpc::XrpcResp for VoteRecord { 217 const NSID: &'static str = "pub.leaflet.poll.vote"; 218 const ENCODING: &'static str = "application/json"; 219 type Output<'de> = VoteGetRecordOutput<'de>; 220 type Err<'de> = jacquard_common::types::collection::RecordError<'de>; 221} 222 223impl jacquard_common::types::collection::Collection for VoteRecord { 224 const NSID: &'static str = "pub.leaflet.poll.vote"; 225 type Record = VoteRecord; 226} 227 228impl<'a> ::jacquard_lexicon::schema::LexiconSchema for Vote<'a> { 229 fn nsid() -> &'static str { 230 "pub.leaflet.poll.vote" 231 } 232 fn def_name() -> &'static str { 233 "main" 234 } 235 fn lexicon_doc() -> ::jacquard_lexicon::lexicon::LexiconDoc<'static> { 236 lexicon_doc_pub_leaflet_poll_vote() 237 } 238 fn validate( 239 &self, 240 ) -> ::core::result::Result<(), ::jacquard_lexicon::validation::ConstraintError> { 241 Ok(()) 242 } 243} 244 245fn lexicon_doc_pub_leaflet_poll_vote() -> ::jacquard_lexicon::lexicon::LexiconDoc< 246 'static, 247> { 248 ::jacquard_lexicon::lexicon::LexiconDoc { 249 lexicon: ::jacquard_lexicon::lexicon::Lexicon::Lexicon1, 250 id: ::jacquard_common::CowStr::new_static("pub.leaflet.poll.vote"), 251 revision: None, 252 description: None, 253 defs: { 254 let mut map = ::alloc::collections::BTreeMap::new(); 255 map.insert( 256 ::jacquard_common::smol_str::SmolStr::new_static("main"), 257 ::jacquard_lexicon::lexicon::LexUserType::Record(::jacquard_lexicon::lexicon::LexRecord { 258 description: Some( 259 ::jacquard_common::CowStr::new_static( 260 "Record declaring a vote on a poll", 261 ), 262 ), 263 key: Some(::jacquard_common::CowStr::new_static("tid")), 264 record: ::jacquard_lexicon::lexicon::LexRecordRecord::Object(::jacquard_lexicon::lexicon::LexObject { 265 description: None, 266 required: Some( 267 vec![ 268 ::jacquard_common::smol_str::SmolStr::new_static("poll"), 269 ::jacquard_common::smol_str::SmolStr::new_static("option") 270 ], 271 ), 272 nullable: None, 273 properties: { 274 #[allow(unused_mut)] 275 let mut map = ::alloc::collections::BTreeMap::new(); 276 map.insert( 277 ::jacquard_common::smol_str::SmolStr::new_static("option"), 278 ::jacquard_lexicon::lexicon::LexObjectProperty::Array(::jacquard_lexicon::lexicon::LexArray { 279 description: None, 280 items: ::jacquard_lexicon::lexicon::LexArrayItem::String(::jacquard_lexicon::lexicon::LexString { 281 description: None, 282 format: None, 283 default: None, 284 min_length: None, 285 max_length: None, 286 min_graphemes: None, 287 max_graphemes: None, 288 r#enum: None, 289 r#const: None, 290 known_values: None, 291 }), 292 min_length: None, 293 max_length: None, 294 }), 295 ); 296 map.insert( 297 ::jacquard_common::smol_str::SmolStr::new_static("poll"), 298 ::jacquard_lexicon::lexicon::LexObjectProperty::Ref(::jacquard_lexicon::lexicon::LexRef { 299 description: None, 300 r#ref: ::jacquard_common::CowStr::new_static( 301 "com.atproto.repo.strongRef", 302 ), 303 }), 304 ); 305 map 306 }, 307 }), 308 }), 309 ); 310 map 311 }, 312 } 313}