From c6a0027e7ad379e1061e70737f93f64a74236a90 Mon Sep 17 00:00:00 2001 From: asonix Date: Fri, 13 Mar 2020 15:54:29 -0500 Subject: [PATCH] Drop typetag in favor of serde_json::Value --- Cargo.toml | 8 +- activitystreams-derive/Cargo.toml | 4 +- activitystreams-derive/README.md | 7 +- activitystreams-derive/src/lib.rs | 216 ++++-- examples/de.rs | 55 ++ src/activity/apub.rs | 296 ++++---- src/activity/kind.rs | 56 +- src/activity/mod.rs | 5 + src/activity/streams.rs | 850 +++++++++++++++++++++++ src/activity/streams/accept.rs | 57 -- src/activity/streams/add.rs | 58 -- src/activity/streams/amove.rs | 56 -- src/activity/streams/announce.rs | 56 -- src/activity/streams/arrive.rs | 59 -- src/activity/streams/block.rs | 58 -- src/activity/streams/create.rs | 54 -- src/activity/streams/delete.rs | 56 -- src/activity/streams/dislike.rs | 54 -- src/activity/streams/flag.rs | 57 -- src/activity/streams/follow.rs | 58 -- src/activity/streams/ignore.rs | 56 -- src/activity/streams/invite.rs | 55 -- src/activity/streams/join.rs | 56 -- src/activity/streams/leave.rs | 56 -- src/activity/streams/like.rs | 56 -- src/activity/streams/listen.rs | 54 -- src/activity/streams/mod.rs | 56 -- src/activity/streams/offer.rs | 56 -- src/activity/streams/question.rs | 63 -- src/activity/streams/read.rs | 54 -- src/activity/streams/reject.rs | 56 -- src/activity/streams/remove.rs | 56 -- src/activity/streams/tentative_accept.rs | 54 -- src/activity/streams/tentative_reject.rs | 54 -- src/activity/streams/travel.rs | 59 -- src/activity/streams/undo.rs | 60 -- src/activity/streams/update.rs | 59 -- src/activity/streams/view.rs | 54 -- src/actor/apub.rs | 44 +- src/actor/kind.rs | 10 +- src/actor/mod.rs | 4 + src/actor/streams.rs | 32 +- src/collection/apub.rs | 46 +- src/collection/kind.rs | 8 +- src/collection/mod.rs | 97 +-- src/collection/streams.rs | 38 +- src/lib.rs | 2 +- src/link/kind.rs | 2 +- src/link/mod.rs | 59 +- src/link/types.rs | 5 +- src/object/apub.rs | 72 +- src/object/kind.rs | 24 +- src/object/mod.rs | 68 +- src/object/streams.rs | 48 +- 54 files changed, 1498 insertions(+), 2195 deletions(-) create mode 100644 examples/de.rs create mode 100644 src/activity/streams.rs delete mode 100644 src/activity/streams/accept.rs delete mode 100644 src/activity/streams/add.rs delete mode 100644 src/activity/streams/amove.rs delete mode 100644 src/activity/streams/announce.rs delete mode 100644 src/activity/streams/arrive.rs delete mode 100644 src/activity/streams/block.rs delete mode 100644 src/activity/streams/create.rs delete mode 100644 src/activity/streams/delete.rs delete mode 100644 src/activity/streams/dislike.rs delete mode 100644 src/activity/streams/flag.rs delete mode 100644 src/activity/streams/follow.rs delete mode 100644 src/activity/streams/ignore.rs delete mode 100644 src/activity/streams/invite.rs delete mode 100644 src/activity/streams/join.rs delete mode 100644 src/activity/streams/leave.rs delete mode 100644 src/activity/streams/like.rs delete mode 100644 src/activity/streams/listen.rs delete mode 100644 src/activity/streams/mod.rs delete mode 100644 src/activity/streams/offer.rs delete mode 100644 src/activity/streams/question.rs delete mode 100644 src/activity/streams/read.rs delete mode 100644 src/activity/streams/reject.rs delete mode 100644 src/activity/streams/remove.rs delete mode 100644 src/activity/streams/tentative_accept.rs delete mode 100644 src/activity/streams/tentative_reject.rs delete mode 100644 src/activity/streams/travel.rs delete mode 100644 src/activity/streams/undo.rs delete mode 100644 src/activity/streams/update.rs delete mode 100644 src/activity/streams/view.rs diff --git a/Cargo.toml b/Cargo.toml index 8bc9648..39d37a4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "activitystreams" description = "Activity Streams in Rust" -version = "0.4.0" +version = "0.5.0-alpha.0" license = "GPL-3.0" authors = ["asonix "] repository = "https://git.asonix.dog/Aardwolf/activitystreams" @@ -14,14 +14,14 @@ default = ["types"] derive = ["activitystreams-derive"] kinds = ["derive", "serde"] primitives = ["chrono", "mime", "serde", "thiserror", "url"] -types = ["derive", "kinds", "primitives", "serde"] +types = ["derive", "kinds", "primitives", "serde", "serde_json"] [dependencies] -activitystreams-derive = { version = "0.4.0", path = "activitystreams-derive", optional = true} -typetag = "0.1.4" +activitystreams-derive = { version = "0.5.0-alpha.0", path = "activitystreams-derive", optional = true} chrono = { version = "0.4", optional = true } mime = { version = "0.3", optional = true } serde = { version = "1.0", features = ["derive"], optional = true } +serde_json = { version = "1.0", optional = true } thiserror = { version = "1.0", optional = true } url = { version = "2.1", optional = true } diff --git a/activitystreams-derive/Cargo.toml b/activitystreams-derive/Cargo.toml index 907e710..8522955 100644 --- a/activitystreams-derive/Cargo.toml +++ b/activitystreams-derive/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "activitystreams-derive" description = "Derive macros for activitystreams" -version = "0.4.0" +version = "0.5.0-alpha.0" license = "GPL-3.0" authors = ["asonix "] repository = "https://git.asonix.dog/Aardwolf/activitystreams" @@ -11,7 +11,7 @@ edition = "2018" [dependencies] quote = "1.0" -syn = "1.0" +syn = { version = "1.0", features = ["full"] } proc-macro2 = "1.0" [dev-dependencies] diff --git a/activitystreams-derive/README.md b/activitystreams-derive/README.md index b619755..00021b0 100644 --- a/activitystreams-derive/README.md +++ b/activitystreams-derive/README.md @@ -32,7 +32,7 @@ use activitystreams::object::properties::ObjectProperties; /// This macro implements Serialize and Deserialize for the given type, making this type /// represent the string "SomeKind" in JSON. #[derive(Clone, Debug, Default, UnitString)] -#[activitystreams(SomeKind)] +#[unit_string(SomeKind)] pub struct MyKind; properties! { @@ -80,17 +80,18 @@ properties! { #[derive(Clone, Default, PropRefs, serde::Deserialize, serde::Serialize)] #[serde(rename_all = "camelCase")] +#[prop_refs(Object)] pub struct My { /// Derive AsRef and AsMut #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] my_properties: MyProperties, /// Derive AsRef and AsMut /// /// as well as the Object trait #[serde(flatten)] - #[activitystreams(Object)] + #[prop_refs] properties: ObjectProperties, } diff --git a/activitystreams-derive/src/lib.rs b/activitystreams-derive/src/lib.rs index 1b4c31c..77a624c 100644 --- a/activitystreams-derive/src/lib.rs +++ b/activitystreams-derive/src/lib.rs @@ -38,7 +38,7 @@ //! /// This macro implements Serialize and Deserialize for the given type, making this type //! /// represent the string "SomeKind" in JSON. //! #[derive(Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd, UnitString)] -//! #[activitystreams(SomeKind)] +//! #[unit_string(SomeKind)] //! pub struct MyKind; //! //! /// Using the properties macro @@ -107,17 +107,18 @@ use syn::{ /// /// ```ignore /// #[derive(Clone, Debug, serde::Deserialize, serde::Serialize, PropRefs)] +/// #[prop_refs(Object)] /// pub struct MyStruct { /// /// Derive AsRef and AsMut delegating to `my_field` -/// #[activitystreams(None)] +/// #[prop_refs] /// my_field: MyProperties, /// /// /// Derive the above, plus Object (activitystreams) -/// #[activitystreams(Object)] +/// #[prop_refs] /// obj_field: ObjectProperties, /// } /// ``` -#[proc_macro_derive(PropRefs, attributes(activitystreams))] +#[proc_macro_derive(PropRefs, attributes(prop_refs))] pub fn ref_derive(input: TokenStream) -> TokenStream { let input: DeriveInput = syn::parse(input).unwrap(); @@ -133,6 +134,39 @@ pub fn ref_derive(input: TokenStream) -> TokenStream { _ => panic!("Can only derive for named fields"), }; + let name2 = name.clone(); + let base_impls: proc_macro2::TokenStream = input + .attrs + .iter() + .filter_map(move |attr| { + if attr + .path + .segments + .last() + .map(|segment| segment.ident == "prop_refs") + .unwrap_or(false) + { + let object = from_value(attr.clone()); + let name = name2.clone(); + let box_name = Ident::new(&format!("{}Box", object), name.span()); + + Some(quote! { + impl #object for #name {} + + impl std::convert::TryFrom<#name> for #box_name { + type Error = serde_json::Error; + + fn try_from(s: #name) -> Result { + #box_name::from_concrete(s) + } + } + }) + } else { + None + } + }) + .collect(); + let tokens: proc_macro2::TokenStream = fields .named .iter() @@ -142,48 +176,15 @@ pub fn ref_derive(input: TokenStream) -> TokenStream { .path .segments .last() - .map(|segment| { - segment.ident == Ident::new("activitystreams", segment.ident.span()) - }) + .map(|segment| segment.ident == "prop_refs") .unwrap_or(false) }); - our_attr.map(move |our_attr| { - ( - field.ident.clone().unwrap(), - field.ty.clone(), - our_attr.clone(), - ) - }) + our_attr.map(move |_| (field.ident.clone().unwrap(), field.ty.clone())) }) - .flat_map(move |(ident, ty, attr)| { - let object = from_value(attr); + .map(move |(ident, ty)| { let name = name.clone(); - - let base_impl = if object.to_string() == "Object" || object.to_string() == "Link" { - quote! { - #[typetag::serde] - impl #object for #name { - fn as_any(&self) -> &dyn std::any::Any { - self - } - - fn as_any_mut(&mut self) -> &mut dyn std::any::Any { - self - } - - fn duplicate(&self) -> Box { - Box::new(self.clone()) - } - } - } - } else { - quote! { - impl #object for #name {} - } - }; - - let ref_impls = quote! { + quote! { impl AsRef<#ty> for #name { fn as_ref(&self) -> &#ty { &self.#ident @@ -195,38 +196,138 @@ pub fn ref_derive(input: TokenStream) -> TokenStream { &mut self.#ident } } - }; - - if object == "None" { - ref_impls - } else { - quote! { - #ref_impls - #base_impl - } } }) .collect(); let full = quote! { + #base_impls #tokens }; full.into() } +/// Derive a wrapper type based on serde_json::Value to contain any possible trait type +/// +/// The following code +/// ```ignore +/// #[wrapper_type] +/// pub trait Object {} +/// ``` +/// produces the following type +/// ```ignore +/// pub struct ObjectBox(pub serde_json::Value); +/// +/// impl ObjectBox { +/// pub fn from_concrete(t: T) -> Result +/// where +/// T: Object + serde::ser::Serialize, +/// { +/// Ok(ObjectBox(serde_json::to_value(t)?)) +/// } +/// +/// pub fn to_concrete(self) -> Result +/// where +/// T: Object + serde::de::DeserializeOwned, +/// { +/// serde_json::from_value(self.0) +/// } +/// +/// pub fn is_type(&self, kind: impl std::fmt::Display) -> bool { +/// self.0["type"] == kind.to_string() +/// } +/// +/// pub fn type(&self) -> Option<&str> { +/// match self.0["type"] { +/// serde_json::Value::String(ref s) -> Some(s), +/// _ => None, +/// } +/// } +/// } +#[proc_macro_attribute] +pub fn wrapper_type(_: TokenStream, input: TokenStream) -> TokenStream { + let input: syn::ItemTrait = syn::parse(input).unwrap(); + let trait_name = input.ident.clone(); + let type_name = Ident::new(&format!("{}Box", trait_name), trait_name.span()); + + let tokens = quote! { + #input + + #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] + #[serde(transparent)] + pub struct #type_name(pub serde_json::Value); + + impl #type_name { + /// Create the wrapper type from a concrete type + pub fn from_concrete(t: T) -> Result + where + T: #trait_name + serde::ser::Serialize, + { + Ok(#type_name(serde_json::to_value(t)?)) + } + + /// Attempt to deserialize the wrapper type to a concrete type + pub fn to_concrete(self) -> Result + where + T: #trait_name + serde::de::DeserializeOwned, + { + serde_json::from_value(self.0) + } + + /// Return whether the given wrapper type is expected. + /// + /// For example + /// ```ignore + /// use activitystreams::object::{ + /// kind::ImageType, + /// apub::Image, + /// }; + /// if my_wrapper_type.is_kind(ImageType) { + /// let image = my_wrapper_type.to_concrete::()?; + /// ... + /// } + /// ``` + pub fn is_kind(&self, kind: impl std::fmt::Display) -> bool { + self.0["type"] == kind.to_string() + } + + /// Return the kind of wrapper type, if present + /// + /// Example + /// ```ignore + /// match my_wrapper_type.kind() { + /// Some("Image") => { + /// let image = my_wrapper_type.to_concrete::()?; + /// ... + /// } + /// _ => ..., + /// } + /// ``` + pub fn kind(&self) -> Option<&str> { + match self.0["type"] { + serde_json::Value::String(ref s) => Some(s), + _ => None, + } + } + } + }; + + tokens.into() +} + /// Derive implementations Serialize and Deserialize for a constant string Struct type /// /// ```ignore /// /// Derive Serialize and Deserialize such that MyStruct becomes the "MyType" string /// #[derive(Clone, Debug, UnitString)] -/// #[activitystreams(MyType)] +/// #[unit_string(MyType)] /// pub struct MyStruct; /// /// // usage /// let _: HashMap = serde_json::from_str(r#"{"type":"MyType"}"#)?; /// ``` -#[proc_macro_derive(UnitString, attributes(activitystreams))] +#[proc_macro_derive(UnitString, attributes(unit_string))] pub fn unit_string(input: TokenStream) -> TokenStream { let input: DeriveInput = syn::parse(input).unwrap(); @@ -240,7 +341,7 @@ pub fn unit_string(input: TokenStream) -> TokenStream { .path .segments .last() - .map(|segment| segment.ident == Ident::new("activitystreams", segment.ident.span())) + .map(|segment| segment.ident == "unit_string") .unwrap_or(false) }) .unwrap() @@ -302,10 +403,19 @@ pub fn unit_string(input: TokenStream) -> TokenStream { } }; + let display = quote! { + impl std::fmt::Display for #name { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + write!(f, "{}", #value) + } + } + }; + let c = quote! { #serialize #visitor #deserialize + #display }; c.into() diff --git a/examples/de.rs b/examples/de.rs new file mode 100644 index 0000000..c02732f --- /dev/null +++ b/examples/de.rs @@ -0,0 +1,55 @@ +use activitystreams::{ + collection::apub::OrderedCollection, + object::{streams::Page, ObjectBox}, +}; +use anyhow::Error; + +fn main() -> Result<(), Error> { + let collection_json = r#"{ + "type": "OrderedCollection", + "id": "http://lemmy_alpha:8540/federation/c/main", + "context": "https://www.w3.org/ns/activitystreams", + "items": [ + { + "type": "Page", + "id": "http://lemmy_alpha:8540/federation/post/2", + "attributedTo": "http://lemmy_alpha:8540/federation/u/2", + "content": "test", + "context": "https://www.w3.org/ns/activitystreams", + "name": "test", + "published": "2020-03-13T00:14:41.188634+00:00" + }, + { + "type": "Page", + "id": "http://lemmy_alpha:8540/federation/post/1", + "attributedTo": "http://lemmy_alpha:8540/federation/u/2", + "context": "https://www.w3.org/ns/activitystreams", + "name": "test", + "published": "2020-03-13T00:13:56.311479+00:00" + } + ], + "totalItems": 2 + }"#; + + let page_json = r#"{ + "type": "Page", + "id": "http://lemmy_alpha:8540/federation/post/2", + "attributedTo": "http://lemmy_alpha:8540/federation/u/2", + "content": "test", + "name": "test", + "published": "2020-03-13T00:14:41.188634+00:00" + }"#; + + let page: Page = serde_json::from_str(page_json)?; + println!("{:#?}", page); + let obox: ObjectBox = page.into(); + println!("{:#?}", obox); + let obox_string = serde_json::to_string(&obox)?; + println!("{}", obox_string); + let obox: ObjectBox = serde_json::from_str(&obox_string)?; + println!("{:#?}", obox); + let collection: OrderedCollection = serde_json::from_str(collection_json)?; + println!("{:#?}", collection); + + Ok(()) +} diff --git a/src/activity/apub.rs b/src/activity/apub.rs index 4d3eed9..2b1f049 100644 --- a/src/activity/apub.rs +++ b/src/activity/apub.rs @@ -20,10 +20,13 @@ //! Activity traits and types use crate::{ - activity::{kind::*, properties::*, Activity, IntransitiveActivity}, + activity::{ + kind::*, properties::*, Activity, ActivityBox, IntransitiveActivity, + IntransitiveActivityBox, + }, object::{ properties::{ApObjectProperties, ObjectProperties}, - Object, + Object, ObjectBox, }, PropRefs, }; @@ -35,24 +38,26 @@ use serde::{Deserialize, Serialize}; /// object has been accepted. #[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] +#[prop_refs(Object)] +#[prop_refs(Activity)] pub struct Accept { #[serde(rename = "type")] kind: AcceptType, #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub accept_props: AcceptProperties, #[serde(flatten)] - #[activitystreams(Object)] + #[prop_refs] pub object_props: ObjectProperties, #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub ap_object_props: ApObjectProperties, #[serde(flatten)] - #[activitystreams(Activity)] + #[prop_refs] pub activity_props: ActivityProperties, } @@ -63,24 +68,26 @@ pub struct Accept { /// originated. #[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] +#[prop_refs(Object)] +#[prop_refs(Activity)] pub struct Add { #[serde(rename = "type")] kind: AddType, #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub add_props: AddProperties, #[serde(flatten)] - #[activitystreams(Object)] + #[prop_refs] pub object_props: ObjectProperties, #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub ap_object_props: ApObjectProperties, #[serde(flatten)] - #[activitystreams(Activity)] + #[prop_refs] pub activity_props: ActivityProperties, } @@ -89,24 +96,26 @@ pub struct Add { /// If the origin or target are not specified, either can be determined by context. #[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] +#[prop_refs(Object)] +#[prop_refs(Activity)] pub struct AMove { #[serde(rename = "type")] kind: MoveType, #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub move_props: MoveProperties, #[serde(flatten)] - #[activitystreams(Object)] + #[prop_refs] pub object_props: ObjectProperties, #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub ap_object_props: ApObjectProperties, #[serde(flatten)] - #[activitystreams(Activity)] + #[prop_refs] pub activity_props: ActivityProperties, } @@ -115,24 +124,26 @@ pub struct AMove { /// The origin typically has no defined meaning. #[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] +#[prop_refs(Object)] +#[prop_refs(Activity)] pub struct Announce { #[serde(rename = "type")] kind: AnnounceType, #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub announce_props: AnnounceProperties, #[serde(flatten)] - #[activitystreams(Object)] + #[prop_refs] pub object_props: ObjectProperties, #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub ap_object_props: ApObjectProperties, #[serde(flatten)] - #[activitystreams(Activity)] + #[prop_refs] pub activity_props: ActivityProperties, } @@ -142,29 +153,30 @@ pub struct Announce { /// typically has no defined meaning. #[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] +#[prop_refs(Object)] +#[prop_refs(Activity)] +#[prop_refs(IntransitiveActivity)] pub struct Arrive { #[serde(rename = "type")] kind: ArriveType, #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub arrive_props: ArriveProperties, #[serde(flatten)] - #[activitystreams(Object)] + #[prop_refs] pub object_props: ObjectProperties, #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub ap_object_props: ApObjectProperties, #[serde(flatten)] - #[activitystreams(Activity)] + #[prop_refs] pub activity_props: ActivityProperties, } -impl IntransitiveActivity for Arrive {} - /// Indicates that the actor is blocking the object. /// /// Blocking is a stronger form of Ignore. The typical use is to support social systems that allow @@ -172,48 +184,52 @@ impl IntransitiveActivity for Arrive {} /// defined meaning. #[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] +#[prop_refs(Object)] +#[prop_refs(Activity)] pub struct Block { #[serde(rename = "type")] kind: BlockType, #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub block_props: BlockProperties, #[serde(flatten)] - #[activitystreams(Object)] + #[prop_refs] pub object_props: ObjectProperties, #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub ap_object_props: ApObjectProperties, #[serde(flatten)] - #[activitystreams(Activity)] + #[prop_refs] pub activity_props: ActivityProperties, } /// Indicates that the actor has created the object. #[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] +#[prop_refs(Object)] +#[prop_refs(Activity)] pub struct Create { #[serde(rename = "type")] kind: CreateType, #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub create_props: CreateProperties, #[serde(flatten)] - #[activitystreams(Object)] + #[prop_refs] pub object_props: ObjectProperties, #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub ap_object_props: ApObjectProperties, #[serde(flatten)] - #[activitystreams(Activity)] + #[prop_refs] pub activity_props: ActivityProperties, } @@ -222,48 +238,52 @@ pub struct Create { /// If specified, the origin indicates the context from which the object was deleted. #[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] +#[prop_refs(Object)] +#[prop_refs(Activity)] pub struct Delete { #[serde(rename = "type")] kind: DeleteType, #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub delete_props: DeleteProperties, #[serde(flatten)] - #[activitystreams(Object)] + #[prop_refs] pub object_props: ObjectProperties, #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub ap_object_props: ApObjectProperties, #[serde(flatten)] - #[activitystreams(Activity)] + #[prop_refs] pub activity_props: ActivityProperties, } /// Indicates that the actor dislikes the object. #[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] +#[prop_refs(Object)] +#[prop_refs(Activity)] pub struct Dislike { #[serde(rename = "type")] kind: DislikeType, #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub dislike_props: DislikeProperties, #[serde(flatten)] - #[activitystreams(Object)] + #[prop_refs] pub object_props: ObjectProperties, #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub ap_object_props: ApObjectProperties, #[serde(flatten)] - #[activitystreams(Activity)] + #[prop_refs] pub activity_props: ActivityProperties, } @@ -273,24 +293,26 @@ pub struct Dislike { /// inappropriate for any number of reasons. #[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] +#[prop_refs(Object)] +#[prop_refs(Activity)] pub struct Flag { #[serde(rename = "type")] kind: FlagType, #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub flag_props: FlagProperties, #[serde(flatten)] - #[activitystreams(Object)] + #[prop_refs] pub object_props: ObjectProperties, #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub ap_object_props: ApObjectProperties, #[serde(flatten)] - #[activitystreams(Activity)] + #[prop_refs] pub activity_props: ActivityProperties, } @@ -301,24 +323,26 @@ pub struct Flag { /// no defined meaning. #[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] +#[prop_refs(Object)] +#[prop_refs(Activity)] pub struct Follow { #[serde(rename = "type")] kind: FollowType, #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub follow_props: FollowProperties, #[serde(flatten)] - #[activitystreams(Object)] + #[prop_refs] pub object_props: ObjectProperties, #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub ap_object_props: ApObjectProperties, #[serde(flatten)] - #[activitystreams(Activity)] + #[prop_refs] pub activity_props: ActivityProperties, } @@ -327,24 +351,26 @@ pub struct Follow { /// The target and origin typically have no defined meaning. #[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] +#[prop_refs(Object)] +#[prop_refs(Activity)] pub struct Ignore { #[serde(rename = "type")] kind: IgnoreType, #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub ignore_props: IgnoreProperties, #[serde(flatten)] - #[activitystreams(Object)] + #[prop_refs] pub object_props: ObjectProperties, #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub ap_object_props: ApObjectProperties, #[serde(flatten)] - #[activitystreams(Activity)] + #[prop_refs] pub activity_props: ActivityProperties, } @@ -352,24 +378,26 @@ pub struct Ignore { /// target. #[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] +#[prop_refs(Object)] +#[prop_refs(Activity)] pub struct Invite { #[serde(rename = "type")] kind: InviteType, #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub invite_props: InviteProperties, #[serde(flatten)] - #[activitystreams(Object)] + #[prop_refs] pub object_props: ObjectProperties, #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub ap_object_props: ApObjectProperties, #[serde(flatten)] - #[activitystreams(Activity)] + #[prop_refs] pub activity_props: ActivityProperties, } @@ -378,24 +406,26 @@ pub struct Invite { /// The target and origin typically have no defined meaning #[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] +#[prop_refs(Object)] +#[prop_refs(Activity)] pub struct Join { #[serde(rename = "type")] kind: JoinType, #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub join_props: JoinProperties, #[serde(flatten)] - #[activitystreams(Object)] + #[prop_refs] pub object_props: ObjectProperties, #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub ap_object_props: ApObjectProperties, #[serde(flatten)] - #[activitystreams(Activity)] + #[prop_refs] pub activity_props: ActivityProperties, } @@ -404,24 +434,26 @@ pub struct Join { /// The target and origin typically have no meaning. #[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] +#[prop_refs(Object)] +#[prop_refs(Activity)] pub struct Leave { #[serde(rename = "type")] kind: LeaveType, #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub leave_props: LeaveProperties, #[serde(flatten)] - #[activitystreams(Object)] + #[prop_refs] pub object_props: ObjectProperties, #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub ap_object_props: ApObjectProperties, #[serde(flatten)] - #[activitystreams(Activity)] + #[prop_refs] pub activity_props: ActivityProperties, } @@ -430,48 +462,52 @@ pub struct Leave { /// The target and origin typically have no defined meaning. #[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] +#[prop_refs(Object)] +#[prop_refs(Activity)] pub struct Like { #[serde(rename = "type")] kind: LikeType, #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub like_props: LikeProperties, #[serde(flatten)] - #[activitystreams(Object)] + #[prop_refs] pub object_props: ObjectProperties, #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub ap_object_props: ApObjectProperties, #[serde(flatten)] - #[activitystreams(Activity)] + #[prop_refs] pub activity_props: ActivityProperties, } /// Indicates that the actor has listened to the object. #[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] +#[prop_refs(Object)] +#[prop_refs(Activity)] pub struct Listen { #[serde(rename = "type")] kind: ListenType, #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub listen_props: ListenProperties, #[serde(flatten)] - #[activitystreams(Object)] + #[prop_refs] pub object_props: ObjectProperties, #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub ap_object_props: ApObjectProperties, #[serde(flatten)] - #[activitystreams(Activity)] + #[prop_refs] pub activity_props: ActivityProperties, } @@ -480,24 +516,26 @@ pub struct Listen { /// If specified, the target indicates the entity to which the object is being offered. #[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] +#[prop_refs(Object)] +#[prop_refs(Activity)] pub struct Offer { #[serde(rename = "type")] kind: OfferType, #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub offer_props: OfferProperties, #[serde(flatten)] - #[activitystreams(Object)] + #[prop_refs] pub object_props: ObjectProperties, #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub ap_object_props: ApObjectProperties, #[serde(flatten)] - #[activitystreams(Activity)] + #[prop_refs] pub activity_props: ActivityProperties, } @@ -511,50 +549,53 @@ pub struct Offer { /// Question object MUST NOT have both properties. #[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] +#[prop_refs(Object)] +#[prop_refs(Activity)] +#[prop_refs(IntransitiveActivity)] pub struct Question { #[serde(rename = "type")] kind: QuestionType, #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub question_props: QuestionProperties, #[serde(flatten)] - #[activitystreams(Object)] + #[prop_refs] pub object_props: ObjectProperties, #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub ap_object_props: ApObjectProperties, #[serde(flatten)] - #[activitystreams(Activity)] + #[prop_refs] pub activity_props: ActivityProperties, } -impl IntransitiveActivity for Question {} - /// Indicates that the actor has read the object. #[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] +#[prop_refs(Object)] +#[prop_refs(Activity)] pub struct Read { #[serde(rename = "type")] kind: ReadType, #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub read_props: ReadProperties, #[serde(flatten)] - #[activitystreams(Object)] + #[prop_refs] pub object_props: ObjectProperties, #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub ap_object_props: ApObjectProperties, #[serde(flatten)] - #[activitystreams(Activity)] + #[prop_refs] pub activity_props: ActivityProperties, } @@ -563,24 +604,26 @@ pub struct Read { /// The target and origin typically have no defined meaning. #[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] +#[prop_refs(Object)] +#[prop_refs(Activity)] pub struct Reject { #[serde(rename = "type")] kind: RejectType, #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub reject_props: RejectProperties, #[serde(flatten)] - #[activitystreams(Object)] + #[prop_refs] pub object_props: ObjectProperties, #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub ap_object_props: ApObjectProperties, #[serde(flatten)] - #[activitystreams(Activity)] + #[prop_refs] pub activity_props: ActivityProperties, } @@ -589,72 +632,78 @@ pub struct Reject { /// If specified, the origin indicates the context from which the object is being removed. #[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] +#[prop_refs(Object)] +#[prop_refs(Activity)] pub struct Remove { #[serde(rename = "type")] kind: RemoveType, #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub remove_props: RemoveProperties, #[serde(flatten)] - #[activitystreams(Object)] + #[prop_refs] pub object_props: ObjectProperties, #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub ap_object_props: ApObjectProperties, #[serde(flatten)] - #[activitystreams(Activity)] + #[prop_refs] pub activity_props: ActivityProperties, } /// A specialization of Accept indicating that the acceptance is tentative. #[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] +#[prop_refs(Object)] +#[prop_refs(Activity)] pub struct TentativeAccept { #[serde(rename = "type")] kind: TentativeAcceptType, #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub tentative_accept_props: TentativeAcceptProperties, #[serde(flatten)] - #[activitystreams(Object)] + #[prop_refs] pub object_props: ObjectProperties, #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub ap_object_props: ApObjectProperties, #[serde(flatten)] - #[activitystreams(Activity)] + #[prop_refs] pub activity_props: ActivityProperties, } /// A specialization of Reject in which the rejection is considered tentative. #[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] +#[prop_refs(Object)] +#[prop_refs(Activity)] pub struct TentativeReject { #[serde(rename = "type")] kind: TentativeRejectType, #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub tentative_reject_props: TentativeRejectProperties, #[serde(flatten)] - #[activitystreams(Object)] + #[prop_refs] pub object_props: ObjectProperties, #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub ap_object_props: ApObjectProperties, #[serde(flatten)] - #[activitystreams(Activity)] + #[prop_refs] pub activity_props: ActivityProperties, } @@ -664,29 +713,30 @@ pub struct TentativeReject { /// origin are not specified, either can be determined by context. #[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] +#[prop_refs(Object)] +#[prop_refs(Activity)] +#[prop_refs(IntransitiveActivity)] pub struct Travel { #[serde(rename = "type")] kind: TravelType, #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub travel_props: TravelProperties, #[serde(flatten)] - #[activitystreams(Object)] + #[prop_refs] pub object_props: ObjectProperties, #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub ap_object_props: ApObjectProperties, #[serde(flatten)] - #[activitystreams(Activity)] + #[prop_refs] pub activity_props: ActivityProperties, } -impl IntransitiveActivity for Travel {} - /// Indicates that the actor is undoing the object. /// /// In most cases, the object will be an Activity describing some previously performed action (for @@ -696,24 +746,26 @@ impl IntransitiveActivity for Travel {} /// The target and origin typically have no defined meaning. #[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] +#[prop_refs(Object)] +#[prop_refs(Activity)] pub struct Undo { #[serde(rename = "type")] kind: UndoType, #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub undo_props: UndoProperties, #[serde(flatten)] - #[activitystreams(Object)] + #[prop_refs] pub object_props: ObjectProperties, #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub ap_object_props: ApObjectProperties, #[serde(flatten)] - #[activitystreams(Activity)] + #[prop_refs] pub activity_props: ActivityProperties, } @@ -725,47 +777,51 @@ pub struct Undo { /// The target and origin typically have no defined meaning. #[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] +#[prop_refs(Object)] +#[prop_refs(Activity)] pub struct Update { #[serde(rename = "type")] kind: UpdateType, #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub update_props: UpdateProperties, #[serde(flatten)] - #[activitystreams(Object)] + #[prop_refs] pub object_props: ObjectProperties, #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub ap_object_props: ApObjectProperties, #[serde(flatten)] - #[activitystreams(Activity)] + #[prop_refs] pub activity_props: ActivityProperties, } /// Indicates that the actor has viewed the object. #[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] +#[prop_refs(Object)] +#[prop_refs(Activity)] pub struct View { #[serde(rename = "type")] kind: ViewType, #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub view_props: ViewProperties, #[serde(flatten)] - #[activitystreams(Object)] + #[prop_refs] pub object_props: ObjectProperties, #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub ap_object_props: ApObjectProperties, #[serde(flatten)] - #[activitystreams(Activity)] + #[prop_refs] pub activity_props: ActivityProperties, } diff --git a/src/activity/kind.rs b/src/activity/kind.rs index 71b9b84..3763f3f 100644 --- a/src/activity/kind.rs +++ b/src/activity/kind.rs @@ -22,113 +22,113 @@ use crate::UnitString; #[derive(Clone, Debug, Default, UnitString)] -#[activitystreams(Accept)] +#[unit_string(Accept)] pub struct AcceptType; #[derive(Clone, Debug, Default, UnitString)] -#[activitystreams(Add)] +#[unit_string(Add)] pub struct AddType; #[derive(Clone, Debug, Default, UnitString)] -#[activitystreams(Move)] +#[unit_string(Move)] pub struct MoveType; #[derive(Clone, Debug, Default, UnitString)] -#[activitystreams(Announce)] +#[unit_string(Announce)] pub struct AnnounceType; #[derive(Clone, Debug, Default, UnitString)] -#[activitystreams(Arrive)] +#[unit_string(Arrive)] pub struct ArriveType; #[derive(Clone, Debug, Default, UnitString)] -#[activitystreams(Block)] +#[unit_string(Block)] pub struct BlockType; #[derive(Clone, Debug, Default, UnitString)] -#[activitystreams(Create)] +#[unit_string(Create)] pub struct CreateType; #[derive(Clone, Debug, Default, UnitString)] -#[activitystreams(Delete)] +#[unit_string(Delete)] pub struct DeleteType; #[derive(Clone, Debug, Default, UnitString)] -#[activitystreams(Dislike)] +#[unit_string(Dislike)] pub struct DislikeType; #[derive(Clone, Debug, Default, UnitString)] -#[activitystreams(Flag)] +#[unit_string(Flag)] pub struct FlagType; #[derive(Clone, Debug, Default, UnitString)] -#[activitystreams(Follow)] +#[unit_string(Follow)] pub struct FollowType; #[derive(Clone, Debug, Default, UnitString)] -#[activitystreams(Ignore)] +#[unit_string(Ignore)] pub struct IgnoreType; #[derive(Clone, Debug, Default, UnitString)] -#[activitystreams(Invite)] +#[unit_string(Invite)] pub struct InviteType; #[derive(Clone, Debug, Default, UnitString)] -#[activitystreams(Join)] +#[unit_string(Join)] pub struct JoinType; #[derive(Clone, Debug, Default, UnitString)] -#[activitystreams(Leave)] +#[unit_string(Leave)] pub struct LeaveType; #[derive(Clone, Debug, Default, UnitString)] -#[activitystreams(Like)] +#[unit_string(Like)] pub struct LikeType; #[derive(Clone, Debug, Default, UnitString)] -#[activitystreams(Listen)] +#[unit_string(Listen)] pub struct ListenType; #[derive(Clone, Debug, Default, UnitString)] -#[activitystreams(Offer)] +#[unit_string(Offer)] pub struct OfferType; #[derive(Clone, Debug, Default, UnitString)] -#[activitystreams(Question)] +#[unit_string(Question)] pub struct QuestionType; #[derive(Clone, Debug, Default, UnitString)] -#[activitystreams(Real)] +#[unit_string(Real)] pub struct ReadType; #[derive(Clone, Debug, Default, UnitString)] -#[activitystreams(Reject)] +#[unit_string(Reject)] pub struct RejectType; #[derive(Clone, Debug, Default, UnitString)] -#[activitystreams(Remove)] +#[unit_string(Remove)] pub struct RemoveType; #[derive(Clone, Debug, Default, UnitString)] -#[activitystreams(TentativeAccept)] +#[unit_string(TentativeAccept)] pub struct TentativeAcceptType; #[derive(Clone, Debug, Default, UnitString)] -#[activitystreams(TentativeReject)] +#[unit_string(TentativeReject)] pub struct TentativeRejectType; #[derive(Clone, Debug, Default, UnitString)] -#[activitystreams(Travel)] +#[unit_string(Travel)] pub struct TravelType; #[derive(Clone, Debug, Default, UnitString)] -#[activitystreams(Undo)] +#[unit_string(Undo)] pub struct UndoType; #[derive(Clone, Debug, Default, UnitString)] -#[activitystreams(Update)] +#[unit_string(Update)] pub struct UpdateType; #[derive(Clone, Debug, Default, UnitString)] -#[activitystreams(View)] +#[unit_string(View)] pub struct ViewType; diff --git a/src/activity/mod.rs b/src/activity/mod.rs index a31ae68..8b96656 100644 --- a/src/activity/mod.rs +++ b/src/activity/mod.rs @@ -26,6 +26,9 @@ pub mod properties; #[cfg(feature = "types")] pub mod streams; +#[cfg(feature = "types")] +use crate::wrapper_type; + use crate::object::Object; /// An Activity is a subtype of `Object` that describes some form of action that may happen, is @@ -34,10 +37,12 @@ use crate::object::Object; /// The `Activity` type itself serves as an abstract base type for all types of activities. It is /// important to note that the `Activity` type itself does not carry any specific semantics about /// the kind of action being taken. +#[cfg_attr(feature = "types", wrapper_type)] pub trait Activity: Object {} /// Instances of `IntransitiveActivity` are a subtype of `Activity` representing intransitive /// actions. /// /// The `object` property is therefore inappropriate for these activities. +#[cfg_attr(feature = "types", wrapper_type)] pub trait IntransitiveActivity: Activity {} diff --git a/src/activity/streams.rs b/src/activity/streams.rs new file mode 100644 index 0000000..75cfdcd --- /dev/null +++ b/src/activity/streams.rs @@ -0,0 +1,850 @@ +/* + * This file is part of ActivityStreams. + * + * Copyright © 2020 Riley Trautman + * + * ActivityStreams is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ActivityStreams is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ActivityStreams. If not, see . + */ + +use crate::{ + activity::{ + kind::*, properties::*, Activity, ActivityBox, IntransitiveActivity, + IntransitiveActivityBox, + }, + object::{properties::ObjectProperties, Object, ObjectBox}, + PropRefs, +}; +use serde::{Deserialize, Serialize}; + +/// Indicates that the actor accepts the object. +/// +/// The target property can be used in certain circumstances to indicate the context into which the +/// object has been accepted. +#[derive(Clone, Debug, Default, Deserialize, PropRefs, Serialize)] +#[serde(rename_all = "camelCase")] +#[prop_refs(Object)] +#[prop_refs(Activity)] +pub struct Accept { + #[serde(rename = "type")] + #[serde(alias = "objectType")] + #[serde(alias = "verb")] + pub kind: AcceptType, + + /// Adds all valid accept properties to this struct + #[serde(flatten)] + #[prop_refs] + pub accept_props: AcceptProperties, + + /// Adds all valid object properties to this struct + #[serde(flatten)] + #[prop_refs] + pub object_props: ObjectProperties, + + /// Adds all valid activity properties to this struct + #[serde(flatten)] + #[prop_refs] + pub activity_props: ActivityProperties, +} + +/// Indicates that the actor has added the object to the target. +/// +/// If the target property is not explicitly specified, the target would need to be determined +/// implicitly by context. The origin can be used to identify the context from which the object +/// originated. +#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] +#[serde(rename_all = "camelCase")] +#[prop_refs(Object)] +#[prop_refs(Activity)] +pub struct Add { + #[serde(rename = "type")] + #[serde(alias = "objectType")] + #[serde(alias = "verb")] + pub kind: AddType, + + /// Adds all valid add properties to this struct + #[serde(flatten)] + #[prop_refs] + pub add_props: AddProperties, + + /// Adds all valid object properties to this struct + #[serde(flatten)] + #[prop_refs] + pub object_props: ObjectProperties, + + /// Adds all valid activity properties to this struct + #[serde(flatten)] + #[prop_refs] + pub activity_props: ActivityProperties, +} + +/// Indicates that the actor has moved object from origin to target. +/// +/// If the origin or target are not specified, either can be determined by context. +#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] +#[serde(rename_all = "camelCase")] +#[prop_refs(Object)] +#[prop_refs(Activity)] +pub struct AMove { + #[serde(rename = "type")] + #[serde(alias = "objectType")] + #[serde(alias = "verb")] + pub kind: MoveType, + + /// Adds all valid move properties to this struct + #[serde(flatten)] + #[prop_refs] + pub move_props: MoveProperties, + + /// Adds all valid object properties to this struct + #[serde(flatten)] + #[prop_refs] + pub object_props: ObjectProperties, + + /// Adds all valid activity properties to this struct + #[serde(flatten)] + #[prop_refs] + pub activity_props: ActivityProperties, +} + +/// Indicates that the actor is calling the target's attention the object. +/// +/// The origin typically has no defined meaning. +#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] +#[serde(rename_all = "camelCase")] +#[prop_refs(Object)] +#[prop_refs(Activity)] +pub struct Announce { + #[serde(rename = "type")] + #[serde(alias = "objectType")] + #[serde(alias = "verb")] + pub kind: AnnounceType, + + /// Adds all valid announce properties to this struct + #[serde(flatten)] + #[prop_refs] + pub announce_props: AnnounceProperties, + + /// Adds all valid object properties to this struct + #[serde(flatten)] + #[prop_refs] + pub object_props: ObjectProperties, + + /// Adds all valid activity properties to this struct + #[serde(flatten)] + #[prop_refs] + pub activity_props: ActivityProperties, +} + +/// An IntransitiveActivity that indicates that the actor has arrived at the location. +/// +/// The origin can be used to identify the context from which the actor originated. The target +/// typically has no defined meaning. +#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] +#[serde(rename_all = "camelCase")] +#[prop_refs(Object)] +#[prop_refs(Activity)] +#[prop_refs(IntransitiveActivity)] +pub struct Arrive { + #[serde(rename = "type")] + #[serde(alias = "objectType")] + #[serde(alias = "verb")] + pub kind: ArriveType, + + /// Adds all valid arrive properties to this struct + #[serde(flatten)] + #[prop_refs] + pub arrive_props: ArriveProperties, + + /// Adds all valid object properties to this struct + #[serde(flatten)] + #[prop_refs] + pub object_props: ObjectProperties, + + /// Adds all valid activity properties to this struct + #[serde(flatten)] + #[prop_refs] + pub activity_props: ActivityProperties, +} + +/// Indicates that the actor is blocking the object. +/// +/// Blocking is a stronger form of Ignore. The typical use is to support social systems that allow +/// one user to block activities or content of other users. The target and origin typically have no +/// defined meaning. +#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] +#[serde(rename_all = "camelCase")] +#[prop_refs(Object)] +#[prop_refs(Activity)] +pub struct Block { + #[serde(rename = "type")] + #[serde(alias = "objectType")] + #[serde(alias = "verb")] + pub kind: BlockType, + + /// Adds all valid block properties to this struct + #[serde(flatten)] + #[prop_refs] + pub block_props: BlockProperties, + + /// Adds all valid object properties to this struct + #[serde(flatten)] + #[prop_refs] + pub object_props: ObjectProperties, + + /// Adds all valid activity properties to this struct + #[serde(flatten)] + #[prop_refs] + pub activity_props: ActivityProperties, +} + +/// Indicates that the actor has created the object. +#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] +#[serde(rename_all = "camelCase")] +#[prop_refs(Object)] +#[prop_refs(Activity)] +pub struct Create { + #[serde(rename = "type")] + #[serde(alias = "objectType")] + #[serde(alias = "verb")] + pub kind: CreateType, + + /// Adds all valid create properties to this struct + #[serde(flatten)] + #[prop_refs] + pub create_props: CreateProperties, + + /// Adds all valid object properties to this struct + #[serde(flatten)] + #[prop_refs] + pub object_props: ObjectProperties, + + /// Adds all valid activity properties to this struct + #[serde(flatten)] + #[prop_refs] + pub activity_props: ActivityProperties, +} + +/// Indicates that the actor has deleted the object. +/// +/// If specified, the origin indicates the context from which the object was deleted. +#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] +#[serde(rename_all = "camelCase")] +#[prop_refs(Object)] +#[prop_refs(Activity)] +pub struct Delete { + #[serde(rename = "type")] + #[serde(alias = "objectType")] + #[serde(alias = "verb")] + pub kind: DeleteType, + + /// Adds all valid delete properties to this struct + #[serde(flatten)] + #[prop_refs] + pub delete_props: DeleteProperties, + + /// Adds all valid object properties to this struct + #[serde(flatten)] + #[prop_refs] + pub object_props: ObjectProperties, + + /// Adds all valid activity properties to this struct + #[serde(flatten)] + #[prop_refs] + pub activity_props: ActivityProperties, +} + +/// Indicates that the actor dislikes the object. +#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] +#[serde(rename_all = "camelCase")] +#[prop_refs(Object)] +#[prop_refs(Activity)] +pub struct Dislike { + #[serde(rename = "type")] + #[serde(alias = "objectType")] + #[serde(alias = "verb")] + pub kind: DislikeType, + + /// Adds all valid dislike properties to this struct + #[serde(flatten)] + #[prop_refs] + pub dislike_props: DislikeProperties, + + /// Adds all valid object properties to this struct + #[serde(flatten)] + #[prop_refs] + pub object_props: ObjectProperties, + + /// Adds all valid activity properties to this struct + #[serde(flatten)] + #[prop_refs] + pub activity_props: ActivityProperties, +} + +/// Indicates that the actor is "flagging" the object. +/// +/// Flagging is defined in the sense common to many social platforms as reporting content as being +/// inappropriate for any number of reasons. +#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] +#[serde(rename_all = "camelCase")] +#[prop_refs(Object)] +#[prop_refs(Activity)] +pub struct Flag { + #[serde(rename = "type")] + #[serde(alias = "objectType")] + #[serde(alias = "verb")] + pub kind: FlagType, + + /// Adds all valid flag properties to this struct + #[serde(flatten)] + #[prop_refs] + pub flag_props: FlagProperties, + + /// Adds all valid object properties to this struct + #[serde(flatten)] + #[prop_refs] + pub object_props: ObjectProperties, + + /// Adds all valid activity properties to this struct + #[serde(flatten)] + #[prop_refs] + pub activity_props: ActivityProperties, +} + +/// Indicates that the actor is "following" the object. +/// +/// Following is defined in the sense typically used within Social systems in which the actor is +/// interested in any activity performed by or on the object. The target and origin typically have +/// no defined meaning. +#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] +#[serde(rename_all = "camelCase")] +#[prop_refs(Object)] +#[prop_refs(Activity)] +pub struct Follow { + #[serde(rename = "type")] + #[serde(alias = "objectType")] + #[serde(alias = "verb")] + pub kind: FollowType, + + /// Adds all valid follow properties to this struct + #[serde(flatten)] + #[prop_refs] + pub follow_props: FollowProperties, + + /// Adds all valid object properties to this struct + #[serde(flatten)] + #[prop_refs] + pub object_props: ObjectProperties, + + /// Adds all valid activity properties to this struct + #[serde(flatten)] + #[prop_refs] + pub activity_props: ActivityProperties, +} + +/// Indicates that the actor is ignoring the object. +/// +/// The target and origin typically have no defined meaning. +#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] +#[serde(rename_all = "camelCase")] +#[prop_refs(Object)] +#[prop_refs(Activity)] +pub struct Ignore { + #[serde(rename = "type")] + #[serde(alias = "objectType")] + #[serde(alias = "verb")] + pub kind: IgnoreType, + + /// Adds all valid ignore properties to this struct + #[serde(flatten)] + #[prop_refs] + pub ignore_props: IgnoreProperties, + + /// Adds all valid object properties to this struct + #[serde(flatten)] + #[prop_refs] + pub object_props: ObjectProperties, + + /// Adds all valid activity properties to this struct + #[serde(flatten)] + #[prop_refs] + pub activity_props: ActivityProperties, +} + +/// A specialization of Offer in which the actor is extending an invitation for the object to the +/// target. +#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] +#[serde(rename_all = "camelCase")] +#[prop_refs(Object)] +#[prop_refs(Activity)] +pub struct Invite { + #[serde(rename = "type")] + #[serde(alias = "objectType")] + #[serde(alias = "verb")] + pub kind: InviteType, + + /// Adds all valid invite properties to this struct + #[serde(flatten)] + #[prop_refs] + pub invite_props: InviteProperties, + + /// Adds all valid object properties to this struct + #[serde(flatten)] + #[prop_refs] + pub object_props: ObjectProperties, + + /// Adds all valid activity properties to this struct + #[serde(flatten)] + #[prop_refs] + pub activity_props: ActivityProperties, +} + +/// Indicates that the actor has joined the object. +/// +/// The target and origin typically have no defined meaning +#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] +#[serde(rename_all = "camelCase")] +#[prop_refs(Object)] +#[prop_refs(Activity)] +pub struct Join { + #[serde(rename = "type")] + #[serde(alias = "objectType")] + #[serde(alias = "verb")] + pub kind: JoinType, + + /// Adds all valid join properties to this struct + #[serde(flatten)] + #[prop_refs] + pub join_props: JoinProperties, + + /// Adds all valid object properties to this struct + #[serde(flatten)] + #[prop_refs] + pub object_props: ObjectProperties, + + /// Adds all valid activity properties to this struct + #[serde(flatten)] + #[prop_refs] + pub activity_props: ActivityProperties, +} + +/// Indicates that the actor has left the object. +/// +/// The target and origin typically have no meaning. +#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] +#[serde(rename_all = "camelCase")] +#[prop_refs(Object)] +#[prop_refs(Activity)] +pub struct Leave { + #[serde(rename = "type")] + #[serde(alias = "objectType")] + #[serde(alias = "verb")] + pub kind: LeaveType, + + /// Adds all valid leave properties to this struct + #[serde(flatten)] + #[prop_refs] + pub leave_props: LeaveProperties, + + /// Adds all valid object properties to this struct + #[serde(flatten)] + #[prop_refs] + pub object_props: ObjectProperties, + + /// Adds all valid activity properties to this struct + #[serde(flatten)] + #[prop_refs] + pub activity_props: ActivityProperties, +} + +/// Indicates that the actor likes, recommends or endorses the object. +/// +/// The target and origin typically have no defined meaning. +#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] +#[serde(rename_all = "camelCase")] +#[prop_refs(Object)] +#[prop_refs(Activity)] +pub struct Like { + #[serde(rename = "type")] + #[serde(alias = "objectType")] + #[serde(alias = "verb")] + pub kind: LikeType, + + /// Adds all valid like properties to this struct + #[serde(flatten)] + #[prop_refs] + pub like_props: LikeProperties, + + /// Adds all valid object properties to this struct + #[serde(flatten)] + #[prop_refs] + pub object_props: ObjectProperties, + + /// Adds all valid activity properties to this struct + #[serde(flatten)] + #[prop_refs] + pub activity_props: ActivityProperties, +} + +/// Indicates that the actor has listened to the object. +#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] +#[serde(rename_all = "camelCase")] +#[prop_refs(Object)] +#[prop_refs(Activity)] +pub struct Listen { + #[serde(rename = "type")] + #[serde(alias = "objectType")] + #[serde(alias = "verb")] + kind: ListenType, + + /// Adds all valid listen properties to this struct + #[serde(flatten)] + #[prop_refs] + pub listen_props: ListenProperties, + + /// Adds all valid object properties to this struct + #[serde(flatten)] + #[prop_refs] + pub object_props: ObjectProperties, + + /// Adds all valid activity properties to this struct + #[serde(flatten)] + #[prop_refs] + pub activity_props: ActivityProperties, +} + +/// Indicates that the actor is offering the object. +/// +/// If specified, the target indicates the entity to which the object is being offered. +#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] +#[serde(rename_all = "camelCase")] +#[prop_refs(Object)] +#[prop_refs(Activity)] +pub struct Offer { + #[serde(rename = "type")] + #[serde(alias = "objectType")] + #[serde(alias = "verb")] + pub kind: OfferType, + + /// Adds all valid object properties to this struct + #[serde(flatten)] + #[prop_refs] + pub offer_props: OfferProperties, + + /// Adds all valid object properties to this struct + #[serde(flatten)] + #[prop_refs] + pub object_props: ObjectProperties, + + /// Adds all valid activity properties to this struct + #[serde(flatten)] + #[prop_refs] + pub activity_props: ActivityProperties, +} + +/// Represents a question being asked. +/// +/// Question objects are an extension of IntransitiveActivity. That is, the Question object is an +/// Activity, but the direct object is the question itself and therefore it would not contain an +/// object property. +/// +/// Either of the anyOf and oneOf properties MAY be used to express possible answers, but a +/// Question object MUST NOT have both properties. +#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] +#[serde(rename_all = "camelCase")] +#[prop_refs(Object)] +#[prop_refs(Activity)] +#[prop_refs(IntransitiveActivity)] +pub struct Question { + #[serde(rename = "type")] + #[serde(alias = "objectType")] + #[serde(alias = "verb")] + pub kind: QuestionType, + + /// Adds all valid question properties to this struct + #[serde(flatten)] + #[prop_refs] + pub question_props: QuestionProperties, + + /// Adds all valid object properties to this struct + #[serde(flatten)] + #[prop_refs] + pub object_props: ObjectProperties, + + /// Adds all valid activity properties to this struct + #[serde(flatten)] + #[prop_refs] + pub activity_props: ActivityProperties, +} + +/// Indicates that the actor has read the object. +#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] +#[serde(rename_all = "camelCase")] +#[prop_refs(Object)] +#[prop_refs(Activity)] +pub struct Read { + #[serde(rename = "type")] + #[serde(alias = "objectType")] + #[serde(alias = "verb")] + pub kind: ReadType, + + /// Adds all valid read properties to this struct + #[serde(flatten)] + #[prop_refs] + pub read_props: ReadProperties, + + /// Adds all valid object properties to this struct + #[serde(flatten)] + #[prop_refs] + pub object_props: ObjectProperties, + + /// Adds all valid activity properties to this struct + #[serde(flatten)] + #[prop_refs] + pub activity_props: ActivityProperties, +} + +/// Indicates that the actor is rejecting the object. +/// +/// The target and origin typically have no defined meaning. +#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] +#[serde(rename_all = "camelCase")] +#[prop_refs(Object)] +#[prop_refs(Activity)] +pub struct Reject { + #[serde(rename = "type")] + #[serde(alias = "objectType")] + #[serde(alias = "verb")] + pub kind: RejectType, + + /// Adds all valid reject properties to this struct + #[serde(flatten)] + #[prop_refs] + pub reject_props: RejectProperties, + + /// Adds all valid object properties to this struct + #[serde(flatten)] + #[prop_refs] + pub object_props: ObjectProperties, + + /// Adds all valid activity properties to this struct + #[serde(flatten)] + #[prop_refs] + pub activity_props: ActivityProperties, +} + +/// Indicates that the actor is removing the object. +/// +/// If specified, the origin indicates the context from which the object is being removed. +#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] +#[serde(rename_all = "camelCase")] +#[prop_refs(Object)] +#[prop_refs(Activity)] +pub struct Remove { + #[serde(rename = "type")] + #[serde(alias = "objectType")] + #[serde(alias = "verb")] + pub kind: RemoveType, + + /// Adds all valid remove properties to this struct + #[serde(flatten)] + #[prop_refs] + pub remove_props: RemoveProperties, + + /// Adds all valid object properties to this struct + #[serde(flatten)] + #[prop_refs] + pub object_props: ObjectProperties, + + /// Adds all valid activity properties to this struct + #[serde(flatten)] + #[prop_refs] + pub activity_props: ActivityProperties, +} + +/// A specialization of Accept indicating that the acceptance is tentative. +#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] +#[serde(rename_all = "camelCase")] +#[prop_refs(Object)] +#[prop_refs(Activity)] +pub struct TentativeAccept { + #[serde(rename = "type")] + #[serde(alias = "objectType")] + #[serde(alias = "verb")] + pub kind: TentativeAcceptType, + + /// Adds all valid tentative_accept properties to this struct + #[serde(flatten)] + #[prop_refs] + pub tentative_accept_props: TentativeAcceptProperties, + + /// Adds all valid object properties to this struct + #[serde(flatten)] + #[prop_refs] + pub object_props: ObjectProperties, + + /// Adds all valid activity properties to this struct + #[serde(flatten)] + #[prop_refs] + pub activity_props: ActivityProperties, +} + +/// A specialization of Reject in which the rejection is considered tentative. +#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] +#[serde(rename_all = "camelCase")] +#[prop_refs(Object)] +#[prop_refs(Activity)] +pub struct TentativeReject { + #[serde(rename = "type")] + #[serde(alias = "objectType")] + #[serde(alias = "verb")] + pub kind: TentativeRejectType, + + /// Adds all valid tentative_reject properties to this struct + #[serde(flatten)] + #[prop_refs] + pub tentative_reject_props: TentativeRejectProperties, + + /// Adds all valid object properties to this struct + #[serde(flatten)] + #[prop_refs] + pub object_props: ObjectProperties, + + /// Adds all valid activity properties to this struct + #[serde(flatten)] + #[prop_refs] + pub activity_props: ActivityProperties, +} + +/// Indicates that the actor is traveling to target from origin. +/// +/// Travel is an IntransitiveObject whose actor specifies the direct object. If the target or +/// origin are not specified, either can be determined by context. +#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] +#[serde(rename_all = "camelCase")] +#[prop_refs(Object)] +#[prop_refs(Activity)] +#[prop_refs(IntransitiveActivity)] +pub struct Travel { + #[serde(rename = "type")] + #[serde(alias = "objectType")] + #[serde(alias = "verb")] + pub kind: TravelType, + + /// Adds all valid travel properties to this struct + #[serde(flatten)] + #[prop_refs] + pub travel_props: TravelProperties, + + /// Adds all valid object properties to this struct + #[serde(flatten)] + #[prop_refs] + pub object_props: ObjectProperties, + + /// Adds all valid activity properties to this struct + #[serde(flatten)] + #[prop_refs] + pub activity_props: ActivityProperties, +} + +/// Indicates that the actor is undoing the object. +/// +/// In most cases, the object will be an Activity describing some previously performed action (for +/// instance, a person may have previously "liked" an article but, for whatever reason, might +/// choose to undo that like at some later point in time). +/// +/// The target and origin typically have no defined meaning. +#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] +#[serde(rename_all = "camelCase")] +#[prop_refs(Object)] +#[prop_refs(Activity)] +pub struct Undo { + #[serde(rename = "type")] + #[serde(alias = "objectType")] + #[serde(alias = "verb")] + pub kind: UndoType, + + /// Adds all valid undo properties to this struct + #[serde(flatten)] + #[prop_refs] + pub undo_props: UndoProperties, + + /// Adds all valid object properties to this struct + #[serde(flatten)] + #[prop_refs] + pub object_props: ObjectProperties, + + /// Adds all valid activity properties to this struct + #[serde(flatten)] + #[prop_refs] + pub activity_props: ActivityProperties, +} + +/// Indicates that the actor has updated the object. +/// +/// Note, however, that this vocabulary does not define a mechanism for describing the actual set +/// of modifications made to object. +/// +/// The target and origin typically have no defined meaning. +#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] +#[serde(rename_all = "camelCase")] +#[prop_refs(Object)] +#[prop_refs(Activity)] +pub struct Update { + #[serde(rename = "type")] + #[serde(alias = "objectType")] + #[serde(alias = "verb")] + pub kind: UpdateType, + + /// Adds all valid update properties to this struct + #[serde(flatten)] + #[prop_refs] + pub update_props: UpdateProperties, + + /// Adds all valid object properties to this struct + #[serde(flatten)] + #[prop_refs] + pub object_props: ObjectProperties, + + /// Adds all valid activity properties to this struct + #[serde(flatten)] + #[prop_refs] + pub activity_props: ActivityProperties, +} + +/// Indicates that the actor has viewed the object. +#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] +#[serde(rename_all = "camelCase")] +#[prop_refs(Object)] +#[prop_refs(Activity)] +pub struct View { + #[serde(rename = "type")] + #[serde(alias = "objectType")] + #[serde(alias = "verb")] + pub kind: ViewType, + + /// Adds all valid view properties to this struct + #[serde(flatten)] + #[prop_refs] + pub view_props: ViewProperties, + + /// Adds all valid object properties to this struct + #[serde(flatten)] + #[prop_refs] + pub object_props: ObjectProperties, + + /// Adds all valid activity properties to this struct + #[serde(flatten)] + #[prop_refs] + pub activity_props: ActivityProperties, +} diff --git a/src/activity/streams/accept.rs b/src/activity/streams/accept.rs deleted file mode 100644 index 39249f1..0000000 --- a/src/activity/streams/accept.rs +++ /dev/null @@ -1,57 +0,0 @@ -/* - * This file is part of ActivityStreams. - * - * Copyright © 2020 Riley Trautman - * - * ActivityStreams is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * ActivityStreams is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with ActivityStreams. If not, see . - */ - -use crate::{ - activity::{ - kind::AcceptType, - properties::{AcceptProperties, ActivityProperties}, - Activity, - }, - object::{properties::ObjectProperties, Object}, - PropRefs, -}; -use serde::{Deserialize, Serialize}; - -/// Indicates that the actor accepts the object. -/// -/// The target property can be used in certain circumstances to indicate the context into which the -/// object has been accepted. -#[derive(Clone, Debug, Default, Deserialize, PropRefs, Serialize)] -#[serde(rename_all = "camelCase")] -pub struct Accept { - #[serde(rename = "type")] - #[serde(alias = "objectType")] - #[serde(alias = "verb")] - pub kind: AcceptType, - - /// Adds all valid accept properties to this struct - #[serde(flatten)] - #[activitystreams(None)] - pub accept_props: AcceptProperties, - - /// Adds all valid object properties to this struct - #[serde(flatten)] - #[activitystreams(Object)] - pub object_props: ObjectProperties, - - /// Adds all valid activity properties to this struct - #[serde(flatten)] - #[activitystreams(Activity)] - pub activity_props: ActivityProperties, -} diff --git a/src/activity/streams/add.rs b/src/activity/streams/add.rs deleted file mode 100644 index e6423d9..0000000 --- a/src/activity/streams/add.rs +++ /dev/null @@ -1,58 +0,0 @@ -/* - * This file is part of ActivityStreams. - * - * Copyright © 2020 Riley Trautman - * - * ActivityStreams is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * ActivityStreams is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with ActivityStreams. If not, see . - */ - -use crate::{ - activity::{ - kind::AddType, - properties::{ActivityProperties, AddProperties}, - Activity, - }, - object::{properties::ObjectProperties, Object}, - PropRefs, -}; -use serde::{Deserialize, Serialize}; - -/// Indicates that the actor has added the object to the target. -/// -/// If the target property is not explicitly specified, the target would need to be determined -/// implicitly by context. The origin can be used to identify the context from which the object -/// originated. -#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] -#[serde(rename_all = "camelCase")] -pub struct Add { - #[serde(rename = "type")] - #[serde(alias = "objectType")] - #[serde(alias = "verb")] - pub kind: AddType, - - /// Adds all valid add properties to this struct - #[serde(flatten)] - #[activitystreams(None)] - pub add_props: AddProperties, - - /// Adds all valid object properties to this struct - #[serde(flatten)] - #[activitystreams(Object)] - pub object_props: ObjectProperties, - - /// Adds all valid activity properties to this struct - #[serde(flatten)] - #[activitystreams(Activity)] - pub activity_props: ActivityProperties, -} diff --git a/src/activity/streams/amove.rs b/src/activity/streams/amove.rs deleted file mode 100644 index 9f3828f..0000000 --- a/src/activity/streams/amove.rs +++ /dev/null @@ -1,56 +0,0 @@ -/* - * This file is part of ActivityStreams. - * - * Copyright © 2020 Riley Trautman - * - * ActivityStreams is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * ActivityStreams is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with ActivityStreams. If not, see . - */ - -use crate::{ - activity::{ - kind::MoveType, - properties::{ActivityProperties, MoveProperties}, - Activity, - }, - object::{properties::ObjectProperties, Object}, - PropRefs, -}; -use serde::{Deserialize, Serialize}; - -/// Indicates that the actor has moved object from origin to target. -/// -/// If the origin or target are not specified, either can be determined by context. -#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] -#[serde(rename_all = "camelCase")] -pub struct AMove { - #[serde(rename = "type")] - #[serde(alias = "objectType")] - #[serde(alias = "verb")] - pub kind: MoveType, - - /// Adds all valid move properties to this struct - #[serde(flatten)] - #[activitystreams(None)] - pub move_props: MoveProperties, - - /// Adds all valid object properties to this struct - #[serde(flatten)] - #[activitystreams(Object)] - pub object_props: ObjectProperties, - - /// Adds all valid activity properties to this struct - #[serde(flatten)] - #[activitystreams(Activity)] - pub activity_props: ActivityProperties, -} diff --git a/src/activity/streams/announce.rs b/src/activity/streams/announce.rs deleted file mode 100644 index 07bba03..0000000 --- a/src/activity/streams/announce.rs +++ /dev/null @@ -1,56 +0,0 @@ -/* - * This file is part of ActivityStreams. - * - * Copyright © 2020 Riley Trautman - * - * ActivityStreams is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * ActivityStreams is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with ActivityStreams. If not, see . - */ - -use crate::{ - activity::{ - kind::AnnounceType, - properties::{ActivityProperties, AnnounceProperties}, - Activity, - }, - object::{properties::ObjectProperties, Object}, - PropRefs, -}; -use serde::{Deserialize, Serialize}; - -/// Indicates that the actor is calling the target's attention the object. -/// -/// The origin typically has no defined meaning. -#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] -#[serde(rename_all = "camelCase")] -pub struct Announce { - #[serde(rename = "type")] - #[serde(alias = "objectType")] - #[serde(alias = "verb")] - pub kind: AnnounceType, - - /// Adds all valid announce properties to this struct - #[serde(flatten)] - #[activitystreams(None)] - pub announce_props: AnnounceProperties, - - /// Adds all valid object properties to this struct - #[serde(flatten)] - #[activitystreams(Object)] - pub object_props: ObjectProperties, - - /// Adds all valid activity properties to this struct - #[serde(flatten)] - #[activitystreams(Activity)] - pub activity_props: ActivityProperties, -} diff --git a/src/activity/streams/arrive.rs b/src/activity/streams/arrive.rs deleted file mode 100644 index 97a6685..0000000 --- a/src/activity/streams/arrive.rs +++ /dev/null @@ -1,59 +0,0 @@ -/* - * This file is part of ActivityStreams. - * - * Copyright © 2020 Riley Trautman - * - * ActivityStreams is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * ActivityStreams is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with ActivityStreams. If not, see . - */ - -use crate::{ - activity::{ - kind::ArriveType, - properties::{ActivityProperties, ArriveProperties}, - Activity, IntransitiveActivity, - }, - object::{properties::ObjectProperties, Object}, - PropRefs, -}; -use serde::{Deserialize, Serialize}; - -/// An IntransitiveActivity that indicates that the actor has arrived at the location. -/// -/// The origin can be used to identify the context from which the actor originated. The target -/// typically has no defined meaning. -#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] -#[serde(rename_all = "camelCase")] -pub struct Arrive { - #[serde(rename = "type")] - #[serde(alias = "objectType")] - #[serde(alias = "verb")] - pub kind: ArriveType, - - /// Adds all valid arrive properties to this struct - #[serde(flatten)] - #[activitystreams(None)] - pub arrive_props: ArriveProperties, - - /// Adds all valid object properties to this struct - #[serde(flatten)] - #[activitystreams(Object)] - pub object_props: ObjectProperties, - - /// Adds all valid activity properties to this struct - #[serde(flatten)] - #[activitystreams(Activity)] - pub activity_props: ActivityProperties, -} - -impl IntransitiveActivity for Arrive {} diff --git a/src/activity/streams/block.rs b/src/activity/streams/block.rs deleted file mode 100644 index b00c1a8..0000000 --- a/src/activity/streams/block.rs +++ /dev/null @@ -1,58 +0,0 @@ -/* - * This file is part of ActivityStreams. - * - * Copyright © 2020 Riley Trautman - * - * ActivityStreams is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * ActivityStreams is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with ActivityStreams. If not, see . - */ - -use crate::{ - activity::{ - kind::BlockType, - properties::{ActivityProperties, BlockProperties}, - Activity, - }, - object::{properties::ObjectProperties, Object}, - PropRefs, -}; -use serde::{Deserialize, Serialize}; - -/// Indicates that the actor is blocking the object. -/// -/// Blocking is a stronger form of Ignore. The typical use is to support social systems that allow -/// one user to block activities or content of other users. The target and origin typically have no -/// defined meaning. -#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] -#[serde(rename_all = "camelCase")] -pub struct Block { - #[serde(rename = "type")] - #[serde(alias = "objectType")] - #[serde(alias = "verb")] - pub kind: BlockType, - - /// Adds all valid block properties to this struct - #[serde(flatten)] - #[activitystreams(None)] - pub block_props: BlockProperties, - - /// Adds all valid object properties to this struct - #[serde(flatten)] - #[activitystreams(Object)] - pub object_props: ObjectProperties, - - /// Adds all valid activity properties to this struct - #[serde(flatten)] - #[activitystreams(Activity)] - pub activity_props: ActivityProperties, -} diff --git a/src/activity/streams/create.rs b/src/activity/streams/create.rs deleted file mode 100644 index d35a704..0000000 --- a/src/activity/streams/create.rs +++ /dev/null @@ -1,54 +0,0 @@ -/* - * This file is part of ActivityStreams. - * - * Copyright © 2020 Riley Trautman - * - * ActivityStreams is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * ActivityStreams is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with ActivityStreams. If not, see . - */ - -use crate::{ - activity::{ - kind::CreateType, - properties::{ActivityProperties, CreateProperties}, - Activity, - }, - object::{properties::ObjectProperties, Object}, - PropRefs, -}; -use serde::{Deserialize, Serialize}; - -/// Indicates that the actor has created the object. -#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] -#[serde(rename_all = "camelCase")] -pub struct Create { - #[serde(rename = "type")] - #[serde(alias = "objectType")] - #[serde(alias = "verb")] - pub kind: CreateType, - - /// Adds all valid create properties to this struct - #[serde(flatten)] - #[activitystreams(None)] - pub create_props: CreateProperties, - - /// Adds all valid object properties to this struct - #[serde(flatten)] - #[activitystreams(Object)] - pub object_props: ObjectProperties, - - /// Adds all valid activity properties to this struct - #[serde(flatten)] - #[activitystreams(Activity)] - pub activity_props: ActivityProperties, -} diff --git a/src/activity/streams/delete.rs b/src/activity/streams/delete.rs deleted file mode 100644 index f044926..0000000 --- a/src/activity/streams/delete.rs +++ /dev/null @@ -1,56 +0,0 @@ -/* - * This file is part of ActivityStreams. - * - * Copyright © 2020 Riley Trautman - * - * ActivityStreams is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * ActivityStreams is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with ActivityStreams. If not, see . - */ - -use crate::{ - activity::{ - kind::DeleteType, - properties::{ActivityProperties, DeleteProperties}, - Activity, - }, - object::{properties::ObjectProperties, Object}, - PropRefs, -}; -use serde::{Deserialize, Serialize}; - -/// Indicates that the actor has deleted the object. -/// -/// If specified, the origin indicates the context from which the object was deleted. -#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] -#[serde(rename_all = "camelCase")] -pub struct Delete { - #[serde(rename = "type")] - #[serde(alias = "objectType")] - #[serde(alias = "verb")] - pub kind: DeleteType, - - /// Adds all valid delete properties to this struct - #[serde(flatten)] - #[activitystreams(None)] - pub delete_props: DeleteProperties, - - /// Adds all valid object properties to this struct - #[serde(flatten)] - #[activitystreams(Object)] - pub object_props: ObjectProperties, - - /// Adds all valid activity properties to this struct - #[serde(flatten)] - #[activitystreams(Activity)] - pub activity_props: ActivityProperties, -} diff --git a/src/activity/streams/dislike.rs b/src/activity/streams/dislike.rs deleted file mode 100644 index 3db7a8b..0000000 --- a/src/activity/streams/dislike.rs +++ /dev/null @@ -1,54 +0,0 @@ -/* - * This file is part of ActivityStreams. - * - * Copyright © 2020 Riley Trautman - * - * ActivityStreams is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * ActivityStreams is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with ActivityStreams. If not, see . - */ - -use crate::{ - activity::{ - kind::DislikeType, - properties::{ActivityProperties, DislikeProperties}, - Activity, - }, - object::{properties::ObjectProperties, Object}, - PropRefs, -}; -use serde::{Deserialize, Serialize}; - -/// Indicates that the actor dislikes the object. -#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] -#[serde(rename_all = "camelCase")] -pub struct Dislike { - #[serde(rename = "type")] - #[serde(alias = "objectType")] - #[serde(alias = "verb")] - pub kind: DislikeType, - - /// Adds all valid dislike properties to this struct - #[serde(flatten)] - #[activitystreams(None)] - pub dislike_props: DislikeProperties, - - /// Adds all valid object properties to this struct - #[serde(flatten)] - #[activitystreams(Object)] - pub object_props: ObjectProperties, - - /// Adds all valid activity properties to this struct - #[serde(flatten)] - #[activitystreams(Activity)] - pub activity_props: ActivityProperties, -} diff --git a/src/activity/streams/flag.rs b/src/activity/streams/flag.rs deleted file mode 100644 index 2d224fe..0000000 --- a/src/activity/streams/flag.rs +++ /dev/null @@ -1,57 +0,0 @@ -/* - * This file is part of ActivityStreams. - * - * Copyright © 2020 Riley Trautman - * - * ActivityStreams is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * ActivityStreams is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with ActivityStreams. If not, see . - */ - -use crate::{ - activity::{ - kind::FlagType, - properties::{ActivityProperties, FlagProperties}, - Activity, - }, - object::{properties::ObjectProperties, Object}, - PropRefs, -}; -use serde::{Deserialize, Serialize}; - -/// Indicates that the actor is "flagging" the object. -/// -/// Flagging is defined in the sense common to many social platforms as reporting content as being -/// inappropriate for any number of reasons. -#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] -#[serde(rename_all = "camelCase")] -pub struct Flag { - #[serde(rename = "type")] - #[serde(alias = "objectType")] - #[serde(alias = "verb")] - pub kind: FlagType, - - /// Adds all valid flag properties to this struct - #[serde(flatten)] - #[activitystreams(None)] - pub flag_props: FlagProperties, - - /// Adds all valid object properties to this struct - #[serde(flatten)] - #[activitystreams(Object)] - pub object_props: ObjectProperties, - - /// Adds all valid activity properties to this struct - #[serde(flatten)] - #[activitystreams(Activity)] - pub activity_props: ActivityProperties, -} diff --git a/src/activity/streams/follow.rs b/src/activity/streams/follow.rs deleted file mode 100644 index be2af65..0000000 --- a/src/activity/streams/follow.rs +++ /dev/null @@ -1,58 +0,0 @@ -/* - * This file is part of ActivityStreams. - * - * Copyright © 2020 Riley Trautman - * - * ActivityStreams is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * ActivityStreams is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with ActivityStreams. If not, see . - */ - -use crate::{ - activity::{ - kind::FollowType, - properties::{ActivityProperties, FollowProperties}, - Activity, - }, - object::{properties::ObjectProperties, Object}, - PropRefs, -}; -use serde::{Deserialize, Serialize}; - -/// Indicates that the actor is "following" the object. -/// -/// Following is defined in the sense typically used within Social systems in which the actor is -/// interested in any activity performed by or on the object. The target and origin typically have -/// no defined meaning. -#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] -#[serde(rename_all = "camelCase")] -pub struct Follow { - #[serde(rename = "type")] - #[serde(alias = "objectType")] - #[serde(alias = "verb")] - pub kind: FollowType, - - /// Adds all valid follow properties to this struct - #[serde(flatten)] - #[activitystreams(None)] - pub follow_props: FollowProperties, - - /// Adds all valid object properties to this struct - #[serde(flatten)] - #[activitystreams(Object)] - pub object_props: ObjectProperties, - - /// Adds all valid activity properties to this struct - #[serde(flatten)] - #[activitystreams(Activity)] - pub activity_props: ActivityProperties, -} diff --git a/src/activity/streams/ignore.rs b/src/activity/streams/ignore.rs deleted file mode 100644 index 6f9aff0..0000000 --- a/src/activity/streams/ignore.rs +++ /dev/null @@ -1,56 +0,0 @@ -/* - * This file is part of ActivityStreams. - * - * Copyright © 2020 Riley Trautman - * - * ActivityStreams is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * ActivityStreams is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with ActivityStreams. If not, see . - */ - -use crate::{ - activity::{ - kind::IgnoreType, - properties::{ActivityProperties, IgnoreProperties}, - Activity, - }, - object::{properties::ObjectProperties, Object}, - PropRefs, -}; -use serde::{Deserialize, Serialize}; - -/// Indicates that the actor is ignoring the object. -/// -/// The target and origin typically have no defined meaning. -#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] -#[serde(rename_all = "camelCase")] -pub struct Ignore { - #[serde(rename = "type")] - #[serde(alias = "objectType")] - #[serde(alias = "verb")] - pub kind: IgnoreType, - - /// Adds all valid ignore properties to this struct - #[serde(flatten)] - #[activitystreams(None)] - pub ignore_props: IgnoreProperties, - - /// Adds all valid object properties to this struct - #[serde(flatten)] - #[activitystreams(Object)] - pub object_props: ObjectProperties, - - /// Adds all valid activity properties to this struct - #[serde(flatten)] - #[activitystreams(Activity)] - pub activity_props: ActivityProperties, -} diff --git a/src/activity/streams/invite.rs b/src/activity/streams/invite.rs deleted file mode 100644 index 9c7387e..0000000 --- a/src/activity/streams/invite.rs +++ /dev/null @@ -1,55 +0,0 @@ -/* - * This file is part of ActivityStreams. - * - * Copyright © 2020 Riley Trautman - * - * ActivityStreams is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * ActivityStreams is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with ActivityStreams. If not, see . - */ - -use crate::{ - activity::{ - kind::InviteType, - properties::{ActivityProperties, InviteProperties}, - Activity, - }, - object::{properties::ObjectProperties, Object}, - PropRefs, -}; -use serde::{Deserialize, Serialize}; - -/// A specialization of Offer in which the actor is extending an invitation for the object to the -/// target. -#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] -#[serde(rename_all = "camelCase")] -pub struct Invite { - #[serde(rename = "type")] - #[serde(alias = "objectType")] - #[serde(alias = "verb")] - pub kind: InviteType, - - /// Adds all valid invite properties to this struct - #[serde(flatten)] - #[activitystreams(None)] - pub invite_props: InviteProperties, - - /// Adds all valid object properties to this struct - #[serde(flatten)] - #[activitystreams(Object)] - pub object_props: ObjectProperties, - - /// Adds all valid activity properties to this struct - #[serde(flatten)] - #[activitystreams(Activity)] - pub activity_props: ActivityProperties, -} diff --git a/src/activity/streams/join.rs b/src/activity/streams/join.rs deleted file mode 100644 index 85f145b..0000000 --- a/src/activity/streams/join.rs +++ /dev/null @@ -1,56 +0,0 @@ -/* - * This file is part of ActivityStreams. - * - * Copyright © 2020 Riley Trautman - * - * ActivityStreams is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * ActivityStreams is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with ActivityStreams. If not, see . - */ - -use crate::{ - activity::{ - kind::JoinType, - properties::{ActivityProperties, JoinProperties}, - Activity, - }, - object::{properties::ObjectProperties, Object}, - PropRefs, -}; -use serde::{Deserialize, Serialize}; - -/// Indicates that the actor has joined the object. -/// -/// The target and origin typically have no defined meaning -#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] -#[serde(rename_all = "camelCase")] -pub struct Join { - #[serde(rename = "type")] - #[serde(alias = "objectType")] - #[serde(alias = "verb")] - pub kind: JoinType, - - /// Adds all valid join properties to this struct - #[serde(flatten)] - #[activitystreams(None)] - pub join_props: JoinProperties, - - /// Adds all valid object properties to this struct - #[serde(flatten)] - #[activitystreams(Object)] - pub object_props: ObjectProperties, - - /// Adds all valid activity properties to this struct - #[serde(flatten)] - #[activitystreams(Activity)] - pub activity_props: ActivityProperties, -} diff --git a/src/activity/streams/leave.rs b/src/activity/streams/leave.rs deleted file mode 100644 index 127b3f7..0000000 --- a/src/activity/streams/leave.rs +++ /dev/null @@ -1,56 +0,0 @@ -/* - * This file is part of ActivityStreams. - * - * Copyright © 2020 Riley Trautman - * - * ActivityStreams is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * ActivityStreams is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with ActivityStreams. If not, see . - */ - -use crate::{ - activity::{ - kind::LeaveType, - properties::{ActivityProperties, LeaveProperties}, - Activity, - }, - object::{properties::ObjectProperties, Object}, - PropRefs, -}; -use serde::{Deserialize, Serialize}; - -/// Indicates that the actor has left the object. -/// -/// The target and origin typically have no meaning. -#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] -#[serde(rename_all = "camelCase")] -pub struct Leave { - #[serde(rename = "type")] - #[serde(alias = "objectType")] - #[serde(alias = "verb")] - pub kind: LeaveType, - - /// Adds all valid leave properties to this struct - #[serde(flatten)] - #[activitystreams(None)] - pub leave_props: LeaveProperties, - - /// Adds all valid object properties to this struct - #[serde(flatten)] - #[activitystreams(Object)] - pub object_props: ObjectProperties, - - /// Adds all valid activity properties to this struct - #[serde(flatten)] - #[activitystreams(Activity)] - pub activity_props: ActivityProperties, -} diff --git a/src/activity/streams/like.rs b/src/activity/streams/like.rs deleted file mode 100644 index 7620167..0000000 --- a/src/activity/streams/like.rs +++ /dev/null @@ -1,56 +0,0 @@ -/* - * This file is part of ActivityStreams. - * - * Copyright © 2020 Riley Trautman - * - * ActivityStreams is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * ActivityStreams is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with ActivityStreams. If not, see . - */ - -use crate::{ - activity::{ - kind::LikeType, - properties::{ActivityProperties, LikeProperties}, - Activity, - }, - object::{properties::ObjectProperties, Object}, - PropRefs, -}; -use serde::{Deserialize, Serialize}; - -/// Indicates that the actor likes, recommends or endorses the object. -/// -/// The target and origin typically have no defined meaning. -#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] -#[serde(rename_all = "camelCase")] -pub struct Like { - #[serde(rename = "type")] - #[serde(alias = "objectType")] - #[serde(alias = "verb")] - pub kind: LikeType, - - /// Adds all valid like properties to this struct - #[serde(flatten)] - #[activitystreams(None)] - pub like_props: LikeProperties, - - /// Adds all valid object properties to this struct - #[serde(flatten)] - #[activitystreams(Object)] - pub object_props: ObjectProperties, - - /// Adds all valid activity properties to this struct - #[serde(flatten)] - #[activitystreams(Activity)] - pub activity_props: ActivityProperties, -} diff --git a/src/activity/streams/listen.rs b/src/activity/streams/listen.rs deleted file mode 100644 index 4cc888b..0000000 --- a/src/activity/streams/listen.rs +++ /dev/null @@ -1,54 +0,0 @@ -/* - * This file is part of ActivityStreams. - * - * Copyright © 2020 Riley Trautman - * - * ActivityStreams is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * ActivityStreams is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with ActivityStreams. If not, see . - */ - -use crate::{ - activity::{ - kind::ListenType, - properties::{ActivityProperties, ListenProperties}, - Activity, - }, - object::{properties::ObjectProperties, Object}, - PropRefs, -}; -use serde::{Deserialize, Serialize}; - -/// Indicates that the actor has listened to the object. -#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] -#[serde(rename_all = "camelCase")] -pub struct Listen { - #[serde(rename = "type")] - #[serde(alias = "objectType")] - #[serde(alias = "verb")] - kind: ListenType, - - /// Adds all valid listen properties to this struct - #[serde(flatten)] - #[activitystreams(None)] - pub listen_props: ListenProperties, - - /// Adds all valid object properties to this struct - #[serde(flatten)] - #[activitystreams(Object)] - pub object_props: ObjectProperties, - - /// Adds all valid activity properties to this struct - #[serde(flatten)] - #[activitystreams(Activity)] - pub activity_props: ActivityProperties, -} diff --git a/src/activity/streams/mod.rs b/src/activity/streams/mod.rs deleted file mode 100644 index 3034011..0000000 --- a/src/activity/streams/mod.rs +++ /dev/null @@ -1,56 +0,0 @@ -/* - * This file is part of ActivityStreams. - * - * Copyright © 2020 Riley Trautman - * - * ActivityStreams is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * ActivityStreams is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with ActivityStreams. If not, see . - */ - -mod accept; -mod add; -mod amove; -mod announce; -mod arrive; -mod block; -mod create; -mod delete; -mod dislike; -mod flag; -mod follow; -mod ignore; -mod invite; -mod join; -mod leave; -mod like; -mod listen; -mod offer; -mod question; -mod read; -mod reject; -mod remove; -mod tentative_accept; -mod tentative_reject; -mod travel; -mod undo; -mod update; -mod view; - -pub use self::{ - accept::Accept, add::Add, amove::AMove, announce::Announce, arrive::Arrive, block::Block, - create::Create, delete::Delete, dislike::Dislike, flag::Flag, follow::Follow, ignore::Ignore, - invite::Invite, join::Join, leave::Leave, like::Like, listen::Listen, offer::Offer, - question::Question, read::Read, reject::Reject, remove::Remove, - tentative_accept::TentativeAccept, tentative_reject::TentativeReject, travel::Travel, - undo::Undo, update::Update, view::View, -}; diff --git a/src/activity/streams/offer.rs b/src/activity/streams/offer.rs deleted file mode 100644 index 58b350d..0000000 --- a/src/activity/streams/offer.rs +++ /dev/null @@ -1,56 +0,0 @@ -/* - * This file is part of ActivityStreams. - * - * Copyright © 2020 Riley Trautman - * - * ActivityStreams is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * ActivityStreams is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with ActivityStreams. If not, see . - */ - -use crate::{ - activity::{ - kind::OfferType, - properties::{ActivityProperties, OfferProperties}, - Activity, - }, - object::{properties::ObjectProperties, Object}, - PropRefs, -}; -use serde::{Deserialize, Serialize}; - -/// Indicates that the actor is offering the object. -/// -/// If specified, the target indicates the entity to which the object is being offered. -#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] -#[serde(rename_all = "camelCase")] -pub struct Offer { - #[serde(rename = "type")] - #[serde(alias = "objectType")] - #[serde(alias = "verb")] - pub kind: OfferType, - - /// Adds all valid object properties to this struct - #[serde(flatten)] - #[activitystreams(None)] - pub offer_props: OfferProperties, - - /// Adds all valid object properties to this struct - #[serde(flatten)] - #[activitystreams(Object)] - pub object_props: ObjectProperties, - - /// Adds all valid activity properties to this struct - #[serde(flatten)] - #[activitystreams(Activity)] - pub activity_props: ActivityProperties, -} diff --git a/src/activity/streams/question.rs b/src/activity/streams/question.rs deleted file mode 100644 index 86bb1be..0000000 --- a/src/activity/streams/question.rs +++ /dev/null @@ -1,63 +0,0 @@ -/* - * This file is part of ActivityStreams. - * - * Copyright © 2020 Riley Trautman - * - * ActivityStreams is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * ActivityStreams is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with ActivityStreams. If not, see . - */ - -use crate::{ - activity::{ - kind::QuestionType, - properties::{ActivityProperties, QuestionProperties}, - Activity, IntransitiveActivity, - }, - object::{properties::ObjectProperties, Object}, - PropRefs, -}; -use serde::{Deserialize, Serialize}; - -/// Represents a question being asked. -/// -/// Question objects are an extension of IntransitiveActivity. That is, the Question object is an -/// Activity, but the direct object is the question itself and therefore it would not contain an -/// object property. -/// -/// Either of the anyOf and oneOf properties MAY be used to express possible answers, but a -/// Question object MUST NOT have both properties. -#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] -#[serde(rename_all = "camelCase")] -pub struct Question { - #[serde(rename = "type")] - #[serde(alias = "objectType")] - #[serde(alias = "verb")] - pub kind: QuestionType, - - /// Adds all valid question properties to this struct - #[serde(flatten)] - #[activitystreams(None)] - pub question_props: QuestionProperties, - - /// Adds all valid object properties to this struct - #[serde(flatten)] - #[activitystreams(Object)] - pub object_props: ObjectProperties, - - /// Adds all valid activity properties to this struct - #[serde(flatten)] - #[activitystreams(Activity)] - pub activity_props: ActivityProperties, -} - -impl IntransitiveActivity for Question {} diff --git a/src/activity/streams/read.rs b/src/activity/streams/read.rs deleted file mode 100644 index 44aec15..0000000 --- a/src/activity/streams/read.rs +++ /dev/null @@ -1,54 +0,0 @@ -/* - * This file is part of ActivityStreams. - * - * Copyright © 2020 Riley Trautman - * - * ActivityStreams is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * ActivityStreams is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with ActivityStreams. If not, see . - */ - -use crate::{ - activity::{ - kind::ReadType, - properties::{ActivityProperties, ReadProperties}, - Activity, - }, - object::{properties::ObjectProperties, Object}, - PropRefs, -}; -use serde::{Deserialize, Serialize}; - -/// Indicates that the actor has read the object. -#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] -#[serde(rename_all = "camelCase")] -pub struct Read { - #[serde(rename = "type")] - #[serde(alias = "objectType")] - #[serde(alias = "verb")] - pub kind: ReadType, - - /// Adds all valid read properties to this struct - #[serde(flatten)] - #[activitystreams(None)] - pub read_props: ReadProperties, - - /// Adds all valid object properties to this struct - #[serde(flatten)] - #[activitystreams(Object)] - pub object_props: ObjectProperties, - - /// Adds all valid activity properties to this struct - #[serde(flatten)] - #[activitystreams(Activity)] - pub activity_props: ActivityProperties, -} diff --git a/src/activity/streams/reject.rs b/src/activity/streams/reject.rs deleted file mode 100644 index 3459258..0000000 --- a/src/activity/streams/reject.rs +++ /dev/null @@ -1,56 +0,0 @@ -/* - * This file is part of ActivityStreams. - * - * Copyright © 2020 Riley Trautman - * - * ActivityStreams is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * ActivityStreams is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with ActivityStreams. If not, see . - */ - -use crate::{ - activity::{ - kind::RejectType, - properties::{ActivityProperties, RejectProperties}, - Activity, - }, - object::{properties::ObjectProperties, Object}, - PropRefs, -}; -use serde::{Deserialize, Serialize}; - -/// Indicates that the actor is rejecting the object. -/// -/// The target and origin typically have no defined meaning. -#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] -#[serde(rename_all = "camelCase")] -pub struct Reject { - #[serde(rename = "type")] - #[serde(alias = "objectType")] - #[serde(alias = "verb")] - pub kind: RejectType, - - /// Adds all valid reject properties to this struct - #[serde(flatten)] - #[activitystreams(None)] - pub reject_props: RejectProperties, - - /// Adds all valid object properties to this struct - #[serde(flatten)] - #[activitystreams(Object)] - pub object_props: ObjectProperties, - - /// Adds all valid activity properties to this struct - #[serde(flatten)] - #[activitystreams(Activity)] - pub activity_props: ActivityProperties, -} diff --git a/src/activity/streams/remove.rs b/src/activity/streams/remove.rs deleted file mode 100644 index ecbf3e6..0000000 --- a/src/activity/streams/remove.rs +++ /dev/null @@ -1,56 +0,0 @@ -/* - * This file is part of ActivityStreams. - * - * Copyright © 2020 Riley Trautman - * - * ActivityStreams is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * ActivityStreams is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with ActivityStreams. If not, see . - */ - -use crate::{ - activity::{ - kind::RemoveType, - properties::{ActivityProperties, RemoveProperties}, - Activity, - }, - object::{properties::ObjectProperties, Object}, - PropRefs, -}; -use serde::{Deserialize, Serialize}; - -/// Indicates that the actor is removing the object. -/// -/// If specified, the origin indicates the context from which the object is being removed. -#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] -#[serde(rename_all = "camelCase")] -pub struct Remove { - #[serde(rename = "type")] - #[serde(alias = "objectType")] - #[serde(alias = "verb")] - pub kind: RemoveType, - - /// Adds all valid remove properties to this struct - #[serde(flatten)] - #[activitystreams(None)] - pub remove_props: RemoveProperties, - - /// Adds all valid object properties to this struct - #[serde(flatten)] - #[activitystreams(Object)] - pub object_props: ObjectProperties, - - /// Adds all valid activity properties to this struct - #[serde(flatten)] - #[activitystreams(Activity)] - pub activity_props: ActivityProperties, -} diff --git a/src/activity/streams/tentative_accept.rs b/src/activity/streams/tentative_accept.rs deleted file mode 100644 index 7847636..0000000 --- a/src/activity/streams/tentative_accept.rs +++ /dev/null @@ -1,54 +0,0 @@ -/* - * This file is part of ActivityStreams. - * - * Copyright © 2020 Riley Trautman - * - * ActivityStreams is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * ActivityStreams is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with ActivityStreams. If not, see . - */ - -use crate::{ - activity::{ - kind::TentativeAcceptType, - properties::{ActivityProperties, TentativeAcceptProperties}, - Activity, - }, - object::{properties::ObjectProperties, Object}, - PropRefs, -}; -use serde::{Deserialize, Serialize}; - -/// A specialization of Accept indicating that the acceptance is tentative. -#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] -#[serde(rename_all = "camelCase")] -pub struct TentativeAccept { - #[serde(rename = "type")] - #[serde(alias = "objectType")] - #[serde(alias = "verb")] - pub kind: TentativeAcceptType, - - /// Adds all valid tentative_accept properties to this struct - #[serde(flatten)] - #[activitystreams(None)] - pub tentative_accept_props: TentativeAcceptProperties, - - /// Adds all valid object properties to this struct - #[serde(flatten)] - #[activitystreams(Object)] - pub object_props: ObjectProperties, - - /// Adds all valid activity properties to this struct - #[serde(flatten)] - #[activitystreams(Activity)] - pub activity_props: ActivityProperties, -} diff --git a/src/activity/streams/tentative_reject.rs b/src/activity/streams/tentative_reject.rs deleted file mode 100644 index d81e559..0000000 --- a/src/activity/streams/tentative_reject.rs +++ /dev/null @@ -1,54 +0,0 @@ -/* - * This file is part of ActivityStreams. - * - * Copyright © 2020 Riley Trautman - * - * ActivityStreams is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * ActivityStreams is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with ActivityStreams. If not, see . - */ - -use crate::{ - activity::{ - kind::TentativeRejectType, - properties::{ActivityProperties, TentativeRejectProperties}, - Activity, - }, - object::{properties::ObjectProperties, Object}, - PropRefs, -}; -use serde::{Deserialize, Serialize}; - -/// A specialization of Reject in which the rejection is considered tentative. -#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] -#[serde(rename_all = "camelCase")] -pub struct TentativeReject { - #[serde(rename = "type")] - #[serde(alias = "objectType")] - #[serde(alias = "verb")] - pub kind: TentativeRejectType, - - /// Adds all valid tentative_reject properties to this struct - #[serde(flatten)] - #[activitystreams(None)] - pub tentative_reject_props: TentativeRejectProperties, - - /// Adds all valid object properties to this struct - #[serde(flatten)] - #[activitystreams(Object)] - pub object_props: ObjectProperties, - - /// Adds all valid activity properties to this struct - #[serde(flatten)] - #[activitystreams(Activity)] - pub activity_props: ActivityProperties, -} diff --git a/src/activity/streams/travel.rs b/src/activity/streams/travel.rs deleted file mode 100644 index 5355290..0000000 --- a/src/activity/streams/travel.rs +++ /dev/null @@ -1,59 +0,0 @@ -/* - * This file is part of ActivityStreams. - * - * Copyright © 2020 Riley Trautman - * - * ActivityStreams is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * ActivityStreams is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with ActivityStreams. If not, see . - */ - -use crate::{ - activity::{ - kind::TravelType, - properties::{ActivityProperties, TravelProperties}, - Activity, IntransitiveActivity, - }, - object::{properties::ObjectProperties, Object}, - PropRefs, -}; -use serde::{Deserialize, Serialize}; - -/// Indicates that the actor is traveling to target from origin. -/// -/// Travel is an IntransitiveObject whose actor specifies the direct object. If the target or -/// origin are not specified, either can be determined by context. -#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] -#[serde(rename_all = "camelCase")] -pub struct Travel { - #[serde(rename = "type")] - #[serde(alias = "objectType")] - #[serde(alias = "verb")] - pub kind: TravelType, - - /// Adds all valid travel properties to this struct - #[serde(flatten)] - #[activitystreams(None)] - pub travel_props: TravelProperties, - - /// Adds all valid object properties to this struct - #[serde(flatten)] - #[activitystreams(Object)] - pub object_props: ObjectProperties, - - /// Adds all valid activity properties to this struct - #[serde(flatten)] - #[activitystreams(Activity)] - pub activity_props: ActivityProperties, -} - -impl IntransitiveActivity for Travel {} diff --git a/src/activity/streams/undo.rs b/src/activity/streams/undo.rs deleted file mode 100644 index 2c34740..0000000 --- a/src/activity/streams/undo.rs +++ /dev/null @@ -1,60 +0,0 @@ -/* - * This file is part of ActivityStreams. - * - * Copyright © 2020 Riley Trautman - * - * ActivityStreams is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * ActivityStreams is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with ActivityStreams. If not, see . - */ - -use crate::{ - activity::{ - kind::UndoType, - properties::{ActivityProperties, UndoProperties}, - Activity, - }, - object::{properties::ObjectProperties, Object}, - PropRefs, -}; -use serde::{Deserialize, Serialize}; - -/// Indicates that the actor is undoing the object. -/// -/// In most cases, the object will be an Activity describing some previously performed action (for -/// instance, a person may have previously "liked" an article but, for whatever reason, might -/// choose to undo that like at some later point in time). -/// -/// The target and origin typically have no defined meaning. -#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] -#[serde(rename_all = "camelCase")] -pub struct Undo { - #[serde(rename = "type")] - #[serde(alias = "objectType")] - #[serde(alias = "verb")] - pub kind: UndoType, - - /// Adds all valid undo properties to this struct - #[serde(flatten)] - #[activitystreams(None)] - pub undo_props: UndoProperties, - - /// Adds all valid object properties to this struct - #[serde(flatten)] - #[activitystreams(Object)] - pub object_props: ObjectProperties, - - /// Adds all valid activity properties to this struct - #[serde(flatten)] - #[activitystreams(Activity)] - pub activity_props: ActivityProperties, -} diff --git a/src/activity/streams/update.rs b/src/activity/streams/update.rs deleted file mode 100644 index 6b20561..0000000 --- a/src/activity/streams/update.rs +++ /dev/null @@ -1,59 +0,0 @@ -/* - * This file is part of ActivityStreams. - * - * Copyright © 2020 Riley Trautman - * - * ActivityStreams is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * ActivityStreams is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with ActivityStreams. If not, see . - */ - -use crate::{ - activity::{ - kind::UpdateType, - properties::{ActivityProperties, UpdateProperties}, - Activity, - }, - object::{properties::ObjectProperties, Object}, - PropRefs, -}; -use serde::{Deserialize, Serialize}; - -/// Indicates that the actor has updated the object. -/// -/// Note, however, that this vocabulary does not define a mechanism for describing the actual set -/// of modifications made to object. -/// -/// The target and origin typically have no defined meaning. -#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] -#[serde(rename_all = "camelCase")] -pub struct Update { - #[serde(rename = "type")] - #[serde(alias = "objectType")] - #[serde(alias = "verb")] - pub kind: UpdateType, - - /// Adds all valid update properties to this struct - #[serde(flatten)] - #[activitystreams(None)] - pub update_props: UpdateProperties, - - /// Adds all valid object properties to this struct - #[serde(flatten)] - #[activitystreams(Object)] - pub object_props: ObjectProperties, - - /// Adds all valid activity properties to this struct - #[serde(flatten)] - #[activitystreams(Activity)] - pub activity_props: ActivityProperties, -} diff --git a/src/activity/streams/view.rs b/src/activity/streams/view.rs deleted file mode 100644 index 7f6611b..0000000 --- a/src/activity/streams/view.rs +++ /dev/null @@ -1,54 +0,0 @@ -/* - * This file is part of ActivityStreams. - * - * Copyright © 2020 Riley Trautman - * - * ActivityStreams is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * ActivityStreams is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with ActivityStreams. If not, see . - */ - -use crate::{ - activity::{ - kind::ViewType, - properties::{ActivityProperties, ViewProperties}, - Activity, - }, - object::{properties::ObjectProperties, Object}, - PropRefs, -}; -use serde::{Deserialize, Serialize}; - -/// Indicates that the actor has viewed the object. -#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] -#[serde(rename_all = "camelCase")] -pub struct View { - #[serde(rename = "type")] - #[serde(alias = "objectType")] - #[serde(alias = "verb")] - pub kind: ViewType, - - /// Adds all valid view properties to this struct - #[serde(flatten)] - #[activitystreams(None)] - pub view_props: ViewProperties, - - /// Adds all valid object properties to this struct - #[serde(flatten)] - #[activitystreams(Object)] - pub object_props: ObjectProperties, - - /// Adds all valid activity properties to this struct - #[serde(flatten)] - #[activitystreams(Activity)] - pub activity_props: ActivityProperties, -} diff --git a/src/actor/apub.rs b/src/actor/apub.rs index be43caf..549cb08 100644 --- a/src/actor/apub.rs +++ b/src/actor/apub.rs @@ -18,10 +18,10 @@ */ use crate::{ - actor::{kind::*, properties::*, Actor}, + actor::{kind::*, properties::*, Actor, ActorBox}, object::{ properties::{ApObjectProperties, ObjectProperties}, - Object, + Object, ObjectBox, }, PropRefs, }; @@ -30,114 +30,124 @@ use serde::{Deserialize, Serialize}; /// Describes a software application. #[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] +#[prop_refs(Object)] +#[prop_refs(Actor)] pub struct Application { #[serde(rename = "type")] kind: ApplicationType, /// Adds all valid object properties to this struct #[serde(flatten)] - #[activitystreams(Object)] + #[prop_refs] pub object_props: ObjectProperties, /// Adds all valid activitypub object properties to this struct #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub ap_object_props: ApObjectProperties, /// Adds all valid activitypub actor properties to this struct #[serde(flatten)] - #[activitystreams(Actor)] + #[prop_refs] pub ap_actor_props: ApActorProperties, } /// Represents a formal or informal collective of Actors. #[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] +#[prop_refs(Object)] +#[prop_refs(Actor)] pub struct Group { #[serde(rename = "type")] kind: GroupType, /// Adds all valid object properties to this struct #[serde(flatten)] - #[activitystreams(Object)] + #[prop_refs] pub object_props: ObjectProperties, /// Adds all valid activitypub object properties to this struct #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub ap_object_props: ApObjectProperties, /// Adds all valid activitypub actor properties to this struct #[serde(flatten)] - #[activitystreams(Actor)] + #[prop_refs] pub ap_actor_props: ApActorProperties, } /// Represents an organization. #[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] +#[prop_refs(Object)] +#[prop_refs(Actor)] pub struct Organization { #[serde(rename = "type")] kind: OrganizationType, /// Adds all valid object properties to this struct #[serde(flatten)] - #[activitystreams(Object)] + #[prop_refs] pub object_props: ObjectProperties, /// Adds all valid activitypub object properties to this struct #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub ap_object_props: ApObjectProperties, /// Adds all valid activitypub actor properties to this struct #[serde(flatten)] - #[activitystreams(Actor)] + #[prop_refs] pub ap_actor_props: ApActorProperties, } /// Represents an individual person. #[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] +#[prop_refs(Object)] +#[prop_refs(Actor)] pub struct Person { #[serde(rename = "type")] kind: PersonType, /// Adds all valid object properties to this struct #[serde(flatten)] - #[activitystreams(Object)] + #[prop_refs] pub object_props: ObjectProperties, /// Adds all valid activitypub object properties to this struct #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub ap_object_props: ApObjectProperties, /// Adds all valid activitypub actor properties to this struct #[serde(flatten)] - #[activitystreams(Actor)] + #[prop_refs] pub ap_actor_props: ApActorProperties, } /// Represents a service of any kind. #[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] +#[prop_refs(Object)] +#[prop_refs(Actor)] pub struct Service { #[serde(rename = "type")] kind: ServiceType, /// Adds all valid object properties to this struct #[serde(flatten)] - #[activitystreams(Object)] + #[prop_refs] pub object_props: ObjectProperties, /// Adds all valid activitypub object properties to this struct #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub ap_object_props: ApObjectProperties, /// Adds all valid activitypub actor properties to this struct #[serde(flatten)] - #[activitystreams(Actor)] + #[prop_refs] pub ap_actor_props: ApActorProperties, } diff --git a/src/actor/kind.rs b/src/actor/kind.rs index 36576ae..b92c62e 100644 --- a/src/actor/kind.rs +++ b/src/actor/kind.rs @@ -21,21 +21,21 @@ use crate::UnitString; #[derive(Clone, Debug, Default, UnitString)] -#[activitystreams(Application)] +#[unit_string(Application)] pub struct ApplicationType; #[derive(Clone, Debug, Default, UnitString)] -#[activitystreams(Group)] +#[unit_string(Group)] pub struct GroupType; #[derive(Clone, Debug, Default, UnitString)] -#[activitystreams(Organization)] +#[unit_string(Organization)] pub struct OrganizationType; #[derive(Clone, Debug, Default, UnitString)] -#[activitystreams(Person)] +#[unit_string(Person)] pub struct PersonType; #[derive(Clone, Debug, Default, UnitString)] -#[activitystreams(Service)] +#[unit_string(Service)] pub struct ServiceType; diff --git a/src/actor/mod.rs b/src/actor/mod.rs index 81e8cab..1032bf1 100644 --- a/src/actor/mod.rs +++ b/src/actor/mod.rs @@ -30,6 +30,9 @@ pub mod streams; use crate::object::Object; +#[cfg(feature = "types")] +use crate::wrapper_type; + /// `Actor` types are `Object` types that are capable of performing activities. /// /// This specification intentionally defines `Actors` in only the most generalized way, stopping @@ -49,4 +52,5 @@ use crate::object::Object; /// (e.g. VCard) define their own types for describing people. An implementation that wishes, for /// example, to use a `vcard:Individual` as an `Actor` MUST also identify that `Actor` as a /// `Person`. +#[cfg_attr(feature = "types", wrapper_type)] pub trait Actor: Object {} diff --git a/src/actor/streams.rs b/src/actor/streams.rs index 34bc010..3ae61d1 100644 --- a/src/actor/streams.rs +++ b/src/actor/streams.rs @@ -18,8 +18,8 @@ */ use crate::{ - actor::{kind::*, Actor}, - object::{properties::ObjectProperties, Object}, + actor::{kind::*, Actor, ActorBox}, + object::{properties::ObjectProperties, Object, ObjectBox}, PropRefs, }; use serde::{Deserialize, Serialize}; @@ -27,6 +27,8 @@ use serde::{Deserialize, Serialize}; /// Describes a software application. #[derive(Clone, Debug, Default, Deserialize, PropRefs, Serialize)] #[serde(rename_all = "camelCase")] +#[prop_refs(Object)] +#[prop_refs(Actor)] pub struct Application { #[serde(rename = "type")] #[serde(alias = "objectType")] @@ -35,15 +37,15 @@ pub struct Application { /// Adds all valid object properties to this struct #[serde(flatten)] - #[activitystreams(Object)] + #[prop_refs] pub object_props: ObjectProperties, } -impl Actor for Application {} - /// Represents a formal or informal collective of Actors. #[derive(Clone, Debug, Default, Deserialize, PropRefs, Serialize)] #[serde(rename_all = "camelCase")] +#[prop_refs(Object)] +#[prop_refs(Actor)] pub struct Group { #[serde(rename = "type")] #[serde(alias = "objectType")] @@ -52,12 +54,10 @@ pub struct Group { /// Adds all valid object properties to this struct #[serde(flatten)] - #[activitystreams(Object)] + #[prop_refs] pub object_props: ObjectProperties, } -impl Actor for Group {} - /// Represents an organization. #[derive(Clone, Debug, Default, Deserialize, PropRefs, Serialize)] #[serde(rename_all = "camelCase")] @@ -69,15 +69,15 @@ pub struct Organization { /// Adds all valid object properties to this struct #[serde(flatten)] - #[activitystreams(Object)] + #[prop_refs] pub object_props: ObjectProperties, } -impl Actor for Organization {} - /// Represents an individual person. #[derive(Clone, Debug, Default, Deserialize, PropRefs, Serialize)] #[serde(rename_all = "camelCase")] +#[prop_refs(Object)] +#[prop_refs(Actor)] pub struct Person { #[serde(rename = "type")] #[serde(alias = "objectType")] @@ -86,15 +86,15 @@ pub struct Person { /// Adds all valid object properties to this struct #[serde(flatten)] - #[activitystreams(Object)] + #[prop_refs] pub object_props: ObjectProperties, } -impl Actor for Person {} - /// Represents a service of any kind. #[derive(Clone, Debug, Default, Deserialize, PropRefs, Serialize)] #[serde(rename_all = "camelCase")] +#[prop_refs(Object)] +#[prop_refs(Actor)] pub struct Service { #[serde(rename = "type")] #[serde(alias = "objectType")] @@ -103,8 +103,6 @@ pub struct Service { /// Adds all valid object properties to this struct #[serde(flatten)] - #[activitystreams(Object)] + #[prop_refs] pub object_props: ObjectProperties, } - -impl Actor for Service {} diff --git a/src/collection/apub.rs b/src/collection/apub.rs index 14d599c..111bf78 100644 --- a/src/collection/apub.rs +++ b/src/collection/apub.rs @@ -20,10 +20,12 @@ //! Collection traits and types use crate::{ - collection::{kind::*, properties::*, Collection, CollectionPage}, + collection::{ + kind::*, properties::*, Collection, CollectionBox, CollectionPage, CollectionPageBox, + }, object::{ properties::{ApObjectProperties, ObjectProperties}, - Object, + Object, ObjectBox, }, PropRefs, }; @@ -32,51 +34,56 @@ use serde::{Deserialize, Serialize}; /// The default `Collection` type. #[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] +#[prop_refs(Object)] +#[prop_refs(Collection)] pub struct UnorderedCollection { #[serde(rename = "type")] kind: CollectionType, /// Adds all valid object properties to this struct #[serde(flatten)] - #[activitystreams(Object)] + #[prop_refs] pub object_props: ObjectProperties, /// Adds all valid ap object properties to this struct #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub ap_object_props: ApObjectProperties, /// Adds all valid collection properties to this struct #[serde(flatten)] - #[activitystreams(Collection)] + #[prop_refs] pub collection_props: CollectionProperties, } /// Used to represent distinct subsets of items from a `Collection`. #[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] +#[prop_refs(Object)] +#[prop_refs(Collection)] +#[prop_refs(CollectionPage)] pub struct UnorderedCollectionPage { #[serde(rename = "type")] kind: CollectionPageType, /// Adds all valid object properties to this struct #[serde(flatten)] - #[activitystreams(Object)] + #[prop_refs] pub object_props: ObjectProperties, /// Adds all valid ap object properties to this struct #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub ap_object_props: ApObjectProperties, /// Adds all valid collection properties to this struct #[serde(flatten)] - #[activitystreams(Collection)] + #[prop_refs] pub collection_props: CollectionProperties, /// Adds all valid collection page properties to this struct #[serde(flatten)] - #[activitystreams(CollectionPage)] + #[prop_refs] pub collection_page_props: CollectionPageProperties, } @@ -84,55 +91,60 @@ pub struct UnorderedCollectionPage { /// strictly ordered. #[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] +#[prop_refs(Object)] +#[prop_refs(Collection)] pub struct OrderedCollection { #[serde(rename = "type")] kind: OrderedCollectionType, /// Adds all valid object properties to this struct #[serde(flatten)] - #[activitystreams(Object)] + #[prop_refs] pub object_props: ObjectProperties, /// Adds all valid ap object properties to this struct #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub ap_object_props: ApObjectProperties, /// Adds all valid collection properties to this struct #[serde(flatten)] - #[activitystreams(Collection)] + #[prop_refs] pub collection_props: CollectionProperties, } /// Used to represent ordered subsets of items from an `OrderedCollection`. #[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] +#[prop_refs(Object)] +#[prop_refs(Collection)] +#[prop_refs(CollectionPage)] pub struct OrderedCollectionPage { #[serde(rename = "type")] kind: OrderedCollectionPageType, /// Adds all valid object properties to this struct #[serde(flatten)] - #[activitystreams(Object)] + #[prop_refs] pub object_props: ObjectProperties, /// Adds all valid ap object properties to this struct #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub ap_object_props: ApObjectProperties, /// Adds all valid collection properties to this struct #[serde(flatten)] - #[activitystreams(Collection)] + #[prop_refs] pub collection_props: CollectionProperties, /// Adds all valid collection page properties to this struct #[serde(flatten)] - #[activitystreams(CollectionPage)] + #[prop_refs] pub collection_page_props: CollectionPageProperties, /// Adds all valid ordered collection page properties to this struct #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub ordered_collection_page_props: OrderedCollectionPageProperties, } diff --git a/src/collection/kind.rs b/src/collection/kind.rs index b2ff172..d349260 100644 --- a/src/collection/kind.rs +++ b/src/collection/kind.rs @@ -21,17 +21,17 @@ use crate::UnitString; #[derive(Clone, Debug, Default, UnitString)] -#[activitystreams(Collection)] +#[unit_string(Collection)] pub struct CollectionType; #[derive(Clone, Debug, Default, UnitString)] -#[activitystreams(CollectionPage)] +#[unit_string(CollectionPage)] pub struct CollectionPageType; #[derive(Clone, Debug, Default, UnitString)] -#[activitystreams(OrderedCollection)] +#[unit_string(OrderedCollection)] pub struct OrderedCollectionType; #[derive(Clone, Debug, Default, UnitString)] -#[activitystreams(OrderedCollectionPage)] +#[unit_string(OrderedCollectionPage)] pub struct OrderedCollectionPageType; diff --git a/src/collection/mod.rs b/src/collection/mod.rs index 8ceecf8..c0210ae 100644 --- a/src/collection/mod.rs +++ b/src/collection/mod.rs @@ -30,6 +30,9 @@ pub mod streams; use crate::object::Object; +#[cfg(feature = "types")] +use crate::wrapper_type; + /// A Collection is a subtype of `Object` that represents ordered or unordered sets of `Object` or /// `Link` instances. /// @@ -40,6 +43,7 @@ use crate::object::Object; /// /// `UnorderedCollection` and `OrderedCollection` types are provided by the `activitystreams-types` /// crate. +#[cfg_attr(feature = "types", wrapper_type)] pub trait Collection: Object {} /// Used to represent distinct subsets of items from a Collection. @@ -51,96 +55,5 @@ pub trait Collection: Object {} /// /// `UnorderedCollectionPage` and `OrderedCollectionPage` types are provied by the /// `activitystreams-types` crate. +#[cfg_attr(feature = "types", wrapper_type)] pub trait CollectionPage: Collection {} - -#[cfg(feature = "types")] -#[derive(Debug, serde::Deserialize, serde::Serialize)] -#[serde(transparent)] -pub struct CollectionBox(pub Box); - -#[cfg(feature = "types")] -#[derive(Debug, serde::Deserialize, serde::Serialize)] -#[serde(transparent)] -pub struct CollectionPageBox(pub Box); - -#[cfg(feature = "types")] -impl CollectionBox { - pub fn is(&self) -> bool - where - T: Collection + 'static, - { - self.0.as_any().is::() - } - - pub fn downcast_ref(&self) -> Option<&T> - where - T: Collection + 'static, - { - self.0.as_any().downcast_ref() - } - - pub fn downcast_mut(&mut self) -> Option<&mut T> - where - T: Collection + 'static, - { - self.0.as_any_mut().downcast_mut() - } -} - -#[cfg(feature = "types")] -impl CollectionPageBox { - pub fn is(&self) -> bool - where - T: CollectionPage + 'static, - { - self.0.as_any().is::() - } - - pub fn downcast_ref(&self) -> Option<&T> - where - T: CollectionPage + 'static, - { - self.0.as_any().downcast_ref() - } - - pub fn downcast_mut(&mut self) -> Option<&mut T> - where - T: CollectionPage + 'static, - { - self.0.as_any_mut().downcast_mut() - } -} - -#[cfg(feature = "types")] -impl Clone for CollectionBox { - fn clone(&self) -> Self { - CollectionBox(self.0.duplicate()) - } -} - -#[cfg(feature = "types")] -impl Clone for CollectionPageBox { - fn clone(&self) -> Self { - CollectionPageBox(self.0.duplicate()) - } -} - -#[cfg(feature = "types")] -impl From for CollectionBox -where - T: Collection + 'static, -{ - fn from(t: T) -> Self { - CollectionBox(Box::new(t)) - } -} - -#[cfg(feature = "types")] -impl From for CollectionPageBox -where - T: CollectionPage + 'static, -{ - fn from(t: T) -> Self { - CollectionPageBox(Box::new(t)) - } -} diff --git a/src/collection/streams.rs b/src/collection/streams.rs index e38fcf4..28b6595 100644 --- a/src/collection/streams.rs +++ b/src/collection/streams.rs @@ -20,8 +20,10 @@ //! Namespace for Collection types use crate::{ - collection::{kind::*, properties::*, Collection, CollectionPage}, - object::{properties::ObjectProperties, Object}, + collection::{ + kind::*, properties::*, Collection, CollectionBox, CollectionPage, CollectionPageBox, + }, + object::{properties::ObjectProperties, Object, ObjectBox}, PropRefs, }; use serde::{Deserialize, Serialize}; @@ -29,6 +31,8 @@ use serde::{Deserialize, Serialize}; /// The default `Collection` type. #[derive(Clone, Debug, Default, Deserialize, PropRefs, Serialize)] #[serde(rename_all = "camelCase")] +#[prop_refs(Object)] +#[prop_refs(Collection)] pub struct UnorderedCollection { #[serde(rename = "type")] #[serde(alias = "objectType")] @@ -37,12 +41,12 @@ pub struct UnorderedCollection { /// Adds all valid object properties to this struct #[serde(flatten)] - #[activitystreams(Object)] + #[prop_refs] pub object_props: ObjectProperties, /// Adds all valid collection properties to this struct #[serde(flatten)] - #[activitystreams(Collection)] + #[prop_refs] pub collection_props: CollectionProperties, } @@ -50,6 +54,8 @@ pub struct UnorderedCollection { /// strictly ordered. #[derive(Clone, Debug, Default, Deserialize, PropRefs, Serialize)] #[serde(rename_all = "camelCase")] +#[prop_refs(Object)] +#[prop_refs(Collection)] pub struct OrderedCollection { #[serde(rename = "type")] #[serde(alias = "objectType")] @@ -58,18 +64,21 @@ pub struct OrderedCollection { /// Adds all valid object properties to this struct #[serde(flatten)] - #[activitystreams(Object)] + #[prop_refs] pub object_props: ObjectProperties, /// Adds all valid collection properties to this struct #[serde(flatten)] - #[activitystreams(Collection)] + #[prop_refs] pub collection_props: CollectionProperties, } /// Used to represent distinct subsets of items from a `Collection`. #[derive(Clone, Debug, Default, Deserialize, PropRefs, Serialize)] #[serde(rename_all = "camelCase")] +#[prop_refs(Object)] +#[prop_refs(Collection)] +#[prop_refs(CollectionPage)] pub struct UnorderedCollectionPage { #[serde(rename = "type")] #[serde(alias = "objectType")] @@ -78,23 +87,26 @@ pub struct UnorderedCollectionPage { /// Adds all valid object properties to this struct #[serde(flatten)] - #[activitystreams(Object)] + #[prop_refs] pub object_props: ObjectProperties, /// Adds all valid collection properties to this struct #[serde(flatten)] - #[activitystreams(Collection)] + #[prop_refs] pub collection_props: CollectionProperties, /// Adds all valid collection page properties to this struct #[serde(flatten)] - #[activitystreams(CollectionPage)] + #[prop_refs] pub collection_page_props: CollectionPageProperties, } /// Used to represent ordered subsets of items from an `OrderedCollection`. #[derive(Clone, Debug, Default, Deserialize, PropRefs, Serialize)] #[serde(rename_all = "camelCase")] +#[prop_refs(Object)] +#[prop_refs(Collection)] +#[prop_refs(CollectionPage)] pub struct OrderedCollectionPage { #[serde(rename = "type")] #[serde(alias = "objectType")] @@ -103,21 +115,21 @@ pub struct OrderedCollectionPage { /// Adds all valid object properties to this struct #[serde(flatten)] - #[activitystreams(Object)] + #[prop_refs] pub object_props: ObjectProperties, /// Adds all valid collection properties to this struct #[serde(flatten)] - #[activitystreams(Collection)] + #[prop_refs] pub collection_props: CollectionProperties, /// Adds all valid collection page properties to this struct #[serde(flatten)] - #[activitystreams(CollectionPage)] + #[prop_refs] pub collection_page_props: CollectionPageProperties, /// Adds all valid ordered collection page properties to this struct #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub ordered_collection_page_props: OrderedCollectionPageProperties, } diff --git a/src/lib.rs b/src/lib.rs index da88a9a..7c05f9b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -412,4 +412,4 @@ pub fn context() -> crate::primitives::XsdAnyUri { } #[cfg(feature = "derive")] -pub use activitystreams_derive::{properties, PropRefs, UnitString}; +pub use activitystreams_derive::{properties, wrapper_type, PropRefs, UnitString}; diff --git a/src/link/kind.rs b/src/link/kind.rs index cbe6be1..0d49100 100644 --- a/src/link/kind.rs +++ b/src/link/kind.rs @@ -22,5 +22,5 @@ use crate::UnitString; /// A Unit Struct that represents the string "Mention" #[derive(Clone, Debug, Default, UnitString)] -#[activitystreams(Mention)] +#[unit_string(Mention)] pub struct MentionType; diff --git a/src/link/mod.rs b/src/link/mod.rs index 7b3b1e8..f5a98cd 100644 --- a/src/link/mod.rs +++ b/src/link/mod.rs @@ -29,7 +29,8 @@ mod types; #[cfg(feature = "types")] pub use self::types::Mention; -use std::any::Any; +#[cfg(feature = "types")] +use crate::wrapper_type; /// A Link is an indirect, qualified reference to a resource identified by a URL. /// @@ -39,57 +40,5 @@ use std::any::Any; /// used, it establishes a qualified relation connecting the subject (the containing object) to the /// resource identified by the href. Properties of the Link are properties of the reference as /// opposed to properties of the resource. -#[typetag::serde(tag = "type")] -pub trait Link: std::fmt::Debug { - fn as_any(&self) -> &dyn Any; - - fn as_any_mut(&mut self) -> &mut dyn Any; - - fn duplicate(&self) -> Box; -} - -#[cfg(feature = "types")] -#[derive(Debug, serde::Deserialize, serde::Serialize)] -#[serde(transparent)] -pub struct LinkBox(pub Box); - -#[cfg(feature = "types")] -impl LinkBox { - pub fn is(&self) -> bool - where - T: Link + 'static, - { - self.0.as_any().is::() - } - - pub fn downcast_ref(&self) -> Option<&T> - where - T: Link + 'static, - { - self.0.as_any().downcast_ref() - } - - pub fn downcast_mut(&mut self) -> Option<&mut T> - where - T: Link + 'static, - { - self.0.as_any_mut().downcast_mut() - } -} - -#[cfg(feature = "types")] -impl Clone for LinkBox { - fn clone(&self) -> Self { - LinkBox(self.0.duplicate()) - } -} - -#[cfg(feature = "types")] -impl From for LinkBox -where - T: Link + 'static, -{ - fn from(t: T) -> Self { - LinkBox(Box::new(t)) - } -} +#[cfg_attr(feature = "types", wrapper_type)] +pub trait Link: std::fmt::Debug {} diff --git a/src/link/types.rs b/src/link/types.rs index 36a3cd1..b17d15a 100644 --- a/src/link/types.rs +++ b/src/link/types.rs @@ -18,7 +18,7 @@ */ use crate::{ - link::{kind::*, properties::*, Link}, + link::{kind::*, properties::*, Link, LinkBox}, PropRefs, }; use serde::{Deserialize, Serialize}; @@ -27,6 +27,7 @@ use serde::{Deserialize, Serialize}; /// A specialized Link that represents an @mention. #[derive(Clone, Debug, Default, Deserialize, PropRefs, Serialize)] #[serde(rename_all = "camelCase")] +#[prop_refs(Link)] pub struct Mention { #[serde(rename = "type")] #[serde(alias = "objectType")] @@ -35,6 +36,6 @@ pub struct Mention { /// Adds all valid link properties to this struct #[serde(flatten)] - #[activitystreams(Link)] + #[prop_refs] pub link_props: LinkProperties, } diff --git a/src/object/apub.rs b/src/object/apub.rs index 70bcdac..5db0407 100644 --- a/src/object/apub.rs +++ b/src/object/apub.rs @@ -18,8 +18,8 @@ */ use crate::{ - object::{kind::*, properties::*}, - Object, PropRefs, + object::{kind::*, properties::*, Object, ObjectBox}, + PropRefs, }; use serde::{Deserialize, Serialize}; @@ -29,197 +29,209 @@ pub struct ApImageBox(pub Box); #[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] +#[prop_refs(Object)] pub struct Article { #[serde(rename = "type")] kind: ArticleType, #[serde(flatten)] - #[activitystreams(Object)] + #[prop_refs] pub object_props: ObjectProperties, #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub ap_object_props: ApObjectProperties, } #[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] +#[prop_refs(Object)] pub struct Audio { #[serde(rename = "type")] kind: AudioType, #[serde(flatten)] - #[activitystreams(Object)] + #[prop_refs] pub object_props: ObjectProperties, #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub ap_object_props: ApObjectProperties, } #[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] +#[prop_refs(Object)] pub struct Document { #[serde(rename = "type")] kind: DocumentType, #[serde(flatten)] - #[activitystreams(Object)] + #[prop_refs] pub object_props: ObjectProperties, #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub ap_object_props: ApObjectProperties, } #[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] +#[prop_refs(Object)] pub struct Event { #[serde(rename = "type")] kind: EventType, #[serde(flatten)] - #[activitystreams(Object)] + #[prop_refs] pub object_props: ObjectProperties, #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub ap_object_props: ApObjectProperties, } #[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] +#[prop_refs(Object)] pub struct Image { #[serde(rename = "type")] kind: ImageType, #[serde(flatten)] - #[activitystreams(Object)] + #[prop_refs] pub object_props: ObjectProperties, #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub ap_object_props: ApObjectProperties, } #[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] +#[prop_refs(Object)] pub struct Note { #[serde(rename = "type")] kind: NoteType, #[serde(flatten)] - #[activitystreams(Object)] + #[prop_refs] pub object_props: ObjectProperties, #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub ap_object_props: ApObjectProperties, } #[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] +#[prop_refs(Object)] pub struct Page { #[serde(rename = "type")] kind: PageType, #[serde(flatten)] - #[activitystreams(Object)] + #[prop_refs] pub object_props: ObjectProperties, #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub ap_object_props: ApObjectProperties, } #[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] +#[prop_refs(Object)] pub struct Place { #[serde(rename = "type")] kind: PlaceType, #[serde(flatten)] - #[activitystreams(Object)] + #[prop_refs] pub object_props: ObjectProperties, #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub ap_object_props: ApObjectProperties, #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub place_props: PlaceProperties, } #[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] +#[prop_refs(Object)] pub struct Profile { #[serde(rename = "type")] kind: ProfileType, #[serde(flatten)] - #[activitystreams(Object)] + #[prop_refs] pub object_props: ObjectProperties, #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub ap_object_props: ApObjectProperties, #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub profile_props: ProfileProperties, } #[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] +#[prop_refs(Object)] pub struct Relationship { #[serde(rename = "type")] kind: RelationshipType, #[serde(flatten)] - #[activitystreams(Object)] + #[prop_refs] pub object_props: ObjectProperties, #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub ap_object_props: ApObjectProperties, #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub relationship_props: RelationshipProperties, } #[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] +#[prop_refs(Object)] pub struct Tombstone { #[serde(rename = "type")] kind: TombstoneType, #[serde(flatten)] - #[activitystreams(Object)] + #[prop_refs] pub object_props: ObjectProperties, #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub ap_object_props: ApObjectProperties, #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub tombstone_props: TombstoneProperties, } #[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] +#[prop_refs(Object)] pub struct Video { #[serde(rename = "type")] kind: VideoType, #[serde(flatten)] - #[activitystreams(Object)] + #[prop_refs] pub object_props: ObjectProperties, #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub ap_object_props: ApObjectProperties, } diff --git a/src/object/kind.rs b/src/object/kind.rs index e483f2b..712a353 100644 --- a/src/object/kind.rs +++ b/src/object/kind.rs @@ -22,60 +22,60 @@ use crate::UnitString; /// A Unit Struct that represents the string "Article" #[derive(Clone, Debug, Default, UnitString)] -#[activitystreams(Article)] +#[unit_string(Article)] pub struct ArticleType; /// A Unit Struct that represents the string "Audio" #[derive(Clone, Debug, Default, UnitString)] -#[activitystreams(Audio)] +#[unit_string(Audio)] pub struct AudioType; /// A Unit Struct that represents the string "Document" #[derive(Clone, Debug, Default, UnitString)] -#[activitystreams(Document)] +#[unit_string(Document)] pub struct DocumentType; /// A Unit Struct that represents the string "Event" #[derive(Clone, Debug, Default, UnitString)] -#[activitystreams(Event)] +#[unit_string(Event)] pub struct EventType; /// A Unit Struct that represents the string "Image" #[derive(Clone, Debug, Default, UnitString)] -#[activitystreams(Image)] +#[unit_string(Image)] pub struct ImageType; /// A Unit Struct that represents the string "Note" #[derive(Clone, Debug, Default, UnitString)] -#[activitystreams(Note)] +#[unit_string(Note)] pub struct NoteType; /// A Unit Struct that represents the string "Page" #[derive(Clone, Debug, Default, UnitString)] -#[activitystreams(Page)] +#[unit_string(Page)] pub struct PageType; /// A Unit Struct that represents the string "Place" #[derive(Clone, Debug, Default, UnitString)] -#[activitystreams(Place)] +#[unit_string(Place)] pub struct PlaceType; /// A Unit Struct that represents the string "Profile" #[derive(Clone, Debug, Default, UnitString)] -#[activitystreams(Profile)] +#[unit_string(Profile)] pub struct ProfileType; /// A Unit Struct that represents the string "Relationship" #[derive(Clone, Debug, Default, UnitString)] -#[activitystreams(Relationship)] +#[unit_string(Relationship)] pub struct RelationshipType; /// A Unit Struct that represents the string "Tombstone" #[derive(Clone, Debug, Default, UnitString)] -#[activitystreams(Tombstone)] +#[unit_string(Tombstone)] pub struct TombstoneType; /// A Unit Struct that represents the string "Video" #[derive(Clone, Debug, Default, UnitString)] -#[activitystreams(Video)] +#[unit_string(Video)] pub struct VideoType; diff --git a/src/object/mod.rs b/src/object/mod.rs index 95f12ac..610fe4e 100644 --- a/src/object/mod.rs +++ b/src/object/mod.rs @@ -28,73 +28,13 @@ pub mod properties; #[cfg(feature = "types")] pub mod streams; -use std::any::Any; +#[cfg(feature = "types")] +use crate::wrapper_type; /// Describes an object of any kind. /// /// The Object type serves as the base type for most of the other kinds of objects defined in the /// Activity Vocabulary, including other Core types such as `Activity`, `IntransitiveActivity`, /// `Collection` and `OrderedCollection`. -#[typetag::serde(tag = "type")] -pub trait Object: std::fmt::Debug { - /// Provide an as_any method to allow for borrowed downcasting. - /// - /// This is useful since Objects can be deserialized generically via typetag - fn as_any(&self) -> &dyn Any; - - /// Provide an as_any method to allow for mutably borrowed downcasting. - /// - /// This is useful since Objects can be deserialized generically via typetag - fn as_any_mut(&mut self) -> &mut dyn Any; - - /// Provide a duplicate method to allow for cloning type objects. - /// - /// This is useful since Objects can be deserialized generically via typetag - fn duplicate(&self) -> Box; -} - -#[cfg(feature = "types")] -#[derive(Debug, serde::Deserialize, serde::Serialize)] -#[serde(transparent)] -pub struct ObjectBox(pub Box); - -#[cfg(feature = "types")] -impl ObjectBox { - pub fn is(&self) -> bool - where - T: Object + 'static, - { - self.0.as_any().is::() - } - - pub fn downcast_ref(&self) -> Option<&T> - where - T: Object + 'static, - { - self.0.as_any().downcast_ref() - } - - pub fn downcast_mut(&mut self) -> Option<&mut T> - where - T: Object + 'static, - { - self.0.as_any_mut().downcast_mut() - } -} - -#[cfg(feature = "types")] -impl Clone for ObjectBox { - fn clone(&self) -> Self { - ObjectBox(self.0.duplicate()) - } -} - -#[cfg(feature = "types")] -impl From for ObjectBox -where - T: Object + 'static, -{ - fn from(t: T) -> Self { - ObjectBox(Box::new(t)) - } -} +#[cfg_attr(feature = "types", wrapper_type)] +pub trait Object: std::fmt::Debug {} diff --git a/src/object/streams.rs b/src/object/streams.rs index c020fcb..77cb783 100644 --- a/src/object/streams.rs +++ b/src/object/streams.rs @@ -18,8 +18,8 @@ */ use crate::{ - object::{kind::*, properties::*}, - Object, PropRefs, + object::{kind::*, properties::*, Object, ObjectBox}, + PropRefs, }; use serde::{Deserialize, Serialize}; @@ -30,6 +30,7 @@ pub struct ImageBox(pub Box); /// Represents any kind of multi-paragraph written work. #[derive(Clone, Debug, Default, Deserialize, PropRefs, Serialize)] #[serde(rename_all = "camelCase")] +#[prop_refs(Object)] pub struct Article { #[serde(rename = "type")] #[serde(alias = "objectType")] @@ -38,13 +39,14 @@ pub struct Article { /// Adds all valid object properties to this struct #[serde(flatten)] - #[activitystreams(Object)] + #[prop_refs] pub object_props: ObjectProperties, } /// Represents an audio document of any kind. #[derive(Clone, Debug, Default, Deserialize, PropRefs, Serialize)] #[serde(rename_all = "camelCase")] +#[prop_refs(Object)] pub struct Audio { #[serde(rename = "type")] #[serde(alias = "objectType")] @@ -53,13 +55,14 @@ pub struct Audio { /// Adds all valid object properties to this struct #[serde(flatten)] - #[activitystreams(Object)] + #[prop_refs] pub object_props: ObjectProperties, } /// Represents a document of any kind. #[derive(Clone, Debug, Default, Deserialize, PropRefs, Serialize)] #[serde(rename_all = "camelCase")] +#[prop_refs(Object)] pub struct Document { #[serde(rename = "type")] #[serde(alias = "objectType")] @@ -68,13 +71,14 @@ pub struct Document { /// Adds all valid object properties to this struct #[serde(flatten)] - #[activitystreams(Object)] + #[prop_refs] pub object_props: ObjectProperties, } /// Represents any kind of event. #[derive(Clone, Debug, Default, Deserialize, PropRefs, Serialize)] #[serde(rename_all = "camelCase")] +#[prop_refs(Object)] pub struct Event { #[serde(rename = "type")] #[serde(alias = "objectType")] @@ -83,13 +87,14 @@ pub struct Event { /// Adds all valid object properties to this struct #[serde(flatten)] - #[activitystreams(Object)] + #[prop_refs] pub object_props: ObjectProperties, } /// An image document of any kind #[derive(Clone, Debug, Default, Deserialize, PropRefs, Serialize)] #[serde(rename_all = "camelCase")] +#[prop_refs(Object)] pub struct Image { #[serde(rename = "type")] #[serde(alias = "objectType")] @@ -98,13 +103,14 @@ pub struct Image { /// Adds all valid object properties to this struct #[serde(flatten)] - #[activitystreams(Object)] + #[prop_refs] pub object_props: ObjectProperties, } /// Represents a short written work typically less than a single paragraph in length. #[derive(Clone, Debug, Default, Deserialize, PropRefs, Serialize)] #[serde(rename_all = "camelCase")] +#[prop_refs(Object)] pub struct Note { #[serde(rename = "type")] #[serde(alias = "objectType")] @@ -113,13 +119,14 @@ pub struct Note { /// Adds all valid object properties to this struct #[serde(flatten)] - #[activitystreams(Object)] + #[prop_refs] pub object_props: ObjectProperties, } /// Represents a Web Page. #[derive(Clone, Debug, Default, Deserialize, PropRefs, Serialize)] #[serde(rename_all = "camelCase")] +#[prop_refs(Object)] pub struct Page { #[serde(rename = "type")] #[serde(alias = "objectType")] @@ -128,7 +135,7 @@ pub struct Page { /// Adds all valid object properties to this struct #[serde(flatten)] - #[activitystreams(Object)] + #[prop_refs] pub object_props: ObjectProperties, } @@ -152,6 +159,7 @@ pub struct Page { /// MUST support the use of these properties. #[derive(Clone, Debug, Default, Deserialize, PropRefs, Serialize)] #[serde(rename_all = "camelCase")] +#[prop_refs(Object)] pub struct Place { #[serde(rename = "type")] #[serde(alias = "objectType")] @@ -160,12 +168,12 @@ pub struct Place { /// Adds all valid object properties to this struct #[serde(flatten)] - #[activitystreams(Object)] + #[prop_refs] pub object_props: ObjectProperties, /// Adds all valid place properties to this struct #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub place: PlaceProperties, } @@ -175,6 +183,7 @@ pub struct Place { /// The `describes` property is used to reference the object being described by the profile. #[derive(Clone, Debug, Default, Deserialize, PropRefs, Serialize)] #[serde(rename_all = "camelCase")] +#[prop_refs(Object)] pub struct Profile { #[serde(rename = "type")] #[serde(alias = "objectType")] @@ -183,12 +192,12 @@ pub struct Profile { /// Adds all valid object properties to this struct #[serde(flatten)] - #[activitystreams(Object)] + #[prop_refs] pub object_props: ObjectProperties, /// Adds all valid profile properties to this struct #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub profile: ProfileProperties, } @@ -208,6 +217,7 @@ pub struct Profile { /// and Jane have a mutual relationship. #[derive(Clone, Debug, Default, Deserialize, PropRefs, Serialize)] #[serde(rename_all = "camelCase")] +#[prop_refs(Object)] pub struct Relationship { #[serde(rename = "type")] #[serde(alias = "objectType")] @@ -216,12 +226,12 @@ pub struct Relationship { /// Adds all valid object properties to this struct #[serde(flatten)] - #[activitystreams(Object)] + #[prop_refs] pub object_props: ObjectProperties, /// Adds all valid relationship properties to this struct #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub relationship: RelationshipProperties, } @@ -231,6 +241,7 @@ pub struct Relationship { /// it has been deleted. #[derive(Clone, Debug, Default, Deserialize, PropRefs, Serialize)] #[serde(rename_all = "camelCase")] +#[prop_refs(Object)] pub struct Tombstone { #[serde(rename = "type")] #[serde(alias = "objectType")] @@ -239,18 +250,19 @@ pub struct Tombstone { /// Adds all valid object properties to this struct #[serde(flatten)] - #[activitystreams(Object)] + #[prop_refs] pub object_props: ObjectProperties, /// Adds all valid tombstone properties to this struct #[serde(flatten)] - #[activitystreams(None)] + #[prop_refs] pub tombstone_props: TombstoneProperties, } /// Represents a video document of any kind. #[derive(Clone, Debug, Default, Deserialize, PropRefs, Serialize)] #[serde(rename_all = "camelCase")] +#[prop_refs(Object)] pub struct Video { #[serde(rename = "type")] #[serde(alias = "objectType")] @@ -259,7 +271,7 @@ pub struct Video { /// Adds all valid object properties to this struct #[serde(flatten)] - #[activitystreams(Object)] + #[prop_refs] pub object_props: ObjectProperties, }