A better Rust ATProto crate
at lifetimes 11 kB view raw
1// @generated by jacquard-lexicon. DO NOT EDIT. 2// 3// Lexicon: tools.ozone.safelink.defs 4// 5// This file was automatically generated from Lexicon schemas. 6// Any manual changes will be overwritten on the next regeneration. 7 8pub mod add_rule; 9pub mod query_events; 10pub mod query_rules; 11pub mod remove_rule; 12pub mod update_rule; 13 14#[derive(Debug, Clone, PartialEq, Eq, Hash)] 15pub enum ActionType<'a> { 16 Block, 17 Warn, 18 Whitelist, 19 Other(jacquard_common::CowStr<'a>), 20} 21 22impl<'a> ActionType<'a> { 23 pub fn as_str(&self) -> &str { 24 match self { 25 Self::Block => "block", 26 Self::Warn => "warn", 27 Self::Whitelist => "whitelist", 28 Self::Other(s) => s.as_ref(), 29 } 30 } 31} 32 33impl<'a> From<&'a str> for ActionType<'a> { 34 fn from(s: &'a str) -> Self { 35 match s { 36 "block" => Self::Block, 37 "warn" => Self::Warn, 38 "whitelist" => Self::Whitelist, 39 _ => Self::Other(jacquard_common::CowStr::from(s)), 40 } 41 } 42} 43 44impl<'a> From<String> for ActionType<'a> { 45 fn from(s: String) -> Self { 46 match s.as_str() { 47 "block" => Self::Block, 48 "warn" => Self::Warn, 49 "whitelist" => Self::Whitelist, 50 _ => Self::Other(jacquard_common::CowStr::from(s)), 51 } 52 } 53} 54 55impl<'a> AsRef<str> for ActionType<'a> { 56 fn as_ref(&self) -> &str { 57 self.as_str() 58 } 59} 60 61impl<'a> serde::Serialize for ActionType<'a> { 62 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> 63 where 64 S: serde::Serializer, 65 { 66 serializer.serialize_str(self.as_str()) 67 } 68} 69 70impl<'de, 'a> serde::Deserialize<'de> for ActionType<'a> 71where 72 'de: 'a, 73{ 74 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> 75 where 76 D: serde::Deserializer<'de>, 77 { 78 let s = <&'de str>::deserialize(deserializer)?; 79 Ok(Self::from(s)) 80 } 81} 82 83impl jacquard_common::IntoStatic for ActionType<'_> { 84 type Output = ActionType<'static>; 85 fn into_static(self) -> Self::Output { 86 match self { 87 ActionType::Block => ActionType::Block, 88 ActionType::Warn => ActionType::Warn, 89 ActionType::Whitelist => ActionType::Whitelist, 90 ActionType::Other(v) => ActionType::Other(v.into_static()), 91 } 92 } 93} 94 95///An event for URL safety decisions 96#[jacquard_derive::lexicon] 97#[derive( 98 serde::Serialize, 99 serde::Deserialize, 100 Debug, 101 Clone, 102 PartialEq, 103 Eq, 104 jacquard_derive::IntoStatic 105)] 106#[serde(rename_all = "camelCase")] 107pub struct Event<'a> { 108 #[serde(borrow)] 109 pub action: crate::tools_ozone::safelink::ActionType<'a>, 110 ///Optional comment about the decision 111 #[serde(skip_serializing_if = "std::option::Option::is_none")] 112 #[serde(borrow)] 113 pub comment: std::option::Option<jacquard_common::CowStr<'a>>, 114 pub created_at: jacquard_common::types::string::Datetime, 115 ///DID of the user who created this rule 116 #[serde(borrow)] 117 pub created_by: jacquard_common::types::string::Did<'a>, 118 #[serde(borrow)] 119 pub event_type: crate::tools_ozone::safelink::EventType<'a>, 120 ///Auto-incrementing row ID 121 pub id: i64, 122 #[serde(borrow)] 123 pub pattern: crate::tools_ozone::safelink::PatternType<'a>, 124 #[serde(borrow)] 125 pub reason: crate::tools_ozone::safelink::ReasonType<'a>, 126 ///The URL that this rule applies to 127 #[serde(borrow)] 128 pub url: jacquard_common::CowStr<'a>, 129} 130 131#[derive(Debug, Clone, PartialEq, Eq, Hash)] 132pub enum EventType<'a> { 133 AddRule, 134 UpdateRule, 135 RemoveRule, 136 Other(jacquard_common::CowStr<'a>), 137} 138 139impl<'a> EventType<'a> { 140 pub fn as_str(&self) -> &str { 141 match self { 142 Self::AddRule => "addRule", 143 Self::UpdateRule => "updateRule", 144 Self::RemoveRule => "removeRule", 145 Self::Other(s) => s.as_ref(), 146 } 147 } 148} 149 150impl<'a> From<&'a str> for EventType<'a> { 151 fn from(s: &'a str) -> Self { 152 match s { 153 "addRule" => Self::AddRule, 154 "updateRule" => Self::UpdateRule, 155 "removeRule" => Self::RemoveRule, 156 _ => Self::Other(jacquard_common::CowStr::from(s)), 157 } 158 } 159} 160 161impl<'a> From<String> for EventType<'a> { 162 fn from(s: String) -> Self { 163 match s.as_str() { 164 "addRule" => Self::AddRule, 165 "updateRule" => Self::UpdateRule, 166 "removeRule" => Self::RemoveRule, 167 _ => Self::Other(jacquard_common::CowStr::from(s)), 168 } 169 } 170} 171 172impl<'a> AsRef<str> for EventType<'a> { 173 fn as_ref(&self) -> &str { 174 self.as_str() 175 } 176} 177 178impl<'a> serde::Serialize for EventType<'a> { 179 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> 180 where 181 S: serde::Serializer, 182 { 183 serializer.serialize_str(self.as_str()) 184 } 185} 186 187impl<'de, 'a> serde::Deserialize<'de> for EventType<'a> 188where 189 'de: 'a, 190{ 191 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> 192 where 193 D: serde::Deserializer<'de>, 194 { 195 let s = <&'de str>::deserialize(deserializer)?; 196 Ok(Self::from(s)) 197 } 198} 199 200impl jacquard_common::IntoStatic for EventType<'_> { 201 type Output = EventType<'static>; 202 fn into_static(self) -> Self::Output { 203 match self { 204 EventType::AddRule => EventType::AddRule, 205 EventType::UpdateRule => EventType::UpdateRule, 206 EventType::RemoveRule => EventType::RemoveRule, 207 EventType::Other(v) => EventType::Other(v.into_static()), 208 } 209 } 210} 211 212#[derive(Debug, Clone, PartialEq, Eq, Hash)] 213pub enum PatternType<'a> { 214 Domain, 215 Url, 216 Other(jacquard_common::CowStr<'a>), 217} 218 219impl<'a> PatternType<'a> { 220 pub fn as_str(&self) -> &str { 221 match self { 222 Self::Domain => "domain", 223 Self::Url => "url", 224 Self::Other(s) => s.as_ref(), 225 } 226 } 227} 228 229impl<'a> From<&'a str> for PatternType<'a> { 230 fn from(s: &'a str) -> Self { 231 match s { 232 "domain" => Self::Domain, 233 "url" => Self::Url, 234 _ => Self::Other(jacquard_common::CowStr::from(s)), 235 } 236 } 237} 238 239impl<'a> From<String> for PatternType<'a> { 240 fn from(s: String) -> Self { 241 match s.as_str() { 242 "domain" => Self::Domain, 243 "url" => Self::Url, 244 _ => Self::Other(jacquard_common::CowStr::from(s)), 245 } 246 } 247} 248 249impl<'a> AsRef<str> for PatternType<'a> { 250 fn as_ref(&self) -> &str { 251 self.as_str() 252 } 253} 254 255impl<'a> serde::Serialize for PatternType<'a> { 256 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> 257 where 258 S: serde::Serializer, 259 { 260 serializer.serialize_str(self.as_str()) 261 } 262} 263 264impl<'de, 'a> serde::Deserialize<'de> for PatternType<'a> 265where 266 'de: 'a, 267{ 268 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> 269 where 270 D: serde::Deserializer<'de>, 271 { 272 let s = <&'de str>::deserialize(deserializer)?; 273 Ok(Self::from(s)) 274 } 275} 276 277impl jacquard_common::IntoStatic for PatternType<'_> { 278 type Output = PatternType<'static>; 279 fn into_static(self) -> Self::Output { 280 match self { 281 PatternType::Domain => PatternType::Domain, 282 PatternType::Url => PatternType::Url, 283 PatternType::Other(v) => PatternType::Other(v.into_static()), 284 } 285 } 286} 287 288#[derive(Debug, Clone, PartialEq, Eq, Hash)] 289pub enum ReasonType<'a> { 290 Csam, 291 Spam, 292 Phishing, 293 None, 294 Other(jacquard_common::CowStr<'a>), 295} 296 297impl<'a> ReasonType<'a> { 298 pub fn as_str(&self) -> &str { 299 match self { 300 Self::Csam => "csam", 301 Self::Spam => "spam", 302 Self::Phishing => "phishing", 303 Self::None => "none", 304 Self::Other(s) => s.as_ref(), 305 } 306 } 307} 308 309impl<'a> From<&'a str> for ReasonType<'a> { 310 fn from(s: &'a str) -> Self { 311 match s { 312 "csam" => Self::Csam, 313 "spam" => Self::Spam, 314 "phishing" => Self::Phishing, 315 "none" => Self::None, 316 _ => Self::Other(jacquard_common::CowStr::from(s)), 317 } 318 } 319} 320 321impl<'a> From<String> for ReasonType<'a> { 322 fn from(s: String) -> Self { 323 match s.as_str() { 324 "csam" => Self::Csam, 325 "spam" => Self::Spam, 326 "phishing" => Self::Phishing, 327 "none" => Self::None, 328 _ => Self::Other(jacquard_common::CowStr::from(s)), 329 } 330 } 331} 332 333impl<'a> AsRef<str> for ReasonType<'a> { 334 fn as_ref(&self) -> &str { 335 self.as_str() 336 } 337} 338 339impl<'a> serde::Serialize for ReasonType<'a> { 340 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> 341 where 342 S: serde::Serializer, 343 { 344 serializer.serialize_str(self.as_str()) 345 } 346} 347 348impl<'de, 'a> serde::Deserialize<'de> for ReasonType<'a> 349where 350 'de: 'a, 351{ 352 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> 353 where 354 D: serde::Deserializer<'de>, 355 { 356 let s = <&'de str>::deserialize(deserializer)?; 357 Ok(Self::from(s)) 358 } 359} 360 361impl jacquard_common::IntoStatic for ReasonType<'_> { 362 type Output = ReasonType<'static>; 363 fn into_static(self) -> Self::Output { 364 match self { 365 ReasonType::Csam => ReasonType::Csam, 366 ReasonType::Spam => ReasonType::Spam, 367 ReasonType::Phishing => ReasonType::Phishing, 368 ReasonType::None => ReasonType::None, 369 ReasonType::Other(v) => ReasonType::Other(v.into_static()), 370 } 371 } 372} 373 374///Input for creating a URL safety rule 375#[jacquard_derive::lexicon] 376#[derive( 377 serde::Serialize, 378 serde::Deserialize, 379 Debug, 380 Clone, 381 PartialEq, 382 Eq, 383 jacquard_derive::IntoStatic 384)] 385#[serde(rename_all = "camelCase")] 386pub struct UrlRule<'a> { 387 #[serde(borrow)] 388 pub action: crate::tools_ozone::safelink::ActionType<'a>, 389 ///Optional comment about the decision 390 #[serde(skip_serializing_if = "std::option::Option::is_none")] 391 #[serde(borrow)] 392 pub comment: std::option::Option<jacquard_common::CowStr<'a>>, 393 ///Timestamp when the rule was created 394 pub created_at: jacquard_common::types::string::Datetime, 395 ///DID of the user added the rule. 396 #[serde(borrow)] 397 pub created_by: jacquard_common::types::string::Did<'a>, 398 #[serde(borrow)] 399 pub pattern: crate::tools_ozone::safelink::PatternType<'a>, 400 #[serde(borrow)] 401 pub reason: crate::tools_ozone::safelink::ReasonType<'a>, 402 ///Timestamp when the rule was last updated 403 pub updated_at: jacquard_common::types::string::Datetime, 404 ///The URL or domain to apply the rule to 405 #[serde(borrow)] 406 pub url: jacquard_common::CowStr<'a>, 407}