A better Rust ATProto crate
at main 9.0 kB view raw
1// @generated by jacquard-lexicon. DO NOT EDIT. 2// 3// Lexicon: com.atproto.label.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 query_labels; 9pub mod subscribe_labels; 10 11/// Metadata tag on an atproto resource (eg, repo or record). 12#[jacquard_derive::lexicon] 13#[derive( 14 serde::Serialize, 15 serde::Deserialize, 16 Debug, 17 Clone, 18 PartialEq, 19 Eq, 20 jacquard_derive::IntoStatic, 21 bon::Builder 22)] 23#[serde(rename_all = "camelCase")] 24pub struct Label<'a> { 25 /// Optionally, CID specifying the specific version of 'uri' resource this label applies to. 26 #[serde(skip_serializing_if = "std::option::Option::is_none")] 27 #[builder(into)] 28 #[serde(borrow)] 29 pub cid: Option<jacquard_common::types::string::Cid<'a>>, 30 /// Timestamp when this label was created. 31 pub cts: jacquard_common::types::string::Datetime, 32 /// Timestamp at which this label expires (no longer applies). 33 #[serde(skip_serializing_if = "std::option::Option::is_none")] 34 #[builder(into)] 35 pub exp: Option<jacquard_common::types::string::Datetime>, 36 /// If true, this is a negation label, overwriting a previous label. 37 #[serde(skip_serializing_if = "std::option::Option::is_none")] 38 #[builder(into)] 39 pub neg: Option<bool>, 40 /// Signature of dag-cbor encoded label. 41 #[serde(skip_serializing_if = "std::option::Option::is_none")] 42 #[builder(into)] 43 pub sig: Option<bytes::Bytes>, 44 /// DID of the actor who created this label. 45 #[serde(borrow)] 46 pub src: jacquard_common::types::string::Did<'a>, 47 /// AT URI of the record, repository (account), or other resource that this label applies to. 48 #[serde(borrow)] 49 pub uri: jacquard_common::types::string::Uri<'a>, 50 /// The short string name of the value or type of this label. 51 #[serde(borrow)] 52 #[builder(into)] 53 pub val: jacquard_common::CowStr<'a>, 54 /// The AT Protocol version of the label object. 55 #[serde(skip_serializing_if = "std::option::Option::is_none")] 56 #[builder(into)] 57 pub ver: Option<i64>, 58} 59 60#[derive(Debug, Clone, PartialEq, Eq, Hash)] 61pub enum LabelValue<'a> { 62 Hide, 63 NoPromote, 64 Warn, 65 NoUnauthenticated, 66 DmcaViolation, 67 Doxxing, 68 Porn, 69 Sexual, 70 Nudity, 71 Nsfl, 72 Gore, 73 Other(jacquard_common::CowStr<'a>), 74} 75 76impl<'a> LabelValue<'a> { 77 pub fn as_str(&self) -> &str { 78 match self { 79 Self::Hide => "!hide", 80 Self::NoPromote => "!no-promote", 81 Self::Warn => "!warn", 82 Self::NoUnauthenticated => "!no-unauthenticated", 83 Self::DmcaViolation => "dmca-violation", 84 Self::Doxxing => "doxxing", 85 Self::Porn => "porn", 86 Self::Sexual => "sexual", 87 Self::Nudity => "nudity", 88 Self::Nsfl => "nsfl", 89 Self::Gore => "gore", 90 Self::Other(s) => s.as_ref(), 91 } 92 } 93} 94 95impl<'a> From<&'a str> for LabelValue<'a> { 96 fn from(s: &'a str) -> Self { 97 match s { 98 "!hide" => Self::Hide, 99 "!no-promote" => Self::NoPromote, 100 "!warn" => Self::Warn, 101 "!no-unauthenticated" => Self::NoUnauthenticated, 102 "dmca-violation" => Self::DmcaViolation, 103 "doxxing" => Self::Doxxing, 104 "porn" => Self::Porn, 105 "sexual" => Self::Sexual, 106 "nudity" => Self::Nudity, 107 "nsfl" => Self::Nsfl, 108 "gore" => Self::Gore, 109 _ => Self::Other(jacquard_common::CowStr::from(s)), 110 } 111 } 112} 113 114impl<'a> From<String> for LabelValue<'a> { 115 fn from(s: String) -> Self { 116 match s.as_str() { 117 "!hide" => Self::Hide, 118 "!no-promote" => Self::NoPromote, 119 "!warn" => Self::Warn, 120 "!no-unauthenticated" => Self::NoUnauthenticated, 121 "dmca-violation" => Self::DmcaViolation, 122 "doxxing" => Self::Doxxing, 123 "porn" => Self::Porn, 124 "sexual" => Self::Sexual, 125 "nudity" => Self::Nudity, 126 "nsfl" => Self::Nsfl, 127 "gore" => Self::Gore, 128 _ => Self::Other(jacquard_common::CowStr::from(s)), 129 } 130 } 131} 132 133impl<'a> AsRef<str> for LabelValue<'a> { 134 fn as_ref(&self) -> &str { 135 self.as_str() 136 } 137} 138 139impl<'a> serde::Serialize for LabelValue<'a> { 140 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> 141 where 142 S: serde::Serializer, 143 { 144 serializer.serialize_str(self.as_str()) 145 } 146} 147 148impl<'de, 'a> serde::Deserialize<'de> for LabelValue<'a> 149where 150 'de: 'a, 151{ 152 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> 153 where 154 D: serde::Deserializer<'de>, 155 { 156 let s = <&'de str>::deserialize(deserializer)?; 157 Ok(Self::from(s)) 158 } 159} 160 161impl jacquard_common::IntoStatic for LabelValue<'_> { 162 type Output = LabelValue<'static>; 163 fn into_static(self) -> Self::Output { 164 match self { 165 LabelValue::Hide => LabelValue::Hide, 166 LabelValue::NoPromote => LabelValue::NoPromote, 167 LabelValue::Warn => LabelValue::Warn, 168 LabelValue::NoUnauthenticated => LabelValue::NoUnauthenticated, 169 LabelValue::DmcaViolation => LabelValue::DmcaViolation, 170 LabelValue::Doxxing => LabelValue::Doxxing, 171 LabelValue::Porn => LabelValue::Porn, 172 LabelValue::Sexual => LabelValue::Sexual, 173 LabelValue::Nudity => LabelValue::Nudity, 174 LabelValue::Nsfl => LabelValue::Nsfl, 175 LabelValue::Gore => LabelValue::Gore, 176 LabelValue::Other(v) => LabelValue::Other(v.into_static()), 177 } 178 } 179} 180 181/// Declares a label value and its expected interpretations and behaviors. 182#[jacquard_derive::lexicon] 183#[derive( 184 serde::Serialize, 185 serde::Deserialize, 186 Debug, 187 Clone, 188 PartialEq, 189 Eq, 190 jacquard_derive::IntoStatic, 191 bon::Builder 192)] 193#[serde(rename_all = "camelCase")] 194pub struct LabelValueDefinition<'a> { 195 /// Does the user need to have adult content enabled in order to configure this label? 196 #[serde(skip_serializing_if = "std::option::Option::is_none")] 197 #[builder(into)] 198 pub adult_only: Option<bool>, 199 /// What should this label hide in the UI, if applied? 'content' hides all of the target; 'media' hides the images/video/audio; 'none' hides nothing. 200 #[serde(borrow)] 201 #[builder(into)] 202 pub blurs: jacquard_common::CowStr<'a>, 203 /// The default setting for this label. 204 #[serde(skip_serializing_if = "std::option::Option::is_none")] 205 #[builder(into)] 206 #[serde(borrow)] 207 pub default_setting: Option<jacquard_common::CowStr<'a>>, 208 /// The value of the label being defined. Must only include lowercase ascii and the '-' character ([a-z-]+). 209 #[serde(borrow)] 210 #[builder(into)] 211 pub identifier: jacquard_common::CowStr<'a>, 212 #[serde(borrow)] 213 pub locales: Vec<crate::com_atproto::label::LabelValueDefinitionStrings<'a>>, 214 /// How should a client visually convey this label? 'inform' means neutral and informational; 'alert' means negative and warning; 'none' means show nothing. 215 #[serde(borrow)] 216 #[builder(into)] 217 pub severity: jacquard_common::CowStr<'a>, 218} 219 220/// Strings which describe the label in the UI, localized into a specific language. 221#[jacquard_derive::lexicon] 222#[derive( 223 serde::Serialize, 224 serde::Deserialize, 225 Debug, 226 Clone, 227 PartialEq, 228 Eq, 229 jacquard_derive::IntoStatic, 230 bon::Builder 231)] 232#[serde(rename_all = "camelCase")] 233pub struct LabelValueDefinitionStrings<'a> { 234 /// A longer description of what the label means and why it might be applied. 235 #[serde(borrow)] 236 #[builder(into)] 237 pub description: jacquard_common::CowStr<'a>, 238 /// The code of the language these strings are written in. 239 pub lang: jacquard_common::types::string::Language, 240 /// A short human-readable name for the label. 241 #[serde(borrow)] 242 #[builder(into)] 243 pub name: jacquard_common::CowStr<'a>, 244} 245 246/// Metadata tag on an atproto record, published by the author within the record. Note that schemas should use #selfLabels, not #selfLabel. 247#[jacquard_derive::lexicon] 248#[derive( 249 serde::Serialize, 250 serde::Deserialize, 251 Debug, 252 Clone, 253 PartialEq, 254 Eq, 255 jacquard_derive::IntoStatic, 256 Default 257)] 258#[serde(rename_all = "camelCase")] 259pub struct SelfLabel<'a> { 260 /// The short string name of the value or type of this label. 261 #[serde(borrow)] 262 pub val: jacquard_common::CowStr<'a>, 263} 264 265/// Metadata tags on an atproto record, published by the author within the record. 266#[jacquard_derive::lexicon] 267#[derive( 268 serde::Serialize, 269 serde::Deserialize, 270 Debug, 271 Clone, 272 PartialEq, 273 Eq, 274 jacquard_derive::IntoStatic, 275 bon::Builder 276)] 277#[serde(rename_all = "camelCase")] 278pub struct SelfLabels<'a> { 279 #[serde(borrow)] 280 pub values: Vec<crate::com_atproto::label::SelfLabel<'a>>, 281}