activitystreams_kinds/
lib.rs1#[cfg(feature = "url")]
6use url::Url;
7
8#[cfg(feature = "url")]
9pub fn context() -> Url {
11 "https://www.w3.org/ns/activitystreams".parse().unwrap()
12}
13
14#[cfg(feature = "url")]
15pub fn public() -> Url {
17 "https://www.w3.org/ns/activitystreams#Public"
18 .parse()
19 .unwrap()
20}
21
22#[cfg(feature = "url")]
23pub fn security() -> Url {
25 "https://w3id.org/security/v1".parse().unwrap()
26}
27
28#[cfg(feature = "iri-string")]
29pub fn context_iri() -> iri_string::types::IriString {
31 "https://www.w3.org/ns/activitystreams".parse().unwrap()
32}
33
34#[cfg(feature = "iri-string")]
35pub fn public_iri() -> iri_string::types::IriString {
37 "https://www.w3.org/ns/activitystreams#Public"
38 .parse()
39 .unwrap()
40}
41
42#[cfg(feature = "iri-string")]
43pub fn security_iri() -> iri_string::types::IriString {
45 "https://w3id.org/security/v1".parse().unwrap()
46}
47
48#[macro_export]
71macro_rules! kind {
72 ($x:ident, $y:ident) => {
73 #[derive(
74 Clone,
75 Debug,
76 Eq,
77 Hash,
78 Ord,
79 PartialEq,
80 PartialOrd,
81 serde::Deserialize,
82 serde::Serialize,
83 )]
84 pub enum $x {
86 $y,
87 }
88
89 impl std::fmt::Display for $x {
90 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
91 write!(f, stringify!($y))
92 }
93 }
94
95 impl Default for $x {
96 fn default() -> Self {
97 $x::$y
98 }
99 }
100 };
101}
102
103pub mod activity {
104 use crate::kind;
110
111 kind!(ActivityType, Activity);
112 kind!(AcceptType, Accept);
113 kind!(AddType, Add);
114 kind!(AnnounceType, Announce);
115 kind!(ArriveType, Arrive);
116 kind!(BlockType, Block);
117 kind!(CreateType, Create);
118 kind!(DeleteType, Delete);
119 kind!(DislikeType, Dislike);
120 kind!(FlagType, Flag);
121 kind!(FollowType, Follow);
122 kind!(IgnoreType, Ignore);
123 kind!(InviteType, Invite);
124 kind!(JoinType, Join);
125 kind!(LeaveType, Leave);
126 kind!(LikeType, Like);
127 kind!(ListenType, Listen);
128 kind!(MoveType, Move);
129 kind!(OfferType, Offer);
130 kind!(QuestionType, Question);
131 kind!(ReadType, Read);
132 kind!(RejectType, Reject);
133 kind!(RemoveType, Remove);
134 kind!(TentativeAcceptType, TentativeAccept);
135 kind!(TentativeRejectType, TentativeReject);
136 kind!(TravelType, Travel);
137 kind!(UndoType, Undo);
138 kind!(UpdateType, Update);
139 kind!(ViewType, View);
140}
141
142pub mod actor {
143 use crate::kind;
149
150 kind!(ApplicationType, Application);
151 kind!(GroupType, Group);
152 kind!(OrganizationType, Organization);
153 kind!(PersonType, Person);
154 kind!(ServiceType, Service);
155}
156
157pub mod collection {
158 use crate::kind;
164
165 kind!(CollectionType, Collection);
166 kind!(OrderedCollectionType, OrderedCollection);
167 kind!(CollectionPageType, CollectionPage);
168 kind!(OrderedCollectionPageType, OrderedCollectionPage);
169}
170
171pub mod link {
172 use crate::kind;
178
179 kind!(LinkType, Link);
180 kind!(MentionType, Mention);
181}
182
183pub mod object {
184 use crate::kind;
190
191 kind!(ObjectType, Object);
192 kind!(ArticleType, Article);
193 kind!(AudioType, Audio);
194 kind!(DocumentType, Document);
195 kind!(EventType, Event);
196 kind!(ImageType, Image);
197 kind!(NoteType, Note);
198 kind!(PageType, Page);
199 kind!(PlaceType, Place);
200 kind!(ProfileType, Profile);
201 kind!(RelationshipType, Relationship);
202 kind!(TombstoneType, Tombstone);
203 kind!(VideoType, Video);
204}
205
206#[cfg(test)]
207mod tests {
208 use super::kind;
209
210 #[test]
211 fn to_string_works() {
212 kind!(MyType, My);
213
214 assert_eq!(MyType::My.to_string(), "My")
215 }
216}