From ac4f1cd5d18755c3ba6cf9d0dd22c50d38c12ec9 Mon Sep 17 00:00:00 2001 From: asonix Date: Mon, 9 Mar 2020 22:22:48 -0500 Subject: [PATCH] Use more specific types for activitystreams fields --- Cargo.toml | 3 + activitystreams-derive/src/lib.rs | 184 ++-- activitystreams-traits/Cargo.toml | 1 - activitystreams-traits/src/link.rs | 2 + activitystreams-traits/src/object.rs | 2 + activitystreams-types/src/activity/accept.rs | 30 +- activitystreams-types/src/activity/add.rs | 30 +- activitystreams-types/src/activity/amove.rs | 30 +- .../src/activity/announce.rs | 30 +- activitystreams-types/src/activity/arrive.rs | 29 +- activitystreams-types/src/activity/block.rs | 30 +- activitystreams-types/src/activity/create.rs | 30 +- activitystreams-types/src/activity/delete.rs | 30 +- activitystreams-types/src/activity/dislike.rs | 30 +- activitystreams-types/src/activity/flag.rs | 30 +- activitystreams-types/src/activity/follow.rs | 30 +- activitystreams-types/src/activity/ignore.rs | 30 +- activitystreams-types/src/activity/invite.rs | 30 +- activitystreams-types/src/activity/join.rs | 30 +- activitystreams-types/src/activity/leave.rs | 30 +- activitystreams-types/src/activity/like.rs | 30 +- activitystreams-types/src/activity/listen.rs | 30 +- activitystreams-types/src/activity/offer.rs | 30 +- .../src/activity/properties.rs | 809 +++++++++++------- .../src/activity/question.rs | 29 +- activitystreams-types/src/activity/read.rs | 30 +- activitystreams-types/src/activity/reject.rs | 30 +- activitystreams-types/src/activity/remove.rs | 30 +- .../src/activity/tentative_accept.rs | 30 +- .../src/activity/tentative_reject.rs | 30 +- activitystreams-types/src/activity/travel.rs | 29 +- activitystreams-types/src/activity/undo.rs | 30 +- activitystreams-types/src/activity/update.rs | 30 +- activitystreams-types/src/activity/view.rs | 30 +- activitystreams-types/src/actor/mod.rs | 68 +- activitystreams-types/src/collection/mod.rs | 189 ++-- .../src/collection/properties.rs | 254 ++++-- activitystreams-types/src/custom_props.rs | 151 ---- activitystreams-types/src/lib.rs | 17 +- activitystreams-types/src/link/mod.rs | 43 +- activitystreams-types/src/link/properties.rs | 300 ++++--- activitystreams-types/src/object/mod.rs | 42 +- .../src/object/properties.rs | 579 +++++++------ activitystreams-types/src/primitives/mod.rs | 4 +- .../src/primitives/rdf_lang_string.rs | 6 +- .../src/primitives/xsd_any_uri.rs | 34 +- .../src/primitives/xsd_float.rs | 2 +- .../src/primitives/xsd_non_negative_float.rs | 2 +- .../primitives/xsd_non_negative_integer.rs | 2 +- .../src/primitives/xsd_string.rs | 2 +- src/error.rs | 22 - src/lib.rs | 3 - 52 files changed, 1616 insertions(+), 1942 deletions(-) delete mode 100644 activitystreams-types/src/custom_props.rs delete mode 100644 src/error.rs diff --git a/Cargo.toml b/Cargo.toml index 8d6345b..299ca5c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,6 +20,9 @@ serde_derive = "1.0" serde_json = "1.0" activitystreams-derive = { version = "0.3", path = "activitystreams-derive" } +[profile.dev.package.activitystreams-derive] +opt-level = 3 + [workspace] members = [ "activitystreams-derive", diff --git a/activitystreams-derive/src/lib.rs b/activitystreams-derive/src/lib.rs index 76a497d..a3929e5 100644 --- a/activitystreams-derive/src/lib.rs +++ b/activitystreams-derive/src/lib.rs @@ -96,8 +96,6 @@ use syn::{ token, Attribute, Data, DeriveInput, Fields, Ident, LitStr, Result, Token, Type, }; -use std::iter::FromIterator; - #[proc_macro_derive(PropRefs, attributes(activitystreams))] pub fn ref_derive(input: TokenStream) -> TokenStream { let input: DeriveInput = syn::parse(input).unwrap(); @@ -114,7 +112,7 @@ pub fn ref_derive(input: TokenStream) -> TokenStream { _ => panic!("Can only derive for named fields"), }; - let impls = fields + let tokens: proc_macro2::TokenStream = fields .named .iter() .filter_map(|field| { @@ -142,25 +140,31 @@ pub fn ref_derive(input: TokenStream) -> TokenStream { let name = name.clone(); let ext_trait = Ident::new(&format!("{}Ext", object), name.span()); - let tt = if object.to_string() == "Object" || object.to_string() == "Link" { + 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! {} + quote! { + impl #object for #name {} + } }; let activity_impls = quote! { - #tt - impl #object for #name { - fn as_any(&self) -> &dyn std::any::Any { - self - } - - fn as_any_mut(&self) -> &mut dyn std::any::Any { - self - } - } + #base_impl impl #ext_trait for #name { fn props(&self) -> &#ty { @@ -195,9 +199,8 @@ pub fn ref_derive(input: TokenStream) -> TokenStream { #activity_impls } } - }); - - let tokens = proc_macro2::TokenStream::from_iter(impls); + }) + .collect(); let full = quote! { #tokens @@ -317,7 +320,15 @@ fn from_value(attr: Attribute) -> Ident { #[proc_macro] pub fn properties(tokens: TokenStream) -> TokenStream { - let Properties { name, fields } = parse_macro_input!(tokens as Properties); + let Properties { name, docs, fields } = parse_macro_input!(tokens as Properties); + + let docs: proc_macro2::TokenStream = docs + .into_iter() + .map(|doc| { + let idents: proc_macro2::TokenStream = format!("/// {}", doc).parse().unwrap(); + quote! { #idents } + }) + .collect(); let name = Ident::new(&format!("{}Properties", name), name.span()); @@ -327,6 +338,11 @@ pub fn properties(tokens: TokenStream) -> TokenStream { } let fname = field.name.clone(); + let fdocs: proc_macro2::TokenStream = field.description.docs.iter().map(|doc| { + let idents: proc_macro2::TokenStream = format!("/// {}", doc).parse().unwrap(); + quote! { #idents } + }).collect(); + let (ty, deps) = if field.description.types.len() == 1 { let ty = Ident::new(&field.description.types.first().unwrap().to_token_stream().to_string(), fname.span()); if field.description.functional { @@ -342,6 +358,12 @@ pub fn properties(tokens: TokenStream) -> TokenStream { Array(Vec<#ty>), } + impl Default for #enum_ty { + fn default() -> Self { + #enum_ty::Array(Vec::new()) + } + } + impl From<#ty> for #enum_ty { fn from(t: #ty) -> Self { #enum_ty::Term(t) @@ -360,7 +382,7 @@ pub fn properties(tokens: TokenStream) -> TokenStream { } else { let ty = Ident::new(&camelize(&format!("{}_{}_enum", name, fname)), fname.span()); - let v_tys: Vec<_> = field + let v_tokens: proc_macro2::TokenStream = field .description .types .iter() @@ -371,12 +393,12 @@ pub fn properties(tokens: TokenStream) -> TokenStream { }) .collect(); - let v_tokens = proc_macro2::TokenStream::from_iter(v_tys); + let first_type = field.description.types.iter().next().unwrap().clone(); let deps = if !field.description.functional { let term_ty = Ident::new(&camelize(&format!("{}_{}_term_enum", name, fname)), fname.span()); - let froms: Vec<_> = field + let from_tokens: proc_macro2::TokenStream = field .description .types .iter() @@ -391,8 +413,6 @@ pub fn properties(tokens: TokenStream) -> TokenStream { }) .collect(); - let from_tokens = proc_macro2::TokenStream::from_iter(froms); - quote! { #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] #[serde(rename_all = "camelCase")] @@ -409,6 +429,12 @@ pub fn properties(tokens: TokenStream) -> TokenStream { Array(Vec<#term_ty>), } + impl Default for #ty { + fn default() -> Self { + #ty::Array(Vec::new()) + } + } + impl From<#term_ty> for #ty { fn from(term: #term_ty) -> Self { #ty::Term(term) @@ -424,7 +450,7 @@ pub fn properties(tokens: TokenStream) -> TokenStream { #from_tokens } } else { - let froms: Vec<_> = field + let from_tokens: proc_macro2::TokenStream = field .description .types .iter() @@ -439,8 +465,6 @@ pub fn properties(tokens: TokenStream) -> TokenStream { }) .collect(); - let from_tokens = proc_macro2::TokenStream::from_iter(froms); - quote! { #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] #[serde(rename_all = "camelCase")] @@ -449,6 +473,12 @@ pub fn properties(tokens: TokenStream) -> TokenStream { #v_tokens } + impl Default for #ty { + fn default() -> Self { + #ty::#first_type(Default::default()) + } + } + #from_tokens } }; @@ -456,32 +486,31 @@ pub fn properties(tokens: TokenStream) -> TokenStream { (ty, Some(deps)) }; + let alias_tokens: proc_macro2::TokenStream = field.description.aliases.iter().map(|alias| quote!{ + #[serde(alias = #alias)] + }).collect(); + let rename_tokens: proc_macro2::TokenStream = field.description.rename.iter().map(|rename| quote!{ + #[serde(rename = #rename)] + }).collect(); + let field_tokens = if field.description.required { - if let Some(ref rename) = field.description.rename { - quote! { - #[serde(rename = #rename)] - pub #fname: #ty, - } - } else { - quote! { - pub #fname: #ty, - } + quote! { + pub #fname: #ty, } } else { - if let Some(ref rename) = field.description.rename { - quote! { - #[serde(skip_serializing_if = "Option::is_none")] - #[serde(rename = #rename)] - pub #fname: Option<#ty>, - } - } else { - quote! { - #[serde(skip_serializing_if = "Option::is_none")] - pub #fname: Option<#ty>, - } + quote! { + #[serde(skip_serializing_if = "Option::is_none")] + pub #fname: Option<#ty>, } }; + let field_tokens = quote!{ + #fdocs + #rename_tokens + #alias_tokens + #field_tokens + }; + let fns = if field.description.types.len() == 1 { let v_ty = field.description.types.first().unwrap().clone(); @@ -637,7 +666,7 @@ pub fn properties(tokens: TokenStream) -> TokenStream { } } } else if field.description.functional { - let impls: Vec<_> = field + let tokens: proc_macro2::TokenStream = field .description .types .iter() @@ -701,14 +730,12 @@ pub fn properties(tokens: TokenStream) -> TokenStream { }) .collect(); - let tokens = proc_macro2::TokenStream::from_iter(impls); - quote! { #tokens } } else { let term_ty = Ident::new(&camelize(&format!("{}_{}_term_enum", name, fname)), fname.span()); - let impls: Vec<_> = field + let tokens: proc_macro2::TokenStream = field .description .types .iter() @@ -825,8 +852,6 @@ pub fn properties(tokens: TokenStream) -> TokenStream { }) .collect(); - let tokens = proc_macro2::TokenStream::from_iter(impls); - let delete = if !field.description.required { let delete_ident = Ident::new(&format!("delete_{}", fname), fname.span()); @@ -851,17 +876,13 @@ pub fn properties(tokens: TokenStream) -> TokenStream { Some(((field_tokens, fns), deps)) }).unzip(); - let (fields, fns): (Vec<_>, Vec<_>) = fields.into_iter().unzip(); - let deps: Vec<_> = deps.into_iter().filter_map(|d| d).collect(); - - let field_tokens = proc_macro2::TokenStream::from_iter(fields); - let fn_tokens = proc_macro2::TokenStream::from_iter(fns); - let deps_tokens = proc_macro2::TokenStream::from_iter(deps); + let (field_tokens, fn_tokens): (proc_macro2::TokenStream, proc_macro2::TokenStream) = + fields.into_iter().unzip(); + let deps_tokens: proc_macro2::TokenStream = deps.into_iter().filter_map(|d| d).collect(); let q = quote! { - #deps_tokens - - #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] + #docs + #[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize)] #[serde(rename_all = "camelCase")] pub struct #name { #field_tokens @@ -870,6 +891,8 @@ pub fn properties(tokens: TokenStream) -> TokenStream { impl #name { #fn_tokens } + + #deps_tokens }; q.into() } @@ -879,10 +902,13 @@ mod kw { syn::custom_keyword!(functional); syn::custom_keyword!(required); syn::custom_keyword!(rename); + syn::custom_keyword!(alias); + syn::custom_keyword!(docs); } struct Properties { name: Ident, + docs: Vec, fields: Punctuated, } @@ -892,10 +918,12 @@ struct Field { } struct Description { + docs: Vec, types: Punctuated, functional: bool, required: bool, rename: Option, + aliases: Vec, } impl Parse for Properties { @@ -904,9 +932,12 @@ impl Parse for Properties { let content; let _: token::Brace = braced!(content in input); + + let docs = parse_string_array::<_, kw::docs>(&&content, kw::docs)?; + let fields = Punctuated::::parse_terminated(&content)?; - Ok(Properties { name, fields }) + Ok(Properties { name, docs, fields }) } } @@ -925,6 +956,8 @@ impl Parse for Field { impl Parse for Description { fn parse(input: ParseStream) -> Result { + let docs = parse_string_array::<_, kw::docs>(&input, kw::docs)?; + let lookahead = input.lookahead1(); if !lookahead.peek(kw::types) { return Err(lookahead.error()); @@ -938,13 +971,16 @@ impl Parse for Description { let functional = parse_kw::<_, kw::functional>(&input, kw::functional)?; let required = parse_kw::<_, kw::required>(&input, kw::required)?; - let rename = parse_rename::<_, kw::rename>(&input, kw::rename)?; + let rename = parse_string_group::<_, kw::rename>(&input, kw::rename)?; + let aliases = parse_string_array::<_, kw::alias>(&input, kw::alias)?; Ok(Description { + docs, types, functional, required, rename, + aliases, }) } } @@ -961,7 +997,25 @@ fn parse_kw(input: &ParseStream, t: T) -> Result Ok(false) } -fn parse_rename(input: &ParseStream, t: T) -> Result> { +fn parse_string_array(input: &ParseStream, t: T) -> Result> { + let lookahead = input.lookahead1(); + if lookahead.peek(t) { + input.parse::()?; + let content; + bracketed!(content in input); + + let docs = Punctuated::::parse_terminated(&content)?; + optional_comma(&input)?; + Ok(docs.into_iter().map(|d| d.value()).collect()) + } else { + Ok(vec![]) + } +} + +fn parse_string_group( + input: &ParseStream, + t: T, +) -> Result> { let lookahead = input.lookahead1(); if lookahead.peek(t) { input.parse::()?; diff --git a/activitystreams-traits/Cargo.toml b/activitystreams-traits/Cargo.toml index e99094f..a4a4472 100644 --- a/activitystreams-traits/Cargo.toml +++ b/activitystreams-traits/Cargo.toml @@ -10,7 +10,6 @@ keywords = ["activitystreams", "activitypub"] edition = "2018" [dependencies] -thiserror = "1.0" typetag = "0.1.4" [dev-dependencies] diff --git a/activitystreams-traits/src/link.rs b/activitystreams-traits/src/link.rs index aa62697..cf5f17c 100644 --- a/activitystreams-traits/src/link.rs +++ b/activitystreams-traits/src/link.rs @@ -32,4 +32,6 @@ 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; } diff --git a/activitystreams-traits/src/object.rs b/activitystreams-traits/src/object.rs index 5ed8cc7..352bee1 100644 --- a/activitystreams-traits/src/object.rs +++ b/activitystreams-traits/src/object.rs @@ -29,4 +29,6 @@ pub trait Object: std::fmt::Debug { fn as_any(&self) -> &dyn Any; fn as_any_mut(&mut self) -> &mut dyn Any; + + fn duplicate(&self) -> Box; } diff --git a/activitystreams-types/src/activity/accept.rs b/activitystreams-types/src/activity/accept.rs index ac84552..a89be5d 100644 --- a/activitystreams-types/src/activity/accept.rs +++ b/activitystreams-types/src/activity/accept.rs @@ -17,9 +17,9 @@ * along with ActivityStreams Types. If not, see . */ -use activitystreams_derive::Properties; +use activitystreams_derive::PropRefs; use activitystreams_traits::{Activity, Object}; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; use super::{ kind::AcceptType, @@ -32,7 +32,7 @@ use crate::object::{properties::ObjectProperties, ObjectExt}; /// /// 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, Serialize, Properties)] +#[derive(Clone, Debug, Default, Deserialize, PropRefs, Serialize)] #[serde(rename_all = "camelCase")] pub struct Accept { #[serde(rename = "type")] @@ -42,34 +42,16 @@ pub struct Accept { /// 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, } - -impl Object for Accept {} -impl ObjectExt for Accept { - fn props(&self) -> &ObjectProperties { - &self.object_props - } - - fn props_mut(&mut self) -> &mut ObjectProperties { - &mut self.object_props - } -} -impl Activity for Accept {} -impl ActivityExt for Accept { - fn props(&self) -> &ActivityProperties { - &self.activity_props - } - - fn props_mut(&mut self) -> &mut ActivityProperties { - &mut self.activity_props - } -} diff --git a/activitystreams-types/src/activity/add.rs b/activitystreams-types/src/activity/add.rs index fd9e613..9e2ba2b 100644 --- a/activitystreams-types/src/activity/add.rs +++ b/activitystreams-types/src/activity/add.rs @@ -17,9 +17,9 @@ * along with ActivityStreams Types. If not, see . */ -use activitystreams_derive::Properties; +use activitystreams_derive::PropRefs; use activitystreams_traits::{Activity, Object}; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; use super::{ kind::AddType, @@ -33,7 +33,7 @@ use crate::object::{properties::ObjectProperties, ObjectExt}; /// 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, Properties)] +#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] pub struct Add { #[serde(rename = "type")] @@ -43,34 +43,16 @@ pub struct Add { /// 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, } - -impl Object for Add {} -impl ObjectExt for Add { - fn props(&self) -> &ObjectProperties { - &self.object_props - } - - fn props_mut(&mut self) -> &mut ObjectProperties { - &mut self.object_props - } -} -impl Activity for Add {} -impl ActivityExt for Add { - fn props(&self) -> &ActivityProperties { - &self.activity_props - } - - fn props_mut(&mut self) -> &mut ActivityProperties { - &mut self.activity_props - } -} diff --git a/activitystreams-types/src/activity/amove.rs b/activitystreams-types/src/activity/amove.rs index 97afe9e..e7f942f 100644 --- a/activitystreams-types/src/activity/amove.rs +++ b/activitystreams-types/src/activity/amove.rs @@ -17,9 +17,9 @@ * along with ActivityStreams Types. If not, see . */ -use activitystreams_derive::Properties; +use activitystreams_derive::PropRefs; use activitystreams_traits::{Activity, Object}; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; use super::{ kind::MoveType, @@ -31,7 +31,7 @@ use crate::object::{properties::ObjectProperties, ObjectExt}; /// 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, Properties)] +#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] pub struct AMove { #[serde(rename = "type")] @@ -41,34 +41,16 @@ pub struct AMove { /// 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, } - -impl Object for AMove {} -impl ObjectExt for AMove { - fn props(&self) -> &ObjectProperties { - &self.object_props - } - - fn props_mut(&mut self) -> &mut ObjectProperties { - &mut self.object_props - } -} -impl Activity for AMove {} -impl ActivityExt for AMove { - fn props(&self) -> &ActivityProperties { - &self.activity_props - } - - fn props_mut(&mut self) -> &mut ActivityProperties { - &mut self.activity_props - } -} diff --git a/activitystreams-types/src/activity/announce.rs b/activitystreams-types/src/activity/announce.rs index 6caa53e..2666b52 100644 --- a/activitystreams-types/src/activity/announce.rs +++ b/activitystreams-types/src/activity/announce.rs @@ -17,9 +17,9 @@ * along with ActivityStreams Types. If not, see . */ -use activitystreams_derive::Properties; +use activitystreams_derive::PropRefs; use activitystreams_traits::{Activity, Object}; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; use super::{ kind::AnnounceType, @@ -31,7 +31,7 @@ use crate::object::{properties::ObjectProperties, ObjectExt}; /// 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, Properties)] +#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] pub struct Announce { #[serde(rename = "type")] @@ -41,34 +41,16 @@ pub struct Announce { /// 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, } - -impl Object for Announce {} -impl ObjectExt for Announce { - fn props(&self) -> &ObjectProperties { - &self.object_props - } - - fn props_mut(&mut self) -> &mut ObjectProperties { - &mut self.object_props - } -} -impl Activity for Announce {} -impl ActivityExt for Announce { - fn props(&self) -> &ActivityProperties { - &self.activity_props - } - - fn props_mut(&mut self) -> &mut ActivityProperties { - &mut self.activity_props - } -} diff --git a/activitystreams-types/src/activity/arrive.rs b/activitystreams-types/src/activity/arrive.rs index 9aa336e..4e10197 100644 --- a/activitystreams-types/src/activity/arrive.rs +++ b/activitystreams-types/src/activity/arrive.rs @@ -17,9 +17,9 @@ * along with ActivityStreams Types. If not, see . */ -use activitystreams_derive::Properties; +use activitystreams_derive::PropRefs; use activitystreams_traits::{Activity, IntransitiveActivity, Object}; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; use super::{ kind::ArriveType, @@ -32,7 +32,7 @@ use crate::object::{properties::ObjectProperties, ObjectExt}; /// /// 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, Properties)] +#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] pub struct Arrive { #[serde(rename = "type")] @@ -42,35 +42,18 @@ pub struct Arrive { /// 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 Object for Arrive {} -impl ObjectExt for Arrive { - fn props(&self) -> &ObjectProperties { - &self.object_props - } - - fn props_mut(&mut self) -> &mut ObjectProperties { - &mut self.object_props - } -} -impl Activity for Arrive {} impl IntransitiveActivity for Arrive {} -impl ActivityExt for Arrive { - fn props(&self) -> &ActivityProperties { - &self.activity_props - } - - fn props_mut(&mut self) -> &mut ActivityProperties { - &mut self.activity_props - } -} diff --git a/activitystreams-types/src/activity/block.rs b/activitystreams-types/src/activity/block.rs index eaf6895..aec816e 100644 --- a/activitystreams-types/src/activity/block.rs +++ b/activitystreams-types/src/activity/block.rs @@ -17,9 +17,9 @@ * along with ActivityStreams Types. If not, see . */ -use activitystreams_derive::Properties; +use activitystreams_derive::PropRefs; use activitystreams_traits::{Activity, Object}; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; use super::{ kind::BlockType, @@ -33,7 +33,7 @@ use crate::object::{properties::ObjectProperties, ObjectExt}; /// 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, Properties)] +#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] pub struct Block { #[serde(rename = "type")] @@ -43,34 +43,16 @@ pub struct Block { /// 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, } - -impl Object for Block {} -impl ObjectExt for Block { - fn props(&self) -> &ObjectProperties { - &self.object_props - } - - fn props_mut(&mut self) -> &mut ObjectProperties { - &mut self.object_props - } -} -impl Activity for Block {} -impl ActivityExt for Block { - fn props(&self) -> &ActivityProperties { - &self.activity_props - } - - fn props_mut(&mut self) -> &mut ActivityProperties { - &mut self.activity_props - } -} diff --git a/activitystreams-types/src/activity/create.rs b/activitystreams-types/src/activity/create.rs index 7e6e543..343707a 100644 --- a/activitystreams-types/src/activity/create.rs +++ b/activitystreams-types/src/activity/create.rs @@ -17,9 +17,9 @@ * along with ActivityStreams Types. If not, see . */ -use activitystreams_derive::Properties; +use activitystreams_derive::PropRefs; use activitystreams_traits::{Activity, Object}; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; use super::{ kind::CreateType, @@ -29,7 +29,7 @@ use super::{ use crate::object::{properties::ObjectProperties, ObjectExt}; /// Indicates that the actor has created the object. -#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)] +#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] pub struct Create { #[serde(rename = "type")] @@ -39,34 +39,16 @@ pub struct Create { /// 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, } - -impl Object for Create {} -impl ObjectExt for Create { - fn props(&self) -> &ObjectProperties { - &self.object_props - } - - fn props_mut(&mut self) -> &mut ObjectProperties { - &mut self.object_props - } -} -impl Activity for Create {} -impl ActivityExt for Create { - fn props(&self) -> &ActivityProperties { - &self.activity_props - } - - fn props_mut(&mut self) -> &mut ActivityProperties { - &mut self.activity_props - } -} diff --git a/activitystreams-types/src/activity/delete.rs b/activitystreams-types/src/activity/delete.rs index 4740c36..4e9a41d 100644 --- a/activitystreams-types/src/activity/delete.rs +++ b/activitystreams-types/src/activity/delete.rs @@ -17,9 +17,9 @@ * along with ActivityStreams Types. If not, see . */ -use activitystreams_derive::Properties; +use activitystreams_derive::PropRefs; use activitystreams_traits::{Activity, Object}; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; use super::{ kind::DeleteType, @@ -31,7 +31,7 @@ use crate::object::{properties::ObjectProperties, ObjectExt}; /// 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, Properties)] +#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] pub struct Delete { #[serde(rename = "type")] @@ -41,34 +41,16 @@ pub struct Delete { /// 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, } - -impl Object for Delete {} -impl ObjectExt for Delete { - fn props(&self) -> &ObjectProperties { - &self.object_props - } - - fn props_mut(&mut self) -> &mut ObjectProperties { - &mut self.object_props - } -} -impl Activity for Delete {} -impl ActivityExt for Delete { - fn props(&self) -> &ActivityProperties { - &self.activity_props - } - - fn props_mut(&mut self) -> &mut ActivityProperties { - &mut self.activity_props - } -} diff --git a/activitystreams-types/src/activity/dislike.rs b/activitystreams-types/src/activity/dislike.rs index 546d78f..51c54d4 100644 --- a/activitystreams-types/src/activity/dislike.rs +++ b/activitystreams-types/src/activity/dislike.rs @@ -17,9 +17,9 @@ * along with ActivityStreams Types. If not, see . */ -use activitystreams_derive::Properties; +use activitystreams_derive::PropRefs; use activitystreams_traits::{Activity, Object}; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; use super::{ kind::DislikeType, @@ -29,7 +29,7 @@ use super::{ use crate::object::{properties::ObjectProperties, ObjectExt}; /// Indicates that the actor dislikes the object. -#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)] +#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] pub struct Dislike { #[serde(rename = "type")] @@ -39,34 +39,16 @@ pub struct Dislike { /// 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, } - -impl Object for Dislike {} -impl ObjectExt for Dislike { - fn props(&self) -> &ObjectProperties { - &self.object_props - } - - fn props_mut(&mut self) -> &mut ObjectProperties { - &mut self.object_props - } -} -impl Activity for Dislike {} -impl ActivityExt for Dislike { - fn props(&self) -> &ActivityProperties { - &self.activity_props - } - - fn props_mut(&mut self) -> &mut ActivityProperties { - &mut self.activity_props - } -} diff --git a/activitystreams-types/src/activity/flag.rs b/activitystreams-types/src/activity/flag.rs index 1c3f20b..cb8ba58 100644 --- a/activitystreams-types/src/activity/flag.rs +++ b/activitystreams-types/src/activity/flag.rs @@ -17,9 +17,9 @@ * along with ActivityStreams Types. If not, see . */ -use activitystreams_derive::Properties; +use activitystreams_derive::PropRefs; use activitystreams_traits::{Activity, Object}; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; use super::{ kind::FlagType, @@ -32,7 +32,7 @@ use crate::object::{properties::ObjectProperties, ObjectExt}; /// /// 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, Properties)] +#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] pub struct Flag { #[serde(rename = "type")] @@ -42,34 +42,16 @@ pub struct Flag { /// 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, } - -impl Object for Flag {} -impl ObjectExt for Flag { - fn props(&self) -> &ObjectProperties { - &self.object_props - } - - fn props_mut(&mut self) -> &mut ObjectProperties { - &mut self.object_props - } -} -impl Activity for Flag {} -impl ActivityExt for Flag { - fn props(&self) -> &ActivityProperties { - &self.activity_props - } - - fn props_mut(&mut self) -> &mut ActivityProperties { - &mut self.activity_props - } -} diff --git a/activitystreams-types/src/activity/follow.rs b/activitystreams-types/src/activity/follow.rs index ab7119c..b2316cd 100644 --- a/activitystreams-types/src/activity/follow.rs +++ b/activitystreams-types/src/activity/follow.rs @@ -17,9 +17,9 @@ * along with ActivityStreams Types. If not, see . */ -use activitystreams_derive::Properties; +use activitystreams_derive::PropRefs; use activitystreams_traits::{Activity, Object}; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; use super::{ kind::FollowType, @@ -33,7 +33,7 @@ use crate::object::{properties::ObjectProperties, ObjectExt}; /// 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, Properties)] +#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] pub struct Follow { #[serde(rename = "type")] @@ -43,34 +43,16 @@ pub struct Follow { /// 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, } - -impl Object for Follow {} -impl ObjectExt for Follow { - fn props(&self) -> &ObjectProperties { - &self.object_props - } - - fn props_mut(&mut self) -> &mut ObjectProperties { - &mut self.object_props - } -} -impl Activity for Follow {} -impl ActivityExt for Follow { - fn props(&self) -> &ActivityProperties { - &self.activity_props - } - - fn props_mut(&mut self) -> &mut ActivityProperties { - &mut self.activity_props - } -} diff --git a/activitystreams-types/src/activity/ignore.rs b/activitystreams-types/src/activity/ignore.rs index c53c87f..fbbd20d 100644 --- a/activitystreams-types/src/activity/ignore.rs +++ b/activitystreams-types/src/activity/ignore.rs @@ -17,9 +17,9 @@ * along with ActivityStreams Types. If not, see . */ -use activitystreams_derive::Properties; +use activitystreams_derive::PropRefs; use activitystreams_traits::{Activity, Object}; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; use super::{ kind::IgnoreType, @@ -31,7 +31,7 @@ use crate::object::{properties::ObjectProperties, ObjectExt}; /// Indicates that the actor is ignoring the object. /// /// The target and origin typically have no defined meaning. -#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)] +#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] pub struct Ignore { #[serde(rename = "type")] @@ -41,34 +41,16 @@ pub struct Ignore { /// 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, } - -impl Object for Ignore {} -impl ObjectExt for Ignore { - fn props(&self) -> &ObjectProperties { - &self.object_props - } - - fn props_mut(&mut self) -> &mut ObjectProperties { - &mut self.object_props - } -} -impl Activity for Ignore {} -impl ActivityExt for Ignore { - fn props(&self) -> &ActivityProperties { - &self.activity_props - } - - fn props_mut(&mut self) -> &mut ActivityProperties { - &mut self.activity_props - } -} diff --git a/activitystreams-types/src/activity/invite.rs b/activitystreams-types/src/activity/invite.rs index 65ec08b..c309e82 100644 --- a/activitystreams-types/src/activity/invite.rs +++ b/activitystreams-types/src/activity/invite.rs @@ -17,9 +17,9 @@ * along with ActivityStreams Types. If not, see . */ -use activitystreams_derive::Properties; +use activitystreams_derive::PropRefs; use activitystreams_traits::{Activity, Object}; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; use super::{ kind::InviteType, @@ -30,7 +30,7 @@ use crate::object::{properties::ObjectProperties, ObjectExt}; /// A specialization of Offer in which the actor is extending an invitation for the object to the /// target. -#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)] +#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] pub struct Invite { #[serde(rename = "type")] @@ -40,34 +40,16 @@ pub struct Invite { /// 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, } - -impl Object for Invite {} -impl ObjectExt for Invite { - fn props(&self) -> &ObjectProperties { - &self.object_props - } - - fn props_mut(&mut self) -> &mut ObjectProperties { - &mut self.object_props - } -} -impl Activity for Invite {} -impl ActivityExt for Invite { - fn props(&self) -> &ActivityProperties { - &self.activity_props - } - - fn props_mut(&mut self) -> &mut ActivityProperties { - &mut self.activity_props - } -} diff --git a/activitystreams-types/src/activity/join.rs b/activitystreams-types/src/activity/join.rs index 71ae385..384e45f 100644 --- a/activitystreams-types/src/activity/join.rs +++ b/activitystreams-types/src/activity/join.rs @@ -17,9 +17,9 @@ * along with ActivityStreams Types. If not, see . */ -use activitystreams_derive::Properties; +use activitystreams_derive::PropRefs; use activitystreams_traits::{Activity, Object}; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; use super::{ kind::JoinType, @@ -31,7 +31,7 @@ use crate::object::{properties::ObjectProperties, ObjectExt}; /// Indicates that the actor has joined the object. /// /// The target and origin typically have no defined meaning -#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)] +#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] pub struct Join { #[serde(rename = "type")] @@ -41,34 +41,16 @@ pub struct Join { /// 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, } - -impl Object for Join {} -impl ObjectExt for Join { - fn props(&self) -> &ObjectProperties { - &self.object_props - } - - fn props_mut(&mut self) -> &mut ObjectProperties { - &mut self.object_props - } -} -impl Activity for Join {} -impl ActivityExt for Join { - fn props(&self) -> &ActivityProperties { - &self.activity_props - } - - fn props_mut(&mut self) -> &mut ActivityProperties { - &mut self.activity_props - } -} diff --git a/activitystreams-types/src/activity/leave.rs b/activitystreams-types/src/activity/leave.rs index 88f15a8..52fc668 100644 --- a/activitystreams-types/src/activity/leave.rs +++ b/activitystreams-types/src/activity/leave.rs @@ -17,9 +17,9 @@ * along with ActivityStreams Types. If not, see . */ -use activitystreams_derive::Properties; +use activitystreams_derive::PropRefs; use activitystreams_traits::{Activity, Object}; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; use super::{ kind::LeaveType, @@ -31,7 +31,7 @@ use crate::object::{properties::ObjectProperties, ObjectExt}; /// Indicates that the actor has left the object. /// /// The target and origin typically have no meaning. -#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)] +#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] pub struct Leave { #[serde(rename = "type")] @@ -41,34 +41,16 @@ pub struct Leave { /// 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, } - -impl Object for Leave {} -impl ObjectExt for Leave { - fn props(&self) -> &ObjectProperties { - &self.object_props - } - - fn props_mut(&mut self) -> &mut ObjectProperties { - &mut self.object_props - } -} -impl Activity for Leave {} -impl ActivityExt for Leave { - fn props(&self) -> &ActivityProperties { - &self.activity_props - } - - fn props_mut(&mut self) -> &mut ActivityProperties { - &mut self.activity_props - } -} diff --git a/activitystreams-types/src/activity/like.rs b/activitystreams-types/src/activity/like.rs index 0288e70..db19fb9 100644 --- a/activitystreams-types/src/activity/like.rs +++ b/activitystreams-types/src/activity/like.rs @@ -17,9 +17,9 @@ * along with ActivityStreams Types. If not, see . */ -use activitystreams_derive::Properties; +use activitystreams_derive::PropRefs; use activitystreams_traits::{Activity, Object}; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; use super::{ kind::LikeType, @@ -31,7 +31,7 @@ use crate::object::{properties::ObjectProperties, ObjectExt}; /// 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, Properties)] +#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] pub struct Like { #[serde(rename = "type")] @@ -41,34 +41,16 @@ pub struct Like { /// 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, } - -impl Object for Like {} -impl ObjectExt for Like { - fn props(&self) -> &ObjectProperties { - &self.object_props - } - - fn props_mut(&mut self) -> &mut ObjectProperties { - &mut self.object_props - } -} -impl Activity for Like {} -impl ActivityExt for Like { - fn props(&self) -> &ActivityProperties { - &self.activity_props - } - - fn props_mut(&mut self) -> &mut ActivityProperties { - &mut self.activity_props - } -} diff --git a/activitystreams-types/src/activity/listen.rs b/activitystreams-types/src/activity/listen.rs index 97fa445..3b571a5 100644 --- a/activitystreams-types/src/activity/listen.rs +++ b/activitystreams-types/src/activity/listen.rs @@ -17,9 +17,9 @@ * along with ActivityStreams Types. If not, see . */ -use activitystreams_derive::Properties; +use activitystreams_derive::PropRefs; use activitystreams_traits::{Activity, Object}; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; use super::{ kind::ListenType, @@ -29,7 +29,7 @@ use super::{ use crate::object::{properties::ObjectProperties, ObjectExt}; /// Indicates that the actor has listened to the object. -#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)] +#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] pub struct Listen { #[serde(rename = "type")] @@ -39,34 +39,16 @@ pub struct Listen { /// 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, } - -impl Object for Listen {} -impl ObjectExt for Listen { - fn props(&self) -> &ObjectProperties { - &self.object_props - } - - fn props_mut(&mut self) -> &mut ObjectProperties { - &mut self.object_props - } -} -impl Activity for Listen {} -impl ActivityExt for Listen { - fn props(&self) -> &ActivityProperties { - &self.activity_props - } - - fn props_mut(&mut self) -> &mut ActivityProperties { - &mut self.activity_props - } -} diff --git a/activitystreams-types/src/activity/offer.rs b/activitystreams-types/src/activity/offer.rs index 6e84907..05b268a 100644 --- a/activitystreams-types/src/activity/offer.rs +++ b/activitystreams-types/src/activity/offer.rs @@ -17,9 +17,9 @@ * along with ActivityStreams Types. If not, see . */ -use activitystreams_derive::Properties; +use activitystreams_derive::PropRefs; use activitystreams_traits::{Activity, Object}; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; use super::{ kind::OfferType, @@ -31,7 +31,7 @@ use crate::object::{properties::ObjectProperties, ObjectExt}; /// 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, Properties)] +#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] pub struct Offer { #[serde(rename = "type")] @@ -41,34 +41,16 @@ pub struct Offer { /// 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, } - -impl Object for Offer {} -impl ObjectExt for Offer { - fn props(&self) -> &ObjectProperties { - &self.object_props - } - - fn props_mut(&mut self) -> &mut ObjectProperties { - &mut self.object_props - } -} -impl Activity for Offer {} -impl ActivityExt for Offer { - fn props(&self) -> &ActivityProperties { - &self.activity_props - } - - fn props_mut(&mut self) -> &mut ActivityProperties { - &mut self.activity_props - } -} diff --git a/activitystreams-types/src/activity/properties.rs b/activitystreams-types/src/activity/properties.rs index c871243..d24775d 100644 --- a/activitystreams-types/src/activity/properties.rs +++ b/activitystreams-types/src/activity/properties.rs @@ -1,5 +1,4 @@ -/* - * This file is part of ActivityStreams Types. +/* This file is part of ActivityStreams Types. * * Copyright © 2018 Riley Trautman * @@ -27,9 +26,9 @@ //! activity::properties::ActivityProperties, //! object::properties::ObjectProperties, //! }; -//! use serde_derive::{Deserialize, Serialize}; +//! use serde::{Deserialize, Serialize}; //! -//! #[derive(Clone, Debug, Serialize, Deserialize)] +//! #[derive(Debug, Serialize, Deserialize)] //! #[serde(rename_all = "camelCase")] //! pub struct MyActivity { //! #[serde(rename = "type")] @@ -53,400 +52,582 @@ //! # fn main() {} //! ``` -use activitystreams_derive::Properties; -use activitystreams_traits::{Link, Object}; -use serde_derive::{Deserialize, Serialize}; +use crate::{link::LinkBox, object::ObjectBox, primitives::*}; +use activitystreams_derive::properties; -/// Activity objects are specializations of the base Object type that provide information about -/// actions that have either already occurred, are in the process of occurring, or may occur in the -/// future. -#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)] -#[serde(rename_all = "camelCase")] -pub struct ActivityProperties { - /// Describes the result of the activity. - /// - /// For instance, if a particular action results in the creation of a new resource, the result - /// property can be used to describe that new resource. - /// - /// - Range: `Object` | `Link` - /// - Funcitonal: false - #[serde(skip_serializing_if = "Option::is_none")] - #[activitystreams(ab(Object, Link), concrete(String))] - pub result: Option, +properties! { + Activity { + docs [ + "Activity objects are specializations of the base Object type that provide information about", + "actions that have either already occurred, are in the process of occurring, or may occur in the", + "future.", + ], - /// Identifies one or more objects used (or to be used) in the completion of an `Activity`. - /// - /// - Range: `Object` | `Link` - /// - Funcitonal: false - #[serde(skip_serializing_if = "Option::is_none")] - #[activitystreams(ab(Object, Link), concrete(String))] - pub instrument: Option, + result { + docs [ + "Describes the result of the activity.", + "", + "For instance, if a particular action results in the creation of a new resource, the result", + "property can be used to describe that new resource.", + "", + "- Range: `Object` | `Link`", + "- Funcitonal: false", + ], + types [ + XsdAnyUri, + ObjectBox, + LinkBox, + ], + }, + + instrument { + docs [ + "Identifies one or more objects used (or to be used) in the completion of an `Activity`.", + "", + "- Range: `Object` | `Link`", + "- Funcitonal: false", + ], + types [ + XsdAnyUri, + ObjectBox, + LinkBox, + ], + }, + } } -/// Struct with `actor` and optional `origin` and `target` properties -#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)] -#[serde(rename_all = "camelCase")] -pub struct ActorOptOriginAndTarget { - /// Describes one or more entities that either performed or are expected to perform the - /// activity. - /// - /// Any single activity can have multiple actors. The actor MAY be specified using an indirect - /// Link. - /// - /// - Range: `Object` | `Link` - /// - Functional: false - #[activitystreams(ab(Object, Link), concrete(String))] - pub actor: serde_json::Value, +properties! { + ActorOptOriginAndTarget { + docs [ "Struct with `actor` and optional `origin` and `target` properties" ], - /// Describes an indirect object of the activity from which the activity is directed. - /// - /// The precise meaning of the origin is the object of the English preposition "from". For - /// instance, in the activity "John moved an item to List B from List A", the origin of the - /// activity is "List A". - /// - /// - Range: `Object` | `Link` - /// - Functional: false - #[serde(skip_serializing_if = "Option::is_none")] - #[activitystreams(ab(Object, Link), concrete(String))] - pub origin: Option, + actor { + docs [ + "Describes one or more entities that either performed or are expected to perform the", + "activity.", + "", + "Any single activity can have multiple actors. The actor MAY be specified using an indirect", + "Link.", + "", + "- Range: `Object` | `Link`", + "- Functional: false", + ], + types [ + XsdAnyUri, + ObjectBox, + LinkBox, + ], + required + }, - /// Describes the indirect object, or target, of the activity. - /// - /// The precise meaning of the target is largely dependent on the type of action being - /// described but will often be the object of the English preposition "to". For instance, in - /// the activity "John added a movie to his wishlist", the target of the activity is John's - /// wishlist. An activity can have more than one target - /// - /// - Range: `Object` | `Link` - /// - Functional: false - #[serde(skip_serializing_if = "Option::is_none")] - #[activitystreams(ab(Object, Link), concrete(String))] - pub target: Option, + origin { + docs [ + "Describes an indirect object of the activity from which the activity is directed.", + "", + "The precise meaning of the origin is the object of the English preposition \"from\". For", + "instance, in the activity \"John moved an item to List B from List A\", the origin of the", + "activity is \"List A\".", + "", + "- Range: `Object` | `Link`", + "- Functional: false", + ], + types [ + XsdAnyUri, + ObjectBox, + LinkBox, + ], + }, + + target { + docs [ + "Describes the indirect object, or target, of the activity.", + "", + "The precise meaning of the target is largely dependent on the type of action being", + "described but will often be the object of the English preposition \"to\". For instance, in", + "the activity \"John added a movie to his wishlist\", the target of the activity is John's", + "wishlist. An activity can have more than one target", + "", + "- Range: `Object` | `Link`", + "- Functional: false", + ], + types [ + XsdAnyUri, + ObjectBox, + LinkBox, + ], + }, + } } -/// Struct with `actor` and `object` properties -#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)] -#[serde(rename_all = "camelCase")] -pub struct ActorAndObject { - /// Describes one or more entities that either performed or are expected to perform the - /// activity. - /// - /// Any single activity can have multiple actors. The actor MAY be specified using an indirect - /// Link. - /// - /// - Range: `Object` | `Link` - /// - Functional: false - #[activitystreams(ab(Object, Link), concrete(String))] - pub actor: serde_json::Value, +properties! { + ActorAndObject { + docs [ "Struct with `actor` and `object` properties" ], - /// When used within an Activity, describes the direct object of the activity. - /// - /// For instance, in the activity "John added a movie to his wishlist", the object of the - /// activity is the movie added. - /// - /// - Range: `Object` | `Link` - /// - Functional: false - #[activitystreams(ab(Object, Link), concrete(String))] - pub object: serde_json::Value, + actor { + docs [ + "Describes one or more entities that either performed or are expected to perform the", + "activity.", + "", + "Any single activity can have multiple actors. The actor MAY be specified using an indirect", + "Link.", + "", + "- Range: `Object` | `Link`", + "- Functional: false", + ], + types [ + XsdAnyUri, + ObjectBox, + LinkBox, + ], + required, + }, + + object { + docs [ + "When used within an Activity, describes the direct object of the activity.", + "", + "For instance, in the activity \"John added a movie to his wishlist\", the object of the", + "activity is the movie added.", + "", + "- Range: `Object` | `Link`", + "- Functional: false", + ], + types [ + XsdAnyUri, + ObjectBox, + LinkBox, + ], + required, + }, + } } -/// Struct with `actor`, `object`, and `target` properties -#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)] -#[serde(rename_all = "camelCase")] -pub struct ActorObjectAndTarget { - /// Describes one or more entities that either performed or are expected to perform the - /// activity. - /// - /// Any single activity can have multiple actors. The actor MAY be specified using an indirect - /// Link. - /// - /// - Range: `Object` | `Link` - /// - Functional: false - #[activitystreams(ab(Object, Link), concrete(String))] - pub actor: serde_json::Value, +properties! { + ActorObjectAndTarget { + docs [ "Struct with `actor`, `object`, and `target` properties" ], - /// When used within an Activity, describes the direct object of the activity. - /// - /// For instance, in the activity "John added a movie to his wishlist", the object of the - /// activity is the movie added. - /// - /// - Range: `Object` | `Link` - /// - Functional: false - #[activitystreams(ab(Object, Link), concrete(String))] - pub object: serde_json::Value, + actor { + docs [ + "Describes one or more entities that either performed or are expected to perform the", + "activity.", + "", + "Any single activity can have multiple actors. The actor MAY be specified using an indirect", + "Link.", + "", + "- Range: `Object` | `Link`", + "- Functional: false", + ], + types [ + XsdAnyUri, + ObjectBox, + LinkBox, + ], + required, + }, - /// Describes the indirect object, or target, of the activity. - /// - /// The precise meaning of the target is largely dependent on the type of action being - /// described but will often be the object of the English preposition "to". For instance, in - /// the activity "John added a movie to his wishlist", the target of the activity is John's - /// wishlist. An activity can have more than one target - /// - /// - Range: `Object` | `Link` - /// - Functional: false - #[activitystreams(ab(Object, Link), concrete(String))] - pub target: serde_json::Value, + object { + docs [ + "When used within an Activity, describes the direct object of the activity.", + "", + "For instance, in the activity \"John added a movie to his wishlist\", the object of the", + "activity is the movie added.", + "", + "- Range: `Object` | `Link`", + "- Functional: false", + ], + types [ + XsdAnyUri, + ObjectBox, + LinkBox, + ], + required, + }, + + target { + docs [ + "Describes the indirect object, or target, of the activity.", + "", + "The precise meaning of the target is largely dependent on the type of action being", + "described but will often be the object of the English preposition \"to\". For instance, in", + "the activity \"John added a movie to his wishlist\", the target of the activity is John's", + "wishlist. An activity can have more than one target", + "", + "- Range: `Object` | `Link`", + "- Functional: false", + ], + types [ + XsdAnyUri, + ObjectBox, + LinkBox, + ], + required, + }, + } } -/// Struct with `actor`, `object`, and optional `target` properties -#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)] -#[serde(rename_all = "camelCase")] -pub struct ActorAndObjectOptTarget { - /// Describes one or more entities that either performed or are expected to perform the - /// activity. - /// - /// Any single activity can have multiple actors. The actor MAY be specified using an indirect - /// Link. - /// - /// - Range: `Object` | `Link` - /// - Functional: false - #[activitystreams(ab(Object, Link), concrete(String))] - pub actor: serde_json::Value, +properties! { + ActorAndObjectOptTarget { + docs [ "Struct with `actor`, `object`, and optional `target` properties" ], - /// When used within an Activity, describes the direct object of the activity. - /// - /// For instance, in the activity "John added a movie to his wishlist", the object of the - /// activity is the movie added. - /// - /// - Range: `Object` | `Link` - /// - Functional: false - #[activitystreams(ab(Object, Link), concrete(String))] - pub object: serde_json::Value, + actor { + docs [ + "Describes one or more entities that either performed or are expected to perform the", + "activity.", + "", + "Any single activity can have multiple actors. The actor MAY be specified using an indirect", + "Link.", + "", + "- Range: `Object` | `Link`", + "- Functional: false", + ], + types [ + XsdAnyUri, + ObjectBox, + LinkBox, + ], + required, + }, - /// Describes the indirect object, or target, of the activity. - /// - /// The precise meaning of the target is largely dependent on the type of action being - /// described but will often be the object of the English preposition "to". For instance, in - /// the activity "John added a movie to his wishlist", the target of the activity is John's - /// wishlist. An activity can have more than one target - /// - /// - Range: `Object` | `Link` - /// - Functional: false - #[serde(skip_serializing_if = "Option::is_none")] - #[activitystreams(ab(Object, Link), concrete(String))] - pub target: Option, + object { + docs [ + "When used within an Activity, describes the direct object of the activity.", + "", + "For instance, in the activity \"John added a movie to his wishlist\", the object of the", + "activity is the movie added.", + "", + "- Range: `Object` | `Link`", + "- Functional: false", + ], + types [ + XsdAnyUri, + ObjectBox, + LinkBox, + ], + required, + }, + + target { + docs [ + "Describes the indirect object, or target, of the activity.", + "", + "The precise meaning of the target is largely dependent on the type of action being", + "described but will often be the object of the English preposition \"to\". For instance, in", + "the activity \"John added a movie to his wishlist\", the target of the activity is John's", + "wishlist. An activity can have more than one target", + "", + "- Range: `Object` | `Link`", + "- Functional: false", + ], + types [ + XsdAnyUri, + ObjectBox, + LinkBox, + ], + }, + } } -/// Struct with `actor`, `object`, and optional `origin` properties -#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)] -#[serde(rename_all = "camelCase")] -pub struct ActorAndObjectOptOrigin { - /// Describes one or more entities that either performed or are expected to perform the - /// activity. - /// - /// Any single activity can have multiple actors. The actor MAY be specified using an indirect - /// Link. - /// - /// - Range: `Object` | `Link` - /// - Functional: false - #[activitystreams(ab(Object, Link), concrete(String))] - pub actor: serde_json::Value, +properties! { + ActorAndObjectOptOrigin { + docs [ "Struct with `actor`, `object`, and optional `origin` properties" ], - /// When used within an Activity, describes the direct object of the activity. - /// - /// For instance, in the activity "John added a movie to his wishlist", the object of the - /// activity is the movie added. - /// - /// - Range: `Object` | `Link` - /// - Functional: false - #[activitystreams(ab(Object, Link), concrete(String))] - pub object: serde_json::Value, + actor { + docs [ + "Describes one or more entities that either performed or are expected to perform the", + "activity.", + "", + "Any single activity can have multiple actors. The actor MAY be specified using an indirect", + "Link.", + "", + "- Range: `Object` | `Link`", + "- Functional: false", + ], + types [ + XsdAnyUri, + ObjectBox, + LinkBox, + ], + required, + }, - /// Describes an indirect object of the activity from which the activity is directed. - /// - /// The precise meaning of the origin is the object of the English preposition "from". For - /// instance, in the activity "John moved an item to List B from List A", the origin of the - /// activity is "List A". - /// - /// - Range: `Object` | `Link` - /// - Functional: false - #[serde(skip_serializing_if = "Option::is_none")] - #[activitystreams(ab(Object, Link), concrete(String))] - pub origin: Option, + object { + docs [ + "When used within an Activity, describes the direct object of the activity.", + "", + "For instance, in the activity \"John added a movie to his wishlist\", the object of the", + "activity is the movie added.", + "", + "- Range: `Object` | `Link`", + "- Functional: false", + ], + types [ + XsdAnyUri, + ObjectBox, + LinkBox, + ], + required, + }, + + origin { + docs [ + "Describes an indirect object of the activity from which the activity is directed.", + "", + "The precise meaning of the origin is the object of the English preposition \"from\". For", + "instance, in the activity \"John moved an item to List B from List A\", the origin of the", + "activity is \"List A\".", + "", + "- Range: `Object` | `Link`", + "- Functional: false", + ], + types [ + XsdAnyUri, + ObjectBox, + LinkBox, + ], + }, + } } -/// Struct with `actor`, `object`, and optional `origin` and `target` properties -#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)] -#[serde(rename_all = "camelCase")] -pub struct ActorAndObjectOptOthers { - /// Describes one or more entities that either performed or are expected to perform the - /// activity. - /// - /// Any single activity can have multiple actors. The actor MAY be specified using an indirect - /// Link. - /// - /// - Range: `Object` | `Link` - /// - Functional: false - #[activitystreams(ab(Object, Link), concrete(String))] - pub actor: serde_json::Value, +properties! { + ActorAndObjectOptOthers { + docs [ "Struct with `actor`, `object`, and optional `origin` and `target` properties" ], - /// When used within an Activity, describes the direct object of the activity. - /// - /// For instance, in the activity "John added a movie to his wishlist", the object of the - /// activity is the movie added. - /// - /// - Range: `Object` | `Link` - /// - Functional: false - #[activitystreams(ab(Object, Link), concrete(String))] - pub object: serde_json::Value, + actor { + docs [ + "Describes one or more entities that either performed or are expected to perform the", + "activity.", + "", + "Any single activity can have multiple actors. The actor MAY be specified using an indirect", + "Link.", + "", + "- Range: `Object` | `Link`", + "- Functional: false", + ], + types [ + XsdAnyUri, + ObjectBox, + LinkBox, + ], + required, + }, - /// Describes an indirect object of the activity from which the activity is directed. - /// - /// The precise meaning of the origin is the object of the English preposition "from". For - /// instance, in the activity "John moved an item to List B from List A", the origin of the - /// activity is "List A". - /// - /// - Range: `Object` | `Link` - /// - Functional: false - #[serde(skip_serializing_if = "Option::is_none")] - #[activitystreams(ab(Object, Link), concrete(String))] - pub origin: Option, + object { + docs [ + "When used within an Activity, describes the direct object of the activity.", + "", + "For instance, in the activity \"John added a movie to his wishlist\", the object of the", + "activity is the movie added.", + "", + "- Range: `Object` | `Link`", + "- Functional: false", + ], + types [ + XsdAnyUri, + ObjectBox, + LinkBox, + ], + required, + }, - /// Describes the indirect object, or target, of the activity. - /// - /// The precise meaning of the target is largely dependent on the type of action being - /// described but will often be the object of the English preposition "to". For instance, in - /// the activity "John added a movie to his wishlist", the target of the activity is John's - /// wishlist. An activity can have more than one target - /// - /// - Range: `Object` | `Link` - /// - Functional: false - #[serde(skip_serializing_if = "Option::is_none")] - #[activitystreams(ab(Object, Link), concrete(String))] - pub target: Option, + origin { + docs [ + "Describes an indirect object of the activity from which the activity is directed.", + "", + "The precise meaning of the origin is the object of the English preposition \"from\". For", + "instance, in the activity \"John moved an item to List B from List A\", the origin of the", + "activity is \"List A\".", + "", + "- Range: `Object` | `Link`", + "- Functional: false", + ], + types [ + XsdAnyUri, + ObjectBox, + LinkBox, + ], + }, + + target { + docs [ + "Describes the indirect object, or target, of the activity.", + "", + "The precise meaning of the target is largely dependent on the type of action being", + "described but will often be the object of the English preposition \"to\". For instance, in", + "the activity \"John added a movie to his wishlist\", the target of the activity is John's", + "wishlist. An activity can have more than one target", + "", + "- Range: `Object` | `Link`", + "- Functional: false", + ], + types [ + XsdAnyUri, + ObjectBox, + LinkBox, + ], + }, + } } -/// Struct with `actor` and `origin` properties -#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)] -#[serde(rename_all = "camelCase")] -pub struct ActorAndOrigin { - /// Describes one or more entities that either performed or are expected to perform the - /// activity. - /// - /// Any single activity can have multiple actors. The actor MAY be specified using an indirect - /// Link. - /// - /// - Range: `Object` | `Link` - /// - Functional: false - #[activitystreams(ab(Object, Link), concrete(String))] - pub actor: serde_json::Value, +properties! { + ActorAndOrigin { + docs [ "Struct with `actor` and `origin` properties" ], - /// Describes an indirect object of the activity from which the activity is directed. - /// - /// The precise meaning of the origin is the object of the English preposition "from". For - /// instance, in the activity "John moved an item to List B from List A", the origin of the - /// activity is "List A". - /// - /// - Range: `Object` | `Link` - /// - Functional: false - #[activitystreams(ab(Object, Link), concrete(String))] - pub origin: serde_json::Value, + actor { + docs [ + "Describes one or more entities that either performed or are expected to perform the", + "activity.", + "", + "Any single activity can have multiple actors. The actor MAY be specified using an indirect", + "Link.", + "", + "- Range: `Object` | `Link`", + "- Functional: false", + ], + types [ + XsdString, + ObjectBox, + LinkBox, + ], + required, + }, + + origin { + docs [ + "Describes an indirect object of the activity from which the activity is directed.", + "", + "The precise meaning of the origin is the object of the English preposition \"from\". For", + "instance, in the activity \"John moved an item to List B from List A\", the origin of the", + "activity is \"List A\".", + "", + "- Range: `Object` | `Link`", + "- Functional: false", + ], + types [ + XsdAnyUri, + ObjectBox, + LinkBox, + ], + required, + }, + } } /// Properties for the Accept activity -pub type AcceptProperties = ActorAndObject; +pub type AcceptProperties = ActorAndObjectProperties; /// Properties for the Add activity -pub type AddProperties = ActorAndObject; +pub type AddProperties = ActorAndObjectProperties; /// Properties for the Move activity -pub type MoveProperties = ActorAndObjectOptOthers; +pub type MoveProperties = ActorAndObjectOptOthersProperties; /// Properties for the Announce activity -pub type AnnounceProperties = ActorAndObjectOptTarget; +pub type AnnounceProperties = ActorAndObjectOptTargetProperties; /// Properties for the Arrive activity -pub type ArriveProperties = ActorAndOrigin; +pub type ArriveProperties = ActorAndOriginProperties; /// Properties for the Block activity -pub type BlockProperties = ActorAndObject; +pub type BlockProperties = ActorAndObjectProperties; /// Properties for the Create activity -pub type CreateProperties = ActorAndObject; +pub type CreateProperties = ActorAndObjectProperties; /// Properties for the Delete activity -pub type DeleteProperties = ActorAndObjectOptOrigin; +pub type DeleteProperties = ActorAndObjectOptOriginProperties; /// Properties for the Dislike activity -pub type DislikeProperties = ActorAndObject; +pub type DislikeProperties = ActorAndObjectProperties; /// Properties for the Flag activity -pub type FlagProperties = ActorAndObject; +pub type FlagProperties = ActorAndObjectProperties; /// Properties for the Follow activity -pub type FollowProperties = ActorAndObject; +pub type FollowProperties = ActorAndObjectProperties; /// Properties for the Ignore activity -pub type IgnoreProperties = ActorAndObject; +pub type IgnoreProperties = ActorAndObjectProperties; /// Properties for the Invite activity -pub type InviteProperties = ActorObjectAndTarget; +pub type InviteProperties = ActorObjectAndTargetProperties; /// Properties for the Join activity -pub type JoinProperties = ActorAndObject; +pub type JoinProperties = ActorAndObjectProperties; /// Properties for the Leave activity -pub type LeaveProperties = ActorAndObject; +pub type LeaveProperties = ActorAndObjectProperties; /// Properties for the Like activity -pub type LikeProperties = ActorAndObject; +pub type LikeProperties = ActorAndObjectProperties; /// Properties for the Listen activity -pub type ListenProperties = ActorAndObject; +pub type ListenProperties = ActorAndObjectProperties; /// Properties for the Offer activity -pub type OfferProperties = ActorAndObjectOptTarget; +pub type OfferProperties = ActorAndObjectOptTargetProperties; -/// Properties for the Question activity -#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)] -#[serde(rename_all = "camelCase")] -pub struct QuestionProperties { - /// Identifies an exclusive option for a Question. - /// - /// Use of `one_of` implies that the Question can have only a single answer. To indicate that a - /// `Question` can have multiple answers, use `any_of`. - /// - /// - Range: `Object` | `Link` - /// - Functional: false - #[serde(skip_serializing_if = "Option::is_none")] - #[activitystreams(ab(Object, Link), concrete(String))] - pub one_of: Option, +properties! { + Question { + docs [ "Properties for the Question activity" ], - /// Identifies an inclusive option for a Question. - /// - /// Use of `any_of` implies that the Question can have multiple answers. To indicate that a - /// `Question` can have only one answer, use `one_of`. - /// - /// - Range: `Object` | `Link` - /// - Functional: false - #[serde(skip_serializing_if = "Option::is_none")] - #[activitystreams(ab(Object, Link), concrete(String))] - pub any_of: Option, + one_of { + docs [ + "Identifies an exclusive option for a Question.", + "", + "Use of `one_of` implies that the Question can have only a single answer. To indicate that a", + "`Question` can have multiple answers, use `any_of`.", + "", + "- Range: `Object` | `Link`", + "- Functional: false", + ], + types [ + XsdAnyUri, + ObjectBox, + LinkBox, + ], + }, + + any_of { + docs [ + "Identifies an inclusive option for a Question.", + "", + "Use of `any_of` implies that the Question can have multiple answers. To indicate that a", + "`Question` can have only one answer, use `one_of`.", + "", + "- Range: `Object` | `Link`", + "- Functional: false", + ], + types [ + XsdAnyUri, + ObjectBox, + LinkBox, + ], + }, + } } /// Properties for the Read activity -pub type ReadProperties = ActorAndObject; +pub type ReadProperties = ActorAndObjectProperties; /// Properties for the Reject activity -pub type RejectProperties = ActorAndObject; +pub type RejectProperties = ActorAndObjectProperties; /// Properties for the Remove activity -pub type RemoveProperties = ActorAndObjectOptOthers; +pub type RemoveProperties = ActorAndObjectOptOthersProperties; /// Properties for the TentativeAccept activity -pub type TentativeAcceptProperties = ActorAndObject; +pub type TentativeAcceptProperties = ActorAndObjectProperties; /// Properties for the TentativeReject activity -pub type TentativeRejectProperties = ActorAndObject; +pub type TentativeRejectProperties = ActorAndObjectProperties; /// Properties for the Travel activity -pub type TravelProperties = ActorOptOriginAndTarget; +pub type TravelProperties = ActorOptOriginAndTargetProperties; /// Properties for the Undo activity -pub type UndoProperties = ActorAndObject; +pub type UndoProperties = ActorAndObjectProperties; /// Properties for the Update activity -pub type UpdateProperties = ActorAndObject; +pub type UpdateProperties = ActorAndObjectProperties; /// Properties for the View activity -pub type ViewProperties = ActorAndObject; +pub type ViewProperties = ActorAndObjectProperties; diff --git a/activitystreams-types/src/activity/question.rs b/activitystreams-types/src/activity/question.rs index 5e1d10a..d411ba2 100644 --- a/activitystreams-types/src/activity/question.rs +++ b/activitystreams-types/src/activity/question.rs @@ -17,9 +17,9 @@ * along with ActivityStreams Types. If not, see . */ -use activitystreams_derive::Properties; +use activitystreams_derive::PropRefs; use activitystreams_traits::{Activity, IntransitiveActivity, Object}; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; use super::{ kind::QuestionType, @@ -36,7 +36,7 @@ use crate::object::{properties::ObjectProperties, ObjectExt}; /// /// 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, Properties)] +#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] pub struct Question { #[serde(rename = "type")] @@ -46,35 +46,18 @@ pub struct Question { /// 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 Object for Question {} -impl ObjectExt for Question { - fn props(&self) -> &ObjectProperties { - &self.object_props - } - - fn props_mut(&mut self) -> &mut ObjectProperties { - &mut self.object_props - } -} -impl Activity for Question {} -impl ActivityExt for Question { - fn props(&self) -> &ActivityProperties { - &self.activity_props - } - - fn props_mut(&mut self) -> &mut ActivityProperties { - &mut self.activity_props - } -} impl IntransitiveActivity for Question {} diff --git a/activitystreams-types/src/activity/read.rs b/activitystreams-types/src/activity/read.rs index 95ee730..56bc05e 100644 --- a/activitystreams-types/src/activity/read.rs +++ b/activitystreams-types/src/activity/read.rs @@ -17,9 +17,9 @@ * along with ActivityStreams Types. If not, see . */ -use activitystreams_derive::Properties; +use activitystreams_derive::PropRefs; use activitystreams_traits::{Activity, Object}; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; use super::{ kind::ReadType, @@ -29,7 +29,7 @@ use super::{ use crate::object::{properties::ObjectProperties, ObjectExt}; /// Indicates that the actor has read the object. -#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)] +#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] pub struct Read { #[serde(rename = "type")] @@ -39,34 +39,16 @@ pub struct Read { /// 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, } - -impl Object for Read {} -impl ObjectExt for Read { - fn props(&self) -> &ObjectProperties { - &self.object_props - } - - fn props_mut(&mut self) -> &mut ObjectProperties { - &mut self.object_props - } -} -impl Activity for Read {} -impl ActivityExt for Read { - fn props(&self) -> &ActivityProperties { - &self.activity_props - } - - fn props_mut(&mut self) -> &mut ActivityProperties { - &mut self.activity_props - } -} diff --git a/activitystreams-types/src/activity/reject.rs b/activitystreams-types/src/activity/reject.rs index b973f20..993d4f4 100644 --- a/activitystreams-types/src/activity/reject.rs +++ b/activitystreams-types/src/activity/reject.rs @@ -17,9 +17,9 @@ * along with ActivityStreams Types. If not, see . */ -use activitystreams_derive::Properties; +use activitystreams_derive::PropRefs; use activitystreams_traits::{Activity, Object}; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; use super::{ kind::RejectType, @@ -31,7 +31,7 @@ use crate::object::{properties::ObjectProperties, ObjectExt}; /// Indicates that the actor is rejecting the object. /// /// The target and origin typically have no defined meaning. -#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)] +#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] pub struct Reject { #[serde(rename = "type")] @@ -41,34 +41,16 @@ pub struct Reject { /// 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, } - -impl Object for Reject {} -impl ObjectExt for Reject { - fn props(&self) -> &ObjectProperties { - &self.object_props - } - - fn props_mut(&mut self) -> &mut ObjectProperties { - &mut self.object_props - } -} -impl Activity for Reject {} -impl ActivityExt for Reject { - fn props(&self) -> &ActivityProperties { - &self.activity_props - } - - fn props_mut(&mut self) -> &mut ActivityProperties { - &mut self.activity_props - } -} diff --git a/activitystreams-types/src/activity/remove.rs b/activitystreams-types/src/activity/remove.rs index 46cd916..d425e0c 100644 --- a/activitystreams-types/src/activity/remove.rs +++ b/activitystreams-types/src/activity/remove.rs @@ -17,9 +17,9 @@ * along with ActivityStreams Types. If not, see . */ -use activitystreams_derive::Properties; +use activitystreams_derive::PropRefs; use activitystreams_traits::{Activity, Object}; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; use super::{ kind::RemoveType, @@ -31,7 +31,7 @@ use crate::object::{properties::ObjectProperties, ObjectExt}; /// 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, Properties)] +#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] pub struct Remove { #[serde(rename = "type")] @@ -41,34 +41,16 @@ pub struct Remove { /// 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, } - -impl Object for Remove {} -impl ObjectExt for Remove { - fn props(&self) -> &ObjectProperties { - &self.object_props - } - - fn props_mut(&mut self) -> &mut ObjectProperties { - &mut self.object_props - } -} -impl Activity for Remove {} -impl ActivityExt for Remove { - fn props(&self) -> &ActivityProperties { - &self.activity_props - } - - fn props_mut(&mut self) -> &mut ActivityProperties { - &mut self.activity_props - } -} diff --git a/activitystreams-types/src/activity/tentative_accept.rs b/activitystreams-types/src/activity/tentative_accept.rs index 20180b7..a72f66b 100644 --- a/activitystreams-types/src/activity/tentative_accept.rs +++ b/activitystreams-types/src/activity/tentative_accept.rs @@ -17,9 +17,9 @@ * along with ActivityStreams Types. If not, see . */ -use activitystreams_derive::Properties; +use activitystreams_derive::PropRefs; use activitystreams_traits::{Activity, Object}; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; use super::{ kind::TentativeAcceptType, @@ -29,7 +29,7 @@ use super::{ use crate::object::{properties::ObjectProperties, ObjectExt}; /// A specialization of Accept indicating that the acceptance is tentative. -#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)] +#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] pub struct TentativeAccept { #[serde(rename = "type")] @@ -39,34 +39,16 @@ pub struct TentativeAccept { /// 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, } - -impl Object for TentativeAccept {} -impl ObjectExt for TentativeAccept { - fn props(&self) -> &ObjectProperties { - &self.object_props - } - - fn props_mut(&mut self) -> &mut ObjectProperties { - &mut self.object_props - } -} -impl Activity for TentativeAccept {} -impl ActivityExt for TentativeAccept { - fn props(&self) -> &ActivityProperties { - &self.activity_props - } - - fn props_mut(&mut self) -> &mut ActivityProperties { - &mut self.activity_props - } -} diff --git a/activitystreams-types/src/activity/tentative_reject.rs b/activitystreams-types/src/activity/tentative_reject.rs index 988bab1..f34fe2e 100644 --- a/activitystreams-types/src/activity/tentative_reject.rs +++ b/activitystreams-types/src/activity/tentative_reject.rs @@ -17,9 +17,9 @@ * along with ActivityStreams Types. If not, see . */ -use activitystreams_derive::Properties; +use activitystreams_derive::PropRefs; use activitystreams_traits::{Activity, Object}; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; use super::{ kind::TentativeRejectType, @@ -29,7 +29,7 @@ use super::{ use crate::object::{properties::ObjectProperties, ObjectExt}; /// A specialization of Reject in which the rejection is considered tentative. -#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)] +#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] pub struct TentativeReject { #[serde(rename = "type")] @@ -39,34 +39,16 @@ pub struct TentativeReject { /// 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, } - -impl Object for TentativeReject {} -impl ObjectExt for TentativeReject { - fn props(&self) -> &ObjectProperties { - &self.object_props - } - - fn props_mut(&mut self) -> &mut ObjectProperties { - &mut self.object_props - } -} -impl Activity for TentativeReject {} -impl ActivityExt for TentativeReject { - fn props(&self) -> &ActivityProperties { - &self.activity_props - } - - fn props_mut(&mut self) -> &mut ActivityProperties { - &mut self.activity_props - } -} diff --git a/activitystreams-types/src/activity/travel.rs b/activitystreams-types/src/activity/travel.rs index 2565519..32025c5 100644 --- a/activitystreams-types/src/activity/travel.rs +++ b/activitystreams-types/src/activity/travel.rs @@ -17,9 +17,9 @@ * along with ActivityStreams Types. If not, see . */ -use activitystreams_derive::Properties; +use activitystreams_derive::PropRefs; use activitystreams_traits::{Activity, IntransitiveActivity, Object}; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; use super::{ kind::TravelType, @@ -32,7 +32,7 @@ use crate::object::{properties::ObjectProperties, ObjectExt}; /// /// 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, Properties)] +#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] pub struct Travel { #[serde(rename = "type")] @@ -42,35 +42,18 @@ pub struct Travel { /// 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 Object for Travel {} -impl ObjectExt for Travel { - fn props(&self) -> &ObjectProperties { - &self.object_props - } - - fn props_mut(&mut self) -> &mut ObjectProperties { - &mut self.object_props - } -} -impl Activity for Travel {} -impl ActivityExt for Travel { - fn props(&self) -> &ActivityProperties { - &self.activity_props - } - - fn props_mut(&mut self) -> &mut ActivityProperties { - &mut self.activity_props - } -} impl IntransitiveActivity for Travel {} diff --git a/activitystreams-types/src/activity/undo.rs b/activitystreams-types/src/activity/undo.rs index 86771f6..315ece6 100644 --- a/activitystreams-types/src/activity/undo.rs +++ b/activitystreams-types/src/activity/undo.rs @@ -17,9 +17,9 @@ * along with ActivityStreams Types. If not, see . */ -use activitystreams_derive::Properties; +use activitystreams_derive::PropRefs; use activitystreams_traits::{Activity, Object}; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; use super::{ kind::UndoType, @@ -35,7 +35,7 @@ use crate::object::{properties::ObjectProperties, ObjectExt}; /// 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, Properties)] +#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] pub struct Undo { #[serde(rename = "type")] @@ -45,34 +45,16 @@ pub struct Undo { /// 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, } - -impl Object for Undo {} -impl ObjectExt for Undo { - fn props(&self) -> &ObjectProperties { - &self.object_props - } - - fn props_mut(&mut self) -> &mut ObjectProperties { - &mut self.object_props - } -} -impl Activity for Undo {} -impl ActivityExt for Undo { - fn props(&self) -> &ActivityProperties { - &self.activity_props - } - - fn props_mut(&mut self) -> &mut ActivityProperties { - &mut self.activity_props - } -} diff --git a/activitystreams-types/src/activity/update.rs b/activitystreams-types/src/activity/update.rs index 1b1b8c3..0b09263 100644 --- a/activitystreams-types/src/activity/update.rs +++ b/activitystreams-types/src/activity/update.rs @@ -17,9 +17,9 @@ * along with ActivityStreams Types. If not, see . */ -use activitystreams_derive::Properties; +use activitystreams_derive::PropRefs; use activitystreams_traits::{Activity, Object}; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; use super::{ kind::UpdateType, @@ -34,7 +34,7 @@ use crate::object::{properties::ObjectProperties, ObjectExt}; /// of modifications made to object. /// /// The target and origin typically have no defined meaning. -#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)] +#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] pub struct Update { #[serde(rename = "type")] @@ -44,34 +44,16 @@ pub struct Update { /// 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, } - -impl Object for Update {} -impl ObjectExt for Update { - fn props(&self) -> &ObjectProperties { - &self.object_props - } - - fn props_mut(&mut self) -> &mut ObjectProperties { - &mut self.object_props - } -} -impl Activity for Update {} -impl ActivityExt for Update { - fn props(&self) -> &ActivityProperties { - &self.activity_props - } - - fn props_mut(&mut self) -> &mut ActivityProperties { - &mut self.activity_props - } -} diff --git a/activitystreams-types/src/activity/view.rs b/activitystreams-types/src/activity/view.rs index bfa3d6f..1395e19 100644 --- a/activitystreams-types/src/activity/view.rs +++ b/activitystreams-types/src/activity/view.rs @@ -17,9 +17,9 @@ * along with ActivityStreams Types. If not, see . */ -use activitystreams_derive::Properties; +use activitystreams_derive::PropRefs; use activitystreams_traits::{Activity, Object}; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; use super::{ kind::ViewType, @@ -29,7 +29,7 @@ use super::{ use crate::object::{properties::ObjectProperties, ObjectExt}; /// Indicates that the actor has viewed the object. -#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)] +#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)] #[serde(rename_all = "camelCase")] pub struct View { #[serde(rename = "type")] @@ -39,34 +39,16 @@ pub struct View { /// 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, } - -impl Object for View {} -impl ObjectExt for View { - fn props(&self) -> &ObjectProperties { - &self.object_props - } - - fn props_mut(&mut self) -> &mut ObjectProperties { - &mut self.object_props - } -} -impl Activity for View {} -impl ActivityExt for View { - fn props(&self) -> &ActivityProperties { - &self.activity_props - } - - fn props_mut(&mut self) -> &mut ActivityProperties { - &mut self.activity_props - } -} diff --git a/activitystreams-types/src/actor/mod.rs b/activitystreams-types/src/actor/mod.rs index bb16982..27b96b7 100644 --- a/activitystreams-types/src/actor/mod.rs +++ b/activitystreams-types/src/actor/mod.rs @@ -19,8 +19,9 @@ //! Namespace for Actor types +use activitystreams_derive::PropRefs; use activitystreams_traits::{Actor, Object}; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; use crate::object::{properties::ObjectProperties, ObjectExt}; @@ -28,7 +29,7 @@ pub mod kind; use self::kind::*; /// Describes a software application. -#[derive(Clone, Debug, Default, Deserialize, Serialize)] +#[derive(Clone, Debug, Default, Deserialize, PropRefs, Serialize)] #[serde(rename_all = "camelCase")] pub struct Application { #[serde(rename = "type")] @@ -38,23 +39,14 @@ pub struct Application { /// Adds all valid object properties to this struct #[serde(flatten)] + #[activitystreams(Object)] pub object_props: ObjectProperties, } -impl Object for Application {} -impl ObjectExt for Application { - fn props(&self) -> &ObjectProperties { - &self.object_props - } - - fn props_mut(&mut self) -> &mut ObjectProperties { - &mut self.object_props - } -} impl Actor for Application {} /// Represents a formal or informal collective of Actors. -#[derive(Clone, Debug, Default, Deserialize, Serialize)] +#[derive(Clone, Debug, Default, Deserialize, PropRefs, Serialize)] #[serde(rename_all = "camelCase")] pub struct Group { #[serde(rename = "type")] @@ -64,23 +56,14 @@ pub struct Group { /// Adds all valid object properties to this struct #[serde(flatten)] + #[activitystreams(Object)] pub object_props: ObjectProperties, } -impl Object for Group {} -impl ObjectExt for Group { - fn props(&self) -> &ObjectProperties { - &self.object_props - } - - fn props_mut(&mut self) -> &mut ObjectProperties { - &mut self.object_props - } -} impl Actor for Group {} /// Represents an organization. -#[derive(Clone, Debug, Default, Deserialize, Serialize)] +#[derive(Clone, Debug, Default, Deserialize, PropRefs, Serialize)] #[serde(rename_all = "camelCase")] pub struct Organization { #[serde(rename = "type")] @@ -90,23 +73,14 @@ pub struct Organization { /// Adds all valid object properties to this struct #[serde(flatten)] + #[activitystreams(Object)] pub object_props: ObjectProperties, } -impl Object for Organization {} -impl ObjectExt for Organization { - fn props(&self) -> &ObjectProperties { - &self.object_props - } - - fn props_mut(&mut self) -> &mut ObjectProperties { - &mut self.object_props - } -} impl Actor for Organization {} /// Represents an individual person. -#[derive(Clone, Debug, Default, Deserialize, Serialize)] +#[derive(Clone, Debug, Default, Deserialize, PropRefs, Serialize)] #[serde(rename_all = "camelCase")] pub struct Person { #[serde(rename = "type")] @@ -116,23 +90,14 @@ pub struct Person { /// Adds all valid object properties to this struct #[serde(flatten)] + #[activitystreams(Object)] pub object_props: ObjectProperties, } -impl Object for Person {} -impl ObjectExt for Person { - fn props(&self) -> &ObjectProperties { - &self.object_props - } - - fn props_mut(&mut self) -> &mut ObjectProperties { - &mut self.object_props - } -} impl Actor for Person {} /// Represents a service of any kind. -#[derive(Clone, Debug, Default, Deserialize, Serialize)] +#[derive(Clone, Debug, Default, Deserialize, PropRefs, Serialize)] #[serde(rename_all = "camelCase")] pub struct Service { #[serde(rename = "type")] @@ -142,17 +107,8 @@ pub struct Service { /// Adds all valid object properties to this struct #[serde(flatten)] + #[activitystreams(Object)] pub object_props: ObjectProperties, } -impl Object for Service {} -impl ObjectExt for Service { - fn props(&self) -> &ObjectProperties { - &self.object_props - } - - fn props_mut(&mut self) -> &mut ObjectProperties { - &mut self.object_props - } -} impl Actor for Service {} diff --git a/activitystreams-types/src/collection/mod.rs b/activitystreams-types/src/collection/mod.rs index a444f5a..9b2dec8 100644 --- a/activitystreams-types/src/collection/mod.rs +++ b/activitystreams-types/src/collection/mod.rs @@ -19,9 +19,9 @@ //! Namespace for Collection types -use activitystreams_derive::Properties; +use activitystreams_derive::PropRefs; use activitystreams_traits::{Collection, CollectionPage, Object}; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; use crate::object::{properties::ObjectProperties, ObjectExt}; @@ -46,8 +46,16 @@ pub trait CollectionPageExt: CollectionPage { fn props_mut(&mut self) -> &mut CollectionPageProperties; } +#[derive(Debug, Deserialize, Serialize)] +#[serde(transparent)] +pub struct CollectionBox(pub Box); + +#[derive(Debug, Deserialize, Serialize)] +#[serde(transparent)] +pub struct CollectionPageBox(pub Box); + /// The default `Collection` type. -#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)] +#[derive(Clone, Debug, Default, Deserialize, PropRefs, Serialize)] #[serde(rename_all = "camelCase")] pub struct UnorderedCollection { #[serde(rename = "type")] @@ -57,37 +65,18 @@ pub struct UnorderedCollection { /// Adds all valid object properties to this struct #[serde(flatten)] + #[activitystreams(Object)] pub object_props: ObjectProperties, /// Adds all valid collection properties to this struct #[serde(flatten)] + #[activitystreams(Collection)] pub collection_props: CollectionProperties, } -impl Object for UnorderedCollection {} -impl ObjectExt for UnorderedCollection { - fn props(&self) -> &ObjectProperties { - &self.object_props - } - - fn props_mut(&mut self) -> &mut ObjectProperties { - &mut self.object_props - } -} -impl Collection for UnorderedCollection {} -impl CollectionExt for UnorderedCollection { - fn props(&self) -> &CollectionProperties { - &self.collection_props - } - - fn props_mut(&mut self) -> &mut CollectionProperties { - &mut self.collection_props - } -} - /// A subtype of `Collection` in which members of the logical collection are assumed to always be /// strictly ordered. -#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)] +#[derive(Clone, Debug, Default, Deserialize, PropRefs, Serialize)] #[serde(rename_all = "camelCase")] pub struct OrderedCollection { #[serde(rename = "type")] @@ -97,36 +86,17 @@ pub struct OrderedCollection { /// Adds all valid object properties to this struct #[serde(flatten)] + #[activitystreams(Object)] pub object_props: ObjectProperties, /// Adds all valid collection properties to this struct #[serde(flatten)] + #[activitystreams(Collection)] pub collection_props: CollectionProperties, } -impl Object for OrderedCollection {} -impl ObjectExt for OrderedCollection { - fn props(&self) -> &ObjectProperties { - &self.object_props - } - - fn props_mut(&mut self) -> &mut ObjectProperties { - &mut self.object_props - } -} -impl Collection for OrderedCollection {} -impl CollectionExt for OrderedCollection { - fn props(&self) -> &CollectionProperties { - &self.collection_props - } - - fn props_mut(&mut self) -> &mut CollectionProperties { - &mut self.collection_props - } -} - /// Used to represent distinct subsets of items from a `Collection`. -#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)] +#[derive(Clone, Debug, Default, Deserialize, PropRefs, Serialize)] #[serde(rename_all = "camelCase")] pub struct UnorderedCollectionPage { #[serde(rename = "type")] @@ -136,50 +106,22 @@ pub struct UnorderedCollectionPage { /// Adds all valid object properties to this struct #[serde(flatten)] + #[activitystreams(Object)] pub object_props: ObjectProperties, /// Adds all valid collection properties to this struct #[serde(flatten)] + #[activitystreams(Collection)] pub collection_props: CollectionProperties, /// Adds all valid collection page properties to this struct #[serde(flatten)] + #[activitystreams(CollectionPage)] pub collection_page_props: CollectionPageProperties, } -impl Object for UnorderedCollectionPage {} -impl ObjectExt for UnorderedCollectionPage { - fn props(&self) -> &ObjectProperties { - &self.object_props - } - - fn props_mut(&mut self) -> &mut ObjectProperties { - &mut self.object_props - } -} -impl Collection for UnorderedCollectionPage {} -impl CollectionExt for UnorderedCollectionPage { - fn props(&self) -> &CollectionProperties { - &self.collection_props - } - - fn props_mut(&mut self) -> &mut CollectionProperties { - &mut self.collection_props - } -} -impl CollectionPage for UnorderedCollectionPage {} -impl CollectionPageExt for UnorderedCollectionPage { - fn props(&self) -> &CollectionPageProperties { - &self.collection_page_props - } - - fn props_mut(&mut self) -> &mut CollectionPageProperties { - &mut self.collection_page_props - } -} - /// Used to represent ordered subsets of items from an `OrderedCollection`. -#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)] +#[derive(Clone, Debug, Default, Deserialize, PropRefs, Serialize)] #[serde(rename_all = "camelCase")] pub struct OrderedCollectionPage { #[serde(rename = "type")] @@ -189,48 +131,97 @@ pub struct OrderedCollectionPage { /// Adds all valid object properties to this struct #[serde(flatten)] + #[activitystreams(Object)] pub object_props: ObjectProperties, /// Adds all valid collection properties to this struct #[serde(flatten)] + #[activitystreams(Collection)] pub collection_props: CollectionProperties, /// Adds all valid collection page properties to this struct #[serde(flatten)] + #[activitystreams(CollectionPage)] pub collection_page_props: CollectionPageProperties, /// Adds all valid ordered collection page properties to this struct #[serde(flatten)] + #[activitystreams(None)] pub ordered_collection_page_props: OrderedCollectionPageProperties, } -impl Object for OrderedCollectionPage {} -impl ObjectExt for OrderedCollectionPage { - fn props(&self) -> &ObjectProperties { - &self.object_props +impl CollectionBox { + pub fn is(&self) -> bool + where + T: Collection + 'static, + { + self.0.as_any().is::() } - fn props_mut(&mut self) -> &mut ObjectProperties { - &mut self.object_props - } -} -impl Collection for OrderedCollectionPage {} -impl CollectionExt for OrderedCollectionPage { - fn props(&self) -> &CollectionProperties { - &self.collection_props + pub fn downcast_ref(&self) -> Option<&T> + where + T: Collection + 'static, + { + self.0.as_any().downcast_ref() } - fn props_mut(&mut self) -> &mut CollectionProperties { - &mut self.collection_props + pub fn downcast_mut(&mut self) -> Option<&mut T> + where + T: Collection + 'static, + { + self.0.as_any_mut().downcast_mut() } } -impl CollectionPage for OrderedCollectionPage {} -impl CollectionPageExt for OrderedCollectionPage { - fn props(&self) -> &CollectionPageProperties { - &self.collection_page_props + +impl CollectionPageBox { + pub fn is(&self) -> bool + where + T: CollectionPage + 'static, + { + self.0.as_any().is::() } - fn props_mut(&mut self) -> &mut CollectionPageProperties { - &mut self.collection_page_props + 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() + } +} + +impl Clone for CollectionBox { + fn clone(&self) -> Self { + CollectionBox(self.0.duplicate()) + } +} + +impl Clone for CollectionPageBox { + fn clone(&self) -> Self { + CollectionPageBox(self.0.duplicate()) + } +} + +impl From for CollectionBox +where + T: Collection + 'static, +{ + fn from(t: T) -> Self { + CollectionBox(Box::new(t)) + } +} + +impl From for CollectionPageBox +where + T: CollectionPage + 'static, +{ + fn from(t: T) -> Self { + CollectionPageBox(Box::new(t)) } } diff --git a/activitystreams-types/src/collection/properties.rs b/activitystreams-types/src/collection/properties.rs index da3a9ab..e0569ad 100644 --- a/activitystreams-types/src/collection/properties.rs +++ b/activitystreams-types/src/collection/properties.rs @@ -27,15 +27,15 @@ //! collection::properties::CollectionProperties, //! object::properties::ObjectProperties, //! }; -//! use serde_derive::{Deserialize, Serialize}; +//! use serde::{Deserialize, Serialize}; //! -//! #[derive(Clone, Debug, Serialize, Deserialize)] +//! #[derive(Debug, Serialize, Deserialize)] //! #[serde(rename_all = "camelCase")] //! pub struct MyCollection { //! #[serde(rename = "type")] //! pub kind: String, //! -//! /// Define a require property for the MyCollection type +//! docs("Define a require property for the MyCollection type"), //! pub my_property: String, //! //! #[serde(flatten)] @@ -51,105 +51,173 @@ //! # fn main() {} //! ``` -use activitystreams_derive::Properties; -use activitystreams_traits::{Collection, CollectionPage, Link, Object}; -use serde_derive::{Deserialize, Serialize}; +use crate::{ + collection::{CollectionBox, CollectionPageBox}, + link::LinkBox, + object::ObjectBox, + primitives::*, +}; +use activitystreams_derive::properties; -/// `Collection` objects are a specialization of the base `Object` that serve as a container for -/// other `Objects` or `Links`. -/// -/// The items within a `Collection` can be ordered or unordered. The `OrderedCollection` type MAY be -/// used to identify a `Collection` whose items are always ordered. In the JSON serialization, the -/// unordered items of a `Collection` are represented using the `items` property while ordered items -/// are represented using the `ordered_items` property. -#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)] -#[serde(rename_all = "camelCase")] -pub struct CollectionProperties { - /// Identifies the items contained in a collection. The items might be ordered or unordered. - /// - /// - Range: `Object` | `Link` | Ordered List of [ `Object` | `Link` ] - /// - Functional: false - #[activitystreams(ab(Object, Link), concrete(String))] - pub items: serde_json::Value, +properties! { + Collection { + docs [ + "`Collection` objects are a specialization of the base `Object` that serve as a container for", + "other `Objects` or `Links`.", + "", + "The items within a `Collection` can be ordered or unordered. The `OrderedCollection` type MAY be", + "used to identify a `Collection` whose items are always ordered. In the JSON serialization, the", + "unordered items of a `Collection` are represented using the `items` property while ordered items", + "are represented using the `ordered_items` property.", + ], - /// A non-negative integer specifying the total number of objects contained by the logical view - /// of the collection. - /// - /// This number might not reflect the actual number of items serialized within the `Collection` - /// object instance. - /// - /// - Range: `xsd:nonNegativeInteger` - /// - Functional: true - #[serde(skip_serializing_if = "Option::is_none")] - #[activitystreams(concrete(u64), functional)] - pub total_items: Option, + items { + docs [ + "Identifies the items contained in a collection. The items might be ordered or unordered.", + "", + "- Range: `Object` | `Link` | Ordered List of [ `Object` | `Link` ]", + "- Functional: false", + ], + types [ + XsdString, + ObjectBox, + LinkBox, + ], + required, + }, - /// In a paged `Collection`, indicates the page that contains the most recently updated member - /// items. - /// - /// - Range: `CollectionPage` | `Link` - /// - Functional: true - #[serde(skip_serializing_if = "Option::is_none")] - #[activitystreams(ab(Link, CollectionPage), concrete(String), functional)] - pub current: Option, + total_items { + docs [ + "A non-negative integer specifying the total number of objects contained by the logical view", + "of the collection.", + "", + "This number might not reflect the actual number of items serialized within the `Collection`", + "object instance.", + "", + "- Range: `xsd:nonNegativeInteger`", + "- Functional: true", + ], + types [ + XsdNonNegativeInteger, + ], + functional, + }, - /// In a paged `Collection`, indicates the furthest preceeding page of items in the collection. - /// - /// - Range: `CollectionPage` | `Link` - /// - Functional: true - #[serde(skip_serializing_if = "Option::is_none")] - #[activitystreams(ab(Link, CollectionPage), concrete(String), functional)] - pub first: Option, + current { + docs [ + "In a paged `Collection`, indicates the page that contains the most recently updated member", + "items.", + "", + "- Range: `CollectionPage` | `Link`", + "- Functional: true", + ], + types [ + XsdAnyUri, + LinkBox, + CollectionPageBox, + ], + functional, + }, - /// In a paged `Collection`, indicates the furthest proceeding page of the collection. - /// - /// - Range: `CollectionPage` | `Link` - /// - Functional: true - #[serde(skip_serializing_if = "Option::is_none")] - #[activitystreams(ab(Link, CollectionPage), concrete(String), functional)] - pub last: Option, + first { + docs [ + "In a paged `Collection`, indicates the furthest preceeding page of items in the collection.", + "", + "- Range: `CollectionPage` | `Link`", + "- Functional: true", + ], + types [ + XsdAnyUri, + LinkBox, + CollectionPageBox, + ], + functional, + }, + + last { + docs [ + "In a paged `Collection`, indicates the furthest proceeding page of the collection.", + "", + "- Range: `CollectionPage` | `Link`", + "- Functional: true", + ], + types [ + XsdAnyUri, + LinkBox, + CollectionPageBox, + ], + }, + } } -/// The `CollectionPage` type extends from the base `Collection` type and inherits all of it's -/// properties. -#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)] -#[serde(rename_all = "camelCase")] -pub struct CollectionPageProperties { - /// Identifies the `Collection` to which a `CollectionPage` objects items belong. - /// - /// Range: `Collection` | `Link` - /// Functional: true - #[serde(skip_serializing_if = "Option::is_none")] - #[activitystreams(ab(Link, Collection), concrete(String), functional)] - pub part_of: Option, +properties! { + CollectionPage { + docs [ + "The `CollectionPage` type extends from the base `Collection` type and inherits all of it's", + "properties.", + ], - /// In a paged `Collection`, indicates the next page of items. - /// - /// - Range: `CollectionPage` | `Link` - /// - Functional: true - #[serde(skip_serializing_if = "Option::is_none")] - #[activitystreams(ab(Link, CollectionPage), concrete(String), functional)] - pub next: Option, + part_of { + docs [ + "Identifies the `Collection` to which a `CollectionPage` objects items belong.", + "", + "Range: `Collection` | `Link`", + "Functional: true", + ], + types [ + XsdAnyUri, + LinkBox, + CollectionBox, + ], + functional, + }, - /// In a paged `Collection`, identifies the previous page of items. - /// - /// - Range: `CollectionPage` | `Link` - /// - Functional: true - #[serde(skip_serializing_if = "Option::is_none")] - #[activitystreams(ab(Link, CollectionPage), concrete(String), functional)] - pub prev: Option, + next { + docs [ + "In a paged `Collection`, indicates the next page of items.", + "", + "- Range: `CollectionPage` | `Link`", + "- Functional: true", + ], + types [ + XsdAnyUri, + LinkBox, + CollectionPageBox, + ], + functional, + }, + + prev { + docs [ + "In a paged `Collection`, identifies the previous page of items.", + "", + "- Range: `CollectionPage` | `Link`", + "- Functional: true", + ], + types [ + XsdAnyUri, + LinkBox, + CollectionPageBox, + ], + functional, + }, + } } -/// The OrderedCollectionPage type MAY be used to identify a page whose items are strictly ordered. -#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)] -#[serde(rename_all = "camelCase")] -pub struct OrderedCollectionPageProperties { - /// A non-negative integer value identifying the relative position within the logical view of a - /// strictly ordered collection. - /// - /// - Range: `xsd:nonNegativeInteger` - /// - Functional: true - #[serde(skip_serializing_if = "Option::is_none")] - #[activitystreams(concrete(u64), functional)] - pub start_index: Option, +properties! { + OrderedCollectionPage { + docs ["The OrderedCollectionPage type MAY be used to identify a page whose items are strictly ordered." ], + start_index { + docs ["A non-negative integer value identifying the relative position within the logical view of a", + "strictly ordered collection.", + "", + "- Range: `xsd:nonNegativeInteger`", + "- Functional: true", + ], + types [ + XsdNonNegativeInteger, + ], + functional, + }, + } } diff --git a/activitystreams-types/src/custom_props.rs b/activitystreams-types/src/custom_props.rs deleted file mode 100644 index 10ab248..0000000 --- a/activitystreams-types/src/custom_props.rs +++ /dev/null @@ -1,151 +0,0 @@ -/* - * This file is part of ActivityStreams Types. - * - * Copyright © 2018 Riley Trautman - * - * ActivityStreams Types 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 Types 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 Types. If not, see . - */ - -//! A collection of simple types for extending the ActivityStreams Types base types - -use serde::{de::DeserializeOwned, ser}; - -use activitystreams_traits::{ - Activity, Actor, Collection, CollectionPage, IntransitiveActivity, Link, Object, -}; -use serde_derive::{Deserialize, Serialize}; - -/// A custom type extending Link -/// -/// CustomLink allows for providing a pre-defined Link type, and a set of extending properties, and -/// treating those two items as a single Link type. -/// -/// ## Example -/// ```rust -/// use activitystreams_types::{ -/// CustomLink, -/// link::Mention, -/// }; -/// -/// struct MyProps { -/// some_prop: String, -/// } -/// -/// fn main() { -/// let mention = Mention::default(); -/// let extended_mention = CustomLink::new(mention, MyProps { some_prop: "hey".to_owned() }); -/// } -/// ``` -#[derive(Clone, Debug, Deserialize, Serialize)] -#[serde(rename_all = "camelCase")] -pub struct CustomLink { - #[serde(flatten)] - pub link: L, - - #[serde(flatten)] - pub custom_props: C, -} - -impl CustomLink { - pub fn new(link: L, custom_props: C) -> Self { - CustomLink { link, custom_props } - } -} - -impl Link for CustomLink -where - C: DeserializeOwned + ser::Serialize, - L: Link, -{ -} - -/// A custom type extending Object -/// -/// CustomObject allows for providing a pre-defined Link type, and a set of extending properties, -/// and treating those two items as a single Object type. -/// -/// This type can also be used to extend any type deriving from Object, such as Actor, Activity, or -/// Collection. -/// -/// ## Example -/// ```rust -/// use activitystreams_types::{ -/// CustomObject, -/// object::Video, -/// }; -/// -/// struct MyProps { -/// some_prop: String, -/// } -/// -/// fn main() { -/// let video = Video::default(); -/// let extended_video = CustomObject::new(video, MyProps { some_prop: "hey".to_owned() }); -/// } -/// ``` -#[derive(Clone, Debug, Deserialize, Serialize)] -#[serde(rename_all = "camelCase")] -pub struct CustomObject { - #[serde(flatten)] - pub object: O, - - #[serde(flatten)] - pub custom_props: C, -} - -impl CustomObject { - pub fn new(object: O, custom_props: C) -> Self { - CustomObject { - object, - custom_props, - } - } -} - -impl Object for CustomObject -where - C: DeserializeOwned + ser::Serialize, - O: Object, -{ -} -impl Actor for CustomObject -where - C: DeserializeOwned + ser::Serialize, - O: Actor, -{ -} -impl Collection for CustomObject -where - C: DeserializeOwned + ser::Serialize, - O: Collection, -{ -} -impl CollectionPage for CustomObject -where - C: DeserializeOwned + ser::Serialize, - O: CollectionPage, -{ -} -impl Activity for CustomObject -where - C: DeserializeOwned + ser::Serialize, - O: Activity, -{ -} -impl IntransitiveActivity for CustomObject -where - C: DeserializeOwned + ser::Serialize, - O: IntransitiveActivity, -{ -} diff --git a/activitystreams-types/src/lib.rs b/activitystreams-types/src/lib.rs index c49e9b3..36411fb 100644 --- a/activitystreams-types/src/lib.rs +++ b/activitystreams-types/src/lib.rs @@ -28,7 +28,7 @@ //! fn run() -> Result<(), anyhow::Error> { //! /// A Mention is the only predefined Link type in the Activity Streams spec //! let mut mention = Mention::default(); -//! mention.link_props.set_context_object(context())?; +//! mention.link_props.set_context_xdg_any_uri(context())?; //! //! let mention_string = serde_json::to_string(&mention)?; //! @@ -42,25 +42,14 @@ //! # } //! ``` -use serde_derive::{Deserialize, Serialize}; - -/// Define a simple wrapper around a string for this crate's main Context type -#[derive(Clone, Debug, Deserialize, Serialize)] -pub struct ContextObject(pub String); - -impl activitystreams_traits::Object for ContextObject {} - /// The context associated with all of the Activity Streams types defined in the crate. -pub fn context() -> ContextObject { - ContextObject("https://www.w3.org/ns/activitystreams".to_owned()) +pub fn context() -> crate::primitives::XsdAnyUri { + "https://www.w3.org/ns/activitystreams".parse().unwrap() } pub mod activity; pub mod actor; pub mod collection; -mod custom_props; pub mod link; pub mod object; pub mod primitives; - -pub use self::custom_props::{CustomLink, CustomObject}; diff --git a/activitystreams-types/src/link/mod.rs b/activitystreams-types/src/link/mod.rs index 52b64f7..5e22ca6 100644 --- a/activitystreams-types/src/link/mod.rs +++ b/activitystreams-types/src/link/mod.rs @@ -19,8 +19,9 @@ //! Namespace for Link types +use activitystreams_derive::PropRefs; use activitystreams_traits::Link; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; pub mod kind; pub mod properties; @@ -35,8 +36,12 @@ pub trait LinkExt: Link { fn props_mut(&mut self) -> &mut LinkProperties; } +#[derive(Debug, Deserialize, Serialize)] +#[serde(transparent)] +pub struct LinkBox(pub Box); + /// A specialized Link that represents an @mention. -#[derive(Clone, Debug, Default, Deserialize, Serialize)] +#[derive(Clone, Debug, Default, Deserialize, PropRefs, Serialize)] #[serde(rename_all = "camelCase")] pub struct Mention { #[serde(rename = "type")] @@ -46,58 +51,42 @@ pub struct Mention { /// Adds all valid link properties to this struct #[serde(flatten)] + #[activitystreams(Link)] pub link_props: LinkProperties, } -impl Link for Mention {} -impl LinkExt for Mention { - fn props(&self) -> &LinkProperties { - &self.link_props - } - - fn props_mut(&mut self) -> &mut LinkProperties { - &mut self.link_props - } -} - -#[derive(Clone, Debug, Deserialize, Serialize)] -#[serde(transparent)] -pub struct LinkBox(pub Box); - impl LinkBox { pub fn is(&self) -> bool where - T: Link, + T: Link + 'static, { self.0.as_any().is::() } pub fn downcast_ref(&self) -> Option<&T> where - T: Link, + T: Link + 'static, { self.0.as_any().downcast_ref() } pub fn downcast_mut(&mut self) -> Option<&mut T> where - T: Link, + T: Link + 'static, { self.0.as_any_mut().downcast_mut() } +} - pub fn downcast(self) -> Option - where - T: Link, - { - let any: Box = self; - any.downcast() +impl Clone for LinkBox { + fn clone(&self) -> Self { + LinkBox(self.0.duplicate()) } } impl From for LinkBox where - T: Link, + T: Link + 'static, { fn from(t: T) -> Self { LinkBox(Box::new(t)) diff --git a/activitystreams-types/src/link/properties.rs b/activitystreams-types/src/link/properties.rs index 321c68e..1e6e557 100644 --- a/activitystreams-types/src/link/properties.rs +++ b/activitystreams-types/src/link/properties.rs @@ -24,7 +24,7 @@ //! ```rust //! use activitystreams_traits::Link; //! use activitystreams_types::link::properties::LinkProperties; -//! use serde_derive::{Deserialize, Serialize}; +//! use serde::{Deserialize, Serialize}; //! //! #[derive(Clone, Debug, Serialize, Deserialize)] //! #[serde(rename_all = "camelCase")] @@ -44,145 +44,185 @@ //! # fn main() {} //! ``` -use activitystreams_derive::Properties; -use activitystreams_traits::{Error, Link, Object, Result}; -use serde_derive::{Deserialize, Serialize}; +use activitystreams_derive::properties; -/// Define all the properties of the Object base type as described by the Activity Streams -/// vocabulary. -/// -/// The properties of the `Link` object are not the properties of the referenced resource, but are -/// provided as hints for rendering agents to understand how to make use of the resource. For -/// example, height and width might represent the desired rendered size of a referenced image, -/// rather than the actual pixel dimensions of the referenced image. -/// -/// The target URI of the Link is expressed using the required href property. -/// -/// For example, all Objects can contain an image property whose value describes a graphical -/// representation of the containing object. This property will typically be used to provide the URL -/// to an image (e.g. JPEG, GIF or PNG) resource that can be displayed to the user. Any given object -/// might have multiple such visual representations -- multiple screenshots, for instance, or the -/// same image at different resolutions. In Activity Streams 2.0, there are essentially three ways -/// of describing such references. -#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)] -#[serde(rename_all = "camelCase")] -pub struct LinkProperties { - // TODO: IRI type - /// Provides the globally unique identifier for an Object or Link. - /// - /// The `id` property is expressed as an absolute IRI in the spec, but for now is represented - /// as a string. - /// - /// - Range: `anyUri` - /// - Functional: true - #[serde(skip_serializing_if = "Option::is_none")] - #[activitystreams(concrete(String), functional)] - pub id: Option, +use crate::{link::LinkBox, object::ObjectBox, primitives::*}; - /// Identifies the context within which the object exists or an activity was performed. - /// - /// The notion of "context" used is intentionally vague. The intended function is to serve as a - /// means of grouping objects and activities that share a common originating context or purpose. - /// An example could be all activities relating to a common project or event. - /// - /// - Range: `Object` | `Link` - /// - Functional: false - #[serde(skip_serializing_if = "Option::is_none", rename = "@context")] - #[activitystreams(ab(Object, Link), concrete(String))] - pub context: Option, +properties! { + Link { + docs [ + "Define all the properties of the Object base type as described by the Activity Streams vocabulary.", + "", + "The properties of the `Link` object are not the properties of the referenced resource, but are", + "provided as hints for rendering agents to understand how to make use of the resource. For", + "example, height and width might represent the desired rendered size of a referenced image,", + "rather than the actual pixel dimensions of the referenced image.", + "", + "The target URI of the Link is expressed using the required href property.", + "", + "For example, all Objects can contain an image property whose value describes a graphical", + "representation of the containing object. This property will typically be used to provide the URL", + "to an image (e.g. JPEG, GIF or PNG) resource that can be displayed to the user. Any given object", + "might have multiple such visual representations -- multiple screenshots, for instance, or the", + "same image at different resolutions. In Activity Streams 2.0, there are essentially three ways", + "of describing such references.", + ], + id { + docs [ + "Provides the globally unique identifier for an Object or Link.", + "", + "The `id` property is expressed as an absolute IRI in the spec, but for now is represented", + "as a string.", + "", + "- Range: `anyUri`", + "- Functional: true", + ], + types [ + XsdAnyUri, + ], + functional, + }, - // TODO: rdf:langString - /// A simple, human-readable, plain-text name for the object. - /// - /// HTML markup MUST NOT be included. The name MAY be expressed using multiple language-tagged - /// values. - /// - /// - Range: `xsd:string` | `rdf:langString` - /// - Functional: false - #[serde(skip_serializing_if = "Option::is_none")] - #[activitystreams(concrete(String))] - pub name: Option, + context { + docs [ + "Identifies the context within which the object exists or an activity was performed.", + "", + "The notion of \"context\" used is intentionally vague. The intended function is to serve as a", + "means of grouping objects and activities that share a common originating context or purpose.", + "An example could be all activities relating to a common project or event.", + "", + "- Range: `Object` | `Link`", + "- Functional: false", + ], + types [ + XsdAnyUri, + ObjectBox, + LinkBox, + ], + rename("@context"), + }, - /// The target resource pointed to by a Link. - /// - /// - Range: `xsd:anyUri` - /// - Functional: true - #[serde(skip_serializing_if = "Option::is_none")] - #[activitystreams(concrete(String), functional)] - pub href: Option, + name { + docs [ + "A simple, human-readable, plain-text name for the object.", + "", + "HTML markup MUST NOT be included. The name MAY be expressed using multiple language-tagged", + "values.", + "", + "- Range: `xsd:string` | `rdf:langString`", + "- Functional: false", + ], + types [ + XsdString, + RdfLangString, + ], + }, - // TODO: lang enum - /// Hints as to the language used by the target resource. - /// - /// Value MUST be a [[BCP47](https://tools.ietf.org/html/bcp47)] - /// Language-Tag. - /// - /// - Range: [[BCP47](https://tools.ietf.org/html/bcp47)] Language - /// Tag - /// - Functional: true - #[serde(skip_serializing_if = "Option::is_none")] - #[activitystreams(concrete(String), functional)] - pub hreflang: Option, + href { + docs [ + "The target resource pointed to by a Link.", + "", + "- Range: `xsd:anyUri`", + "- Functional: true", + ], + types [ + XsdAnyUri, + ], + functional, + }, - /// When used on a `Link`, identifies the MIME media type of the referenced resource. - /// - /// If not specified, the content property is assumed to contain text/html content. - /// - /// - Range: `Mime Media Type` - /// - Functional: true - #[serde(skip_serializing_if = "Option::is_none")] - #[activitystreams(concrete(String), functional)] - pub media_type: Option, + hreflang { + docs [ + "Hints as to the language used by the target resource.", + "", + "Value MUST be a [[BCP47](https://tools.ietf.org/html/bcp47)]", + "Language-Tag.", + "", + "- Range: [[BCP47](https://tools.ietf.org/html/bcp47)] Language", + "Tag", + "- Functional: true", + ], + types [ + XsdString, + ], + functional, + }, - /// A link relation associated with a Link. - /// - /// The value MUST conform to both the - /// [[HTML5](https://www.w3.org/TR/html5/)] and [[RFC5988](https://tools.ietf.org/html/rfc5988)] - /// "link relation" definitions. - /// - /// In the [[HTML5](https://www.w3.org/TR/html5/)], any string - /// not containing the "space" U+0020, "tab" (U+0009), "LF" (U+000A), "FF" (U+000C), "CR" - /// (U+000D) or "," (U+002C) characters can be used as a valid link relation. - /// - /// - Range: - /// [[RFC5988](https://tools.ietf.org/html/rfc5988)] or - /// [[HTML5](https://www.w3.org/TR/html5/)] Link Relation - /// - Functional: false - #[serde(skip_serializing_if = "Option::is_none")] - #[activitystreams(concrete(String))] - pub rel: Option, + media_type { + docs [ + "When used on a `Link`, identifies the MIME media type of the referenced resource.", + "", + "If not specified, the content property is assumed to contain text/html content.", + "", + "- Range: `Mime Media Type`", + "- Functional: true", + ], + types [ + MimeMediaType, + ], + functional, + }, - /// On a `Link`, specifies a hint as to the rendering height in device-independent pixels of the - /// linked resource. - /// - /// - Range: `xsd:nonNegativeInteger` - /// - Functional: true - #[serde(skip_serializing_if = "Option::is_none")] - #[activitystreams(concrete(u64), functional)] - pub height: Option, + rel { + docs [ + "A link relation associated with a Link.", + "", + "The value MUST conform to both the", + "[[HTML5](https://www.w3.org/TR/html5/)] and [[RFC5988](https://tools.ietf.org/html/rfc5988)]", + "\"link relation\" definitions.", + "", + "In the [[HTML5](https://www.w3.org/TR/html5/)], any string", + "not containing the \"space\" U+0020, \"tab\" (U+0009), \"LF\" (U+000A), \"FF\" (U+000C), \"CR\"", + "(U+000D) or \",\" (U+002C) characters can be used as a valid link relation.", + "", + "- Range:", + " [[RFC5988](https://tools.ietf.org/html/rfc5988)] or", + " [[HTML5](https://www.w3.org/TR/html5/)] Link Relation", + "- Functional: false", + ], + types [ + XsdString, + ], + }, - /// On a `Link`, specifies a hint as to the rendering width in device-independent pixels of the - /// linked resource. - /// - /// - Range: `xsd:nonNegativeInteger` - /// - Functional: true - #[serde(skip_serializing_if = "Option::is_none")] - #[activitystreams(concrete(u64), functional)] - pub width: Option, + height { + docs ["On a `Link`, specifies a hint as to the rendering height in device-independent pixels of the", + "linked resource.", + "", + "- Range: `xsd:nonNegativeInteger`", + "- Functional: true", + ], + types [ + XsdNonNegativeInteger, + ], + functional, + }, - /// Identifies an entity that provides a preview of this object. - /// - /// - Range: `Object` | `Link` - /// - Functional: false - #[serde(skip_serializing_if = "Option::is_none")] - #[activitystreams(ab(Object, Link), concrete(String))] - pub preview: Option, -} + width { + docs [ + "On a `Link`, specifies a hint as to the rendering width in device-independent pixels of the", + "linked resource.", + "", + "- Range: `xsd:nonNegativeInteger`", + "- Functional: true", + ], + types [ + XsdNonNegativeInteger, + ], + }, -impl LinkProperties { - /// Fetch a typed `Mime` struct from the `media_type` field. - pub fn media_type(&self) -> Result { - self.media_type_string() - .and_then(|s| s.parse().map_err(|_| Error::Deserialize)) + preview { + docs [ + "Identifies an entity that provides a preview of this object.", + "", + "- Range: `Object` | `Link`", + "- Functional: false", + ], + types [ + XsdAnyUri, + ObjectBox, + LinkBox, + ], + }, } } diff --git a/activitystreams-types/src/object/mod.rs b/activitystreams-types/src/object/mod.rs index 126823c..68b07fa 100644 --- a/activitystreams-types/src/object/mod.rs +++ b/activitystreams-types/src/object/mod.rs @@ -19,9 +19,9 @@ //! Namespace for Object types -use activitystreams_derive::{PropRefs, Properties}; +use activitystreams_derive::PropRefs; use activitystreams_traits::Object; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; pub mod kind; pub mod properties; @@ -36,6 +36,14 @@ pub trait ObjectExt: Object { fn props_mut(&mut self) -> &mut ObjectProperties; } +#[derive(Clone, Debug, Deserialize, Serialize)] +#[serde(transparent)] +pub struct ImageBox(pub Box); + +#[derive(Debug, Deserialize, Serialize)] +#[serde(transparent)] +pub struct ObjectBox(pub Box); + /// Represents any kind of multi-paragraph written work. #[derive(Clone, Debug, Default, Deserialize, PropRefs, Serialize)] #[serde(rename_all = "camelCase")] @@ -272,43 +280,27 @@ pub struct Video { pub object_props: ObjectProperties, } -#[derive(Clone, Debug, Deserialize, Serialize)] -#[serde(transparent)] -pub struct ImageBox(pub Box); - -#[derive(Clone, Debug, Deserialize, Serialize)] -#[serde(transparent)] -pub struct ObjectBox(pub Box); - impl ObjectBox { pub fn is(&self) -> bool where - T: Object, + T: Object + 'static, { self.0.as_any().is::() } pub fn downcast_ref(&self) -> Option<&T> where - T: Object, + T: Object + 'static, { self.0.as_any().downcast_ref() } pub fn downcast_mut(&mut self) -> Option<&mut T> where - T: Object, + T: Object + 'static, { self.0.as_any_mut().downcast_mut() } - - pub fn downcast(self) -> Option - where - T: Object, - { - let any: Box = self; - any.downcast() - } } impl From for ImageBox { @@ -323,9 +315,15 @@ impl From for Image { } } +impl Clone for ObjectBox { + fn clone(&self) -> Self { + ObjectBox(self.0.duplicate()) + } +} + impl From for ObjectBox where - T: Object, + T: Object + 'static, { fn from(t: T) -> Self { ObjectBox(Box::new(t)) diff --git a/activitystreams-types/src/object/properties.rs b/activitystreams-types/src/object/properties.rs index 95a0186..9154bd6 100644 --- a/activitystreams-types/src/object/properties.rs +++ b/activitystreams-types/src/object/properties.rs @@ -24,7 +24,7 @@ //! ```rust //! use activitystreams_traits::Object; //! use activitystreams_types::object::properties::ObjectProperties; -//! use serde_derive::{Deserialize, Serialize}; +//! use serde::{Deserialize, Serialize}; //! use std::any::Any; //! //! #[derive(Clone, Debug, Serialize, Deserialize)] @@ -54,53 +54,56 @@ //! ``` use activitystreams_derive::properties; -use activitystreams_traits::{Collection, Error, Link, Object, Result}; -use chrono::{offset::Utc, DateTime}; -use serde_derive::{Deserialize, Serialize}; use crate::{ link::LinkBox, - object::{Image, ObjectBox}, + object::{ImageBox, ObjectBox}, primitives::*, }; - -/// Define all the properties of the Object base type as described by the Activity Streams -/// vocabulary. -/// -/// In addition to having a global identifier (expressed as an absolute IRI using the id property) -/// and an "object type" (expressed using the type property), all instances of the Object type share -/// a common set of properties normatively defined by the Activity Vocabulary. -/// -/// This struct does not provide an optional `type` property, if you are implementing your own -/// object type, you must supply your own type. This crate's provided object types all supply their -/// own `type` properties as Unit Structs with custom serde behaviour. -/// -/// All properties are optional (including the id and type). properties! { Object { + docs [ + "Define all the properties of the Object base type as described by the Activity Streams", + "vocabulary.", + "", + "In addition to having a global identifier (expressed as an absolute IRI using the id property)", + "and an \"object type\"(expressed using the type property), all instances of the Object type share", + "a common set of properties normatively defined by the Activity Vocabulary.", + "", + "This struct does not provide an optional `type` property, if you are implementing your own", + "object type, you must supply your own type. This crate's provided object types all supply their", + "own `type` properties as Unit Structs with custom serde behaviour.", + "", + "All properties are optional (including the id and type).", + ], id { - /// Provides the globally unique identifier for an Object or Link. - /// - /// The `id` property is expressed as an absolute IRI in the spec, but for now is represented - /// as a string. - /// - /// - Range: `xsd:anyUri` - /// - Functional: true + docs [ + "Provides the globally unique identifier for an Object or Link.", + "", + "The `id` property is expressed as an absolute IRI in the spec, but for now is represented", + "as a string.", + "", + "- Range: `xsd:anyUri`", + "- Functional: true", + ], types [ XsdAnyUri, ], functional, + alias [ "@id" ], }, attachment { - /// Identifies a resource attached or related to an object that potentially requires special - /// handling. - /// - /// The intent is to provide a model that is at least semantically similar to attachments in - /// email. - /// - /// - Range: `Object` | `Link` - /// - Functional: false + docs [ + "Identifies a resource attached or related to an object that potentially requires special", + "handling.", + "", + "The intent is to provide a model that is at least semantically similar to attachments in", + "email.", + "", + "- Range: `Object` | `Link`", + "- Functional: false", + ], types [ XsdAnyUri, ObjectBox, @@ -109,13 +112,15 @@ properties! { }, attributed_to { - /// Identifies one or more entities to which this object is attributed. - /// - /// The attributed entities might not be Actors. For instance, an object might be attributed to - /// the completion of another activity. - /// - /// - Range: `Object` | `Link` - /// - Functional: false + docs [ + "Identifies one or more entities to which this object is attributed.", + "", + "The attributed entities might not be Actors. For instance, an object might be attributed to", + "the completion of another activity.", + "", + "- Range: `Object` | `Link`", + "- Functional: false", + ], types [ XsdAnyUri, ObjectBox, @@ -124,11 +129,13 @@ properties! { }, audience { - /// Identifies one or more entities that represent the total population of entities for which - /// the object can considered to be relevant. - /// - /// - Range: `Object` | `Link` - /// - Functional: false + docs [ + "Identifies one or more entities that represent the total population of entities for which", + "the object can considered to be relevant.", + "", + "- Range: `Object` | `Link`", + "- Functional: false", + ], types [ XsdAnyUri, ObjectBox, @@ -137,15 +144,17 @@ properties! { }, content { - /// The content or textual representation of the Object encoded as a JSON string. - /// - /// By default, the value of content is HTML. The mediaType property can be used in the object - /// to indicate a different content type. - /// - /// The content MAY be expressed using multiple language-tagged values. - /// - /// - Range: `xsd:string` | `rdf:langString` - /// - Functional: false + docs [ + "The content or textual representation of the Object encoded as a JSON string.", + "", + "By default, the value of content is HTML. The mediaType property can be used in the object", + "to indicate a different content type.", + "", + "The content MAY be expressed using multiple language-tagged values.", + "", + "- Range: `xsd:string` | `rdf:langString`", + "- Functional: false", + ], types [ XsdString, RdfLangString, @@ -153,14 +162,16 @@ properties! { }, context { - /// Identifies the context within which the object exists or an activity was performed. - /// - /// The notion of "context" used is intentionally vague. The intended function is to serve as a - /// means of grouping objects and activities that share a common originating context or purpose. - /// An example could be all activities relating to a common project or event. - /// - /// - Range: `Object` | `Link` - /// - Functional: false + docs [ + "Identifies the context within which the object exists or an activity was performed.", + "", + "The notion of \"context\"used is intentionally vague. The intended function is to serve as a", + "means of grouping objects and activities that share a common originating context or purpose.", + "An example could be all activities relating to a common project or event.", + "", + "- Range: `Object` | `Link`", + "- Functional: false", + ], types [ XsdAnyUri, ObjectBox, @@ -169,28 +180,32 @@ properties! { }, name { - /// A simple, human-readable, plain-text name for the object. - /// - /// HTML markup MUST NOT be included. The name MAY be expressed using multiple language-tagged - /// values. - /// - /// - Range: `xsd:string` | `rdf:langString` - /// - Functional: false + docs [ + "A simple, human-readable, plain-text name for the object.", + "", + "HTML markup MUST NOT be included. The name MAY be expressed using multiple language-tagged", + "values.", + "", + "- Range: `xsd:string` | `rdf:langString`", + "- Functional: false", + ], types [ XsdString, RdfLangString, ], - alias("displayName"), + alias [ "displayName" ], }, end_time { - /// The date and time describing the actual or expected ending time of the object. - /// - /// When used with an Activity object, for instance, the endTime property specifies the moment - /// the activity concluded or is expected to conclude. - /// - /// - Range: `xsd:dateTime` - /// - Functional: true + docs [ + "The date and time describing the actual or expected ending time of the object.", + "", + "When used with an Activity object, for instance, the endTime property specifies the moment", + "the activity concluded or is expected to conclude.", + "", + "- Range: `xsd:dateTime`", + "- Functional: true", + ], types [ XsdDateTime, ], @@ -198,10 +213,12 @@ properties! { }, generator { - /// Identifies the entity (e.g. an application) that generated the object. - /// - /// - Range: `Object` | `Link` - /// - Functional: false + docs [ + "Identifies the entity (e.g. an application) that generated the object.", + "", + "- Range: `Object` | `Link`", + "- Functional: false", + ], types [ XsdAnyUri, ObjectBox, @@ -210,13 +227,15 @@ properties! { }, icon { - /// Indicates an entity that describes an icon for this object. - /// - /// The image should have an aspect ratio of one (horizontal) to one (vertical) and should be - /// suitable for presentation at a small size. - /// - /// - Range: `Image` | `Link` - /// - Functional: false + docs [ + "Indicates an entity that describes an icon for this object.", + "", + "The image should have an aspect ratio of one (horizontal) to one (vertical) and should be", + "suitable for presentation at a small size.", + "", + "- Range: `Image` | `Link`", + "- Functional: false", + ], types [ XsdAnyUri, ImageBox, @@ -225,12 +244,14 @@ properties! { }, image { - /// Indicates an entity that describes an image for this object. - /// - /// Unlike the icon property, there are no aspect ratio or display size limitations assumed. - /// - /// - Range: `Image` | `Link` - /// - Functional: false + docs [ + "Indicates an entity that describes an image for this object.", + "", + "Unlike the icon property, there are no aspect ratio or display size limitations assumed.", + "", + "- Range: `Image` | `Link`", + "- Functional: false", + ], types [ XsdAnyUri, ImageBox, @@ -239,10 +260,12 @@ properties! { }, in_reply_to { - /// Indicates one or more entities for which this object is considered a response. - /// - /// - Range: `Object` | `Link` - /// - Functional: false + docs [ + "Indicates one or more entities for which this object is considered a response.", + "", + "- Range: `Object` | `Link`", + "- Functional: false", + ], types [ XsdAnyUri, ObjectBox, @@ -251,10 +274,12 @@ properties! { }, location { - /// Indicates one or more physical or logical locations associated with the object. - /// - /// - Range: `Object` | `Link` - /// - Functional: false + docs [ + "Indicates one or more physical or logical locations associated with the object.", + "", + "- Range: `Object` | `Link`", + "- Functional: false", + ], types [ XsdAnyUri, ObjectBox, @@ -263,10 +288,12 @@ properties! { }, preview { - /// Identifies an entity that provides a preview of this object. - /// - /// - Range: `Object` | `Link` - /// - Functional: false + docs [ + "Identifies an entity that provides a preview of this object.", + "", + "- Range: `Object` | `Link`", + "- Functional: false", + ], types [ XsdAnyUri, ObjectBox, @@ -275,10 +302,12 @@ properties! { }, published { - /// The date and time at which the object was published. - /// - /// - Range: `xsd:dateTime` - /// - Functional: true + docs [ + "The date and time at which the object was published.", + "", + "- Range: `xsd:dateTime`", + "- Functional: true", + ], types [ XsdDateTime, ], @@ -286,10 +315,12 @@ properties! { }, replies { - /// Identifies a `Collection` containing objects considered to be responses to this object. - /// - /// - Range: `Object` | `Link` - /// - Functional: false + docs [ + "Identifies a `Collection` containing objects considered to be responses to this object.", + "", + "- Range: `Object` | `Link`", + "- Functional: false", + ], types [ XsdAnyUri, ObjectBox, @@ -298,13 +329,15 @@ properties! { }, start_time { - /// The date and time describing the actual or expected starting time of the object. - /// - /// When used with an `Activity` object, for instance, the `start_time` property specifies the - /// moment the activity began or is scheduled to begin. - /// - /// - Range: `xsd:DateTime` - /// - Functional: true + docs [ + "The date and time describing the actual or expected starting time of the object.", + "", + "When used with an `Activity` object, for instance, the `start_time` property specifies the", + "moment the activity began or is scheduled to begin.", + "", + "- Range: `xsd:DateTime`", + "- Functional: true", + ], types [ XsdDateTime, ], @@ -312,12 +345,14 @@ properties! { }, summary { - /// A natural language summarization of the object encoded as HTML. - /// - /// Multiple language tagged summaries MAY be provided. - /// - /// - Range: `xsd:string` | `rdf:langString` - /// - Functional: false + docs [ + "A natural language summarization of the object encoded as HTML.", + "", + "Multiple language tagged summaries MAY be provided.", + "", + "- Range: `xsd:string` | `rdf:langString`", + "- Functional: false", + ], types [ XsdString, RdfLangString, @@ -325,14 +360,16 @@ properties! { }, tag { - /// One or more "tags" that have been associated with an objects. A tag can be any kind of - /// `Object`. - /// - /// The key difference between attachment and tag is that the former implies association by - /// inclusion, while the latter implies associated by reference. - /// - /// - Range: `Object` | `Link` - /// - Functional: false + docs [ + "One or more \"tags\" that have been associated with an objects. A tag can be any kind of", + "`Object`.", + "", + "The key difference between attachment and tag is that the former implies association by", + "inclusion, while the latter implies associated by reference.", + "", + "- Range: `Object` | `Link`", + "- Functional: false", + ], types [ XsdAnyUri, ObjectBox, @@ -341,10 +378,12 @@ properties! { }, updated { - /// The date and time at which the object was updated, - /// - /// - Range: `xsd:dateTime` - /// - Functional: true + docs [ + "The date and time at which the object was updated,", + "", + "- Range: `xsd:dateTime`", + "- Functional: true", + ], types [ XsdDateTime, ], @@ -352,10 +391,12 @@ properties! { }, url { - /// Identifies one or more links to representations of the object. - /// - /// - Range: `xsd:anyUri` | `Link` - /// - Functional: false + docs [ + "Identifies one or more links to representations of the object.", + "", + "- Range: `xsd:anyUri` | `Link`", + "- Functional: false", + ], types [ XsdAnyUri, LinkBox, @@ -363,10 +404,12 @@ properties! { }, to { - /// Identifies an entity considered to be part of the public primary audience of an `Object`. - /// - /// - Range: `Object` | `Link` - /// - Functional: false + docs [ + "Identifies an entity considered to be part of the public primary audience of an `Object`.", + "", + "- Range: `Object` | `Link`", + "- Functional: false", + ], types [ XsdAnyUri, ObjectBox, @@ -375,10 +418,12 @@ properties! { }, bto { - /// Identifies an `Object` that is part of the private primary audience of this `Object`. - /// - /// - Range: `Object` | `Link` - /// - Functional: false + docs [ + "Identifies an `Object` that is part of the private primary audience of this `Object`.", + "", + "- Range: `Object` | `Link`", + "- Functional: false", + ], types [ XsdAnyUri, ObjectBox, @@ -387,10 +432,12 @@ properties! { }, cc { - /// Identifies an `Object` that is part of the public secondary audience of this `Object`. - /// - /// - Range: `Object` | `Link` - /// - Functional: false + docs [ + "Identifies an `Object` that is part of the public secondary audience of this `Object`.", + "", + "- Range: `Object` | `Link`", + "- Functional: false", + ], types [ XsdAnyUri, ObjectBox, @@ -399,11 +446,13 @@ properties! { }, bcc { - /// Identifies one or more `Objects` that are part of the private secondary audience of this - /// `Object`. - /// - /// - Range: `Object` | `Link` - /// - Functional: false + docs [ + "Identifies one or more `Objects` that are part of the private secondary audience of this", + "`Object`.", + "", + "- Range: `Object` | `Link`", + "- Functional: false", + ], types [ XsdAnyUri, ObjectBox, @@ -412,13 +461,15 @@ properties! { }, media_type { - /// When used on an `Object`, identifies the MIME media type of the value of the content - /// property. - /// - /// If not specified, the content property is assumed to contain text/html content. - /// - /// - Range: `Mime Media Type` - /// - Functional: true + docs [ + "When used on an `Object`, identifies the MIME media type of the value of the content", + "property.", + "", + "If not specified, the content property is assumed to contain text/html content.", + "", + "- Range: `Mime Media Type`", + "- Functional: true", + ], types [ MimeMediaType, ], @@ -426,15 +477,17 @@ properties! { }, duration { - /// When the object describes a time-bound resource, such as an audio or video, a meeting, etc, - /// the duration property indicates the object's approximate duration. - /// - /// The value MUST be expressed as an xsd:duration as defined by - /// [[xmlschema11-2](https://www.w3.org/TR/xmlschema11-2/)], section - /// 3.3.6 (e.g. a period of 5 seconds is represented as "PT5S"). - /// - /// - Range: `xsd:duration` - /// - Functional: true + docs [ + "When the object describes a time-bound resource, such as an audio or video, a meeting, etc,", + "the duration property indicates the object's approximate duration.", + "", + "The value MUST be expressed as an xsd:duration as defined by", + "[[xmlschema11-2](https://www.w3.org/TR/xmlschema11-2/)], section", + "3.3.6 (e.g. a period of 5 seconds is represented as \"PT5S\").", + "", + "- Range: `xsd:duration`", + "- Functional: true", + ], types [ XsdDuration, ], @@ -443,16 +496,18 @@ properties! { } } -/// Define all the properties of the Location type as described by the Activity Streams vocabulary. properties! { Place { + docs [ "Define all the properties of the Location type as described by the Activity Streams vocabulary." ], accuracy { - /// Indicates the accuracy of position coordinates on a `Place` objects. - /// - /// Expressed in properties of percentage. e.g. "94.0" means "94.0% accurate". - /// - /// - Range: `xsd:float` [>= 0.0f, <= 100.0f] - /// - Functional: true + docs [ + "Indicates the accuracy of position coordinates on a `Place` objects.", + "", + "Expressed in properties of percentage. e.g. \"94.0\"means \"94.0% accurate\".", + "", + "- Range: `xsd:float` [>= 0.0f, <= 100.0f]", + "- Functional: true", + ], types [ XsdFloat, ], @@ -460,13 +515,15 @@ properties! { }, altitude { - /// Indicates the altitude of a place. The measurement units is indicated using the units - /// property. - /// - /// If units is not specified, the default is assumed to be "m" indicating meters. - /// - /// - Range: `xsd:float` - /// - Functional: true + docs [ + "Indicates the altitude of a place. The measurement units is indicated using the units", + "property.", + "", + "If units is not specified, the default is assumed to be \"m\" indicating meters.", + "", + "- Range: `xsd:float`", + "- Functional: true", + ], types [ XsdFloat, ], @@ -474,21 +531,25 @@ properties! { }, latitude { - /// The latitude of a place. - /// - /// - Range: `xsd:float` - /// - Functional: true + docs [ + "The latitude of a place.", + "", + "- Range: `xsd:float`", + "- Functional: true", + ], types [ XsdFloat, ], functional, - } + }, - logitude { - /// The longitude of a place. - /// - /// - Range: `xsd:float` - /// - Functional: true + longitude { + docs [ + "The longitude of a place.", + "", + "- Range: `xsd:float`", + "- Functional: true", + ], types [ XsdFloat, ], @@ -496,13 +557,15 @@ properties! { }, radius { - /// The radius from the given latitude and longitude for a Place. - /// - /// The units is expressed by the units property. If units is not specified, the default is - /// assumed to be "m" indicating "meters". - /// - /// - Range: `xsd:float` - /// - Functional: true + docs [ + "The radius from the given latitude and longitude for a Place.", + "", + "The units is expressed by the units property. If units is not specified, the default is", + "assumed to be \"m\" indicating meters.", + "", + "- Range: `xsd:float`", + "- Functional: true", + ], types [ XsdFloat, ], @@ -510,13 +573,15 @@ properties! { }, units { - /// Specifies the measurement units for the radius and altitude properties on a `Place` object. - /// - /// If not specified, the default is assumed to be "m" for "meters". - /// - /// TODO: encode rage as any of `"cm"` | `"feet"` | `"inches"` | `"km"` | `"m"` | `xsd:anyUri` - /// - Range: `xsd:anyUri` | `xsd:string` - /// - Functional: true + docs [ + "Specifies the measurement units for the radius and altitude properties on a `Place` object.", + "", + "If not specified, the default is assumed to be \"m\" for meters.", + "", + "TODO: encode rage as any of `\"cm\"` | `\"feet\"` | `\"inches\"` | `\"km\"` | `\"m\"` | `xsd:anyUri`", + "- Range: `xsd:anyUri` | `xsd:string`", + "- Functional: true", + ], types [ XsdAnyUri, XsdString, @@ -526,15 +591,17 @@ properties! { } } -/// Define all the properties of the Profile type as described by the Activity Streams vocabulary. properties! { Profile { + docs [ "Define all the properties of the Profile type as described by the Activity Streams vocabulary." ], describes { - /// On a `Profile` object, the describes property identifies the object described by the - /// `Profile`. - /// - /// - Range: `Object` - /// - Functional: true + docs [ + "On a `Profile` object, the describes property identifies the object described by the", + "`Profile`.", + "", + "- Range: `Object`", + "- Functional: true", + ], types [ XsdAnyUri, ObjectBox, @@ -544,19 +611,23 @@ properties! { } } -/// Define all the properties of the Relationship type as described by the Activity Streams -/// vocabulary. properties! { Relationship { + docs [ + "Define all the properties of the Relationship type as described by the Activity Streams", + "vocabulary.", + ], subject { - /// On a `Relationship` object, the subject property identifies one of the connected - /// individuals. - /// - /// For instance, for a `Relationship` object describing "John is related to Sally", subject - /// would refer to John. - /// - /// - Range: `Object` | `Link` - /// - Functional: true + docs [ + "On a `Relationship` object, the subject property identifies one of the connected", + "individuals.", + "", + "For instance, for a `Relationship` object describing \"John is related to Sally\", subject", + "would refer to John.", + "", + "- Range: `Object` | `Link`", + "- Functional: true", + ], types [ XsdAnyUri, ObjectBox, @@ -566,10 +637,12 @@ properties! { }, object { - /// When used within a `Relationship` describes the entity to which the subject is related. - /// - /// - Range: `Object` | `Link` - /// - Functional: false + docs [ + "When used within a `Relationship` describes the entity to which the subject is related.", + "", + "- Range: `Object` | `Link`", + "- Functional: false", + ], types [ XsdAnyUri, ObjectBox, @@ -578,11 +651,13 @@ properties! { }, relationship { - /// On a `Relationship` object, the relationship property identifies the kind of relationship - /// that exists between subject and object. - /// - /// - Range: `Object` - /// - Functional: false + docs [ + "On a `Relationship` object, the relationship property identifies the kind of relationship", + "that exists between subject and object.", + "", + "- Range: `Object`", + "- Functional: false", + ], types [ XsdAnyUri, ObjectBox, @@ -591,15 +666,17 @@ properties! { } } -/// Define all the properties of the Tombstone type as described by the Activity Streams vocabulary. properties! { Tombstone { + docs [ "Define all the properties of the Tombstone type as described by the Activity Streams vocabulary." ], former_type { - /// On a `Tombstone` object, the formerType property identifies the type of the object that was - /// deleted. - /// - /// - Range: `Object` - /// - Functional: false + docs [ + "On a `Tombstone` object, the formerType property identifies the type of the object that was", + "deleted.", + "", + "- Range: `Object`", + "- Functional: false", + ], types [ XsdAnyUri, ObjectBox, @@ -607,11 +684,13 @@ properties! { }, deleted { - /// On a `Tombstone` object, the deleted property is a timestamp for when the object was - /// deleted. - /// - /// - Range: `xsd:dateTime` - /// - Functional: true + docs [ + "On a `Tombstone` object, the deleted property is a timestamp for when the object was", + "deleted.", + "", + "- Range: `xsd:dateTime`", + "- Functional: true", + ], types [ XsdDateTime, ], diff --git a/activitystreams-types/src/primitives/mod.rs b/activitystreams-types/src/primitives/mod.rs index 91b7a9a..996e913 100644 --- a/activitystreams-types/src/primitives/mod.rs +++ b/activitystreams-types/src/primitives/mod.rs @@ -10,8 +10,8 @@ mod xsd_string; pub use self::{ mime_media_type::{MimeMediaType, MimeMediaTypeError}, - rdf_lang_string::RDFLangString, - xsd_any_uri::{XsdAnyURI, XsdAnyURIError}, + rdf_lang_string::RdfLangString, + xsd_any_uri::{XsdAnyUri, XsdAnyUriError}, xsd_datetime::{XsdDateTime, XsdDateTimeError}, xsd_duration::{XsdDuration, XsdDurationError}, xsd_float::{XsdFloat, XsdFloatError}, diff --git a/activitystreams-types/src/primitives/rdf_lang_string.rs b/activitystreams-types/src/primitives/rdf_lang_string.rs index 95f02b3..5771697 100644 --- a/activitystreams-types/src/primitives/rdf_lang_string.rs +++ b/activitystreams-types/src/primitives/rdf_lang_string.rs @@ -1,5 +1,5 @@ -#[derive(Clone, Debug, serde_derive::Deserialize, serde_derive::Serialize)] -pub struct RDFLangString { +#[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize)] +pub struct RdfLangString { #[serde(rename = "@value")] pub value: String, @@ -7,7 +7,7 @@ pub struct RDFLangString { pub language: String, } -impl std::fmt::Display for RDFLangString { +impl std::fmt::Display for RdfLangString { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{}:{}", self.language, self.value) } diff --git a/activitystreams-types/src/primitives/xsd_any_uri.rs b/activitystreams-types/src/primitives/xsd_any_uri.rs index 66e1c5e..7752044 100644 --- a/activitystreams-types/src/primitives/xsd_any_uri.rs +++ b/activitystreams-types/src/primitives/xsd_any_uri.rs @@ -1,44 +1,44 @@ -#[derive(Clone, Debug, serde_derive::Deserialize, serde_derive::Serialize)] +#[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize)] #[serde(transparent)] -pub struct XsdAnyURI(String); +pub struct XsdAnyUri(String); #[derive(Clone, Debug, thiserror::Error)] -#[error("Could not parse XsdAnyURI")] -pub struct XsdAnyURIError; +#[error("Could not parse XsdAnyUri")] +pub struct XsdAnyUriError; -impl std::convert::TryFrom for XsdAnyURI { - type Error = XsdAnyURIError; +impl std::convert::TryFrom for XsdAnyUri { + type Error = XsdAnyUriError; fn try_from(s: String) -> Result { - Ok(XsdAnyURI(s)) + Ok(XsdAnyUri(s)) } } -impl std::convert::TryFrom<&str> for XsdAnyURI { - type Error = XsdAnyURIError; +impl std::convert::TryFrom<&str> for XsdAnyUri { + type Error = XsdAnyUriError; fn try_from(s: &str) -> Result { - Ok(XsdAnyURI(s.to_owned())) + Ok(XsdAnyUri(s.to_owned())) } } -impl std::convert::TryFrom<&mut str> for XsdAnyURI { - type Error = XsdAnyURIError; +impl std::convert::TryFrom<&mut str> for XsdAnyUri { + type Error = XsdAnyUriError; fn try_from(s: &mut str) -> Result { - Ok(XsdAnyURI(s.to_owned())) + Ok(XsdAnyUri(s.to_owned())) } } -impl std::str::FromStr for XsdAnyURI { - type Err = XsdAnyURIError; +impl std::str::FromStr for XsdAnyUri { + type Err = XsdAnyUriError; fn from_str(s: &str) -> Result { - Ok(XsdAnyURI(s.to_owned())) + Ok(XsdAnyUri(s.to_owned())) } } -impl std::fmt::Display for XsdAnyURI { +impl std::fmt::Display for XsdAnyUri { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { std::fmt::Display::fmt(&self.0, f) } diff --git a/activitystreams-types/src/primitives/xsd_float.rs b/activitystreams-types/src/primitives/xsd_float.rs index cd23990..786b0af 100644 --- a/activitystreams-types/src/primitives/xsd_float.rs +++ b/activitystreams-types/src/primitives/xsd_float.rs @@ -1,4 +1,4 @@ -#[derive(Clone, Debug, serde_derive::Deserialize, serde_derive::Serialize)] +#[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize)] #[serde(transparent)] pub struct XsdFloat(f64); diff --git a/activitystreams-types/src/primitives/xsd_non_negative_float.rs b/activitystreams-types/src/primitives/xsd_non_negative_float.rs index a729138..b1bd56e 100644 --- a/activitystreams-types/src/primitives/xsd_non_negative_float.rs +++ b/activitystreams-types/src/primitives/xsd_non_negative_float.rs @@ -1,4 +1,4 @@ -#[derive(Clone, Debug, serde_derive::Deserialize, serde_derive::Serialize)] +#[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize)] #[serde(transparent)] pub struct XsdNonNegativeFloat(f64); diff --git a/activitystreams-types/src/primitives/xsd_non_negative_integer.rs b/activitystreams-types/src/primitives/xsd_non_negative_integer.rs index d9a674f..34cfad0 100644 --- a/activitystreams-types/src/primitives/xsd_non_negative_integer.rs +++ b/activitystreams-types/src/primitives/xsd_non_negative_integer.rs @@ -1,4 +1,4 @@ -#[derive(Clone, Debug, serde_derive::Deserialize, serde_derive::Serialize)] +#[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize)] #[serde(transparent)] pub struct XsdNonNegativeInteger(u64); diff --git a/activitystreams-types/src/primitives/xsd_string.rs b/activitystreams-types/src/primitives/xsd_string.rs index 1096b08..5db7d6b 100644 --- a/activitystreams-types/src/primitives/xsd_string.rs +++ b/activitystreams-types/src/primitives/xsd_string.rs @@ -1,4 +1,4 @@ -#[derive(Clone, Debug, serde_derive::Deserialize, serde_derive::Serialize)] +#[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize)] #[serde(transparent)] pub struct XsdString(String); diff --git a/src/error.rs b/src/error.rs deleted file mode 100644 index 773c163..0000000 --- a/src/error.rs +++ /dev/null @@ -1,22 +0,0 @@ -/* - * This file is part of ActivityStreams. - * - * Copyright © 2018 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 . - */ - -//! Error traits and types - -pub use activitystreams_traits::{Error, Result}; diff --git a/src/lib.rs b/src/lib.rs index 58bc11a..b7682ca 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -125,15 +125,12 @@ pub mod activity; pub mod actor; pub mod collection; -mod error; pub mod link; pub mod object; pub use self::activity::{Activity, ActivityExt, IntransitiveActivity}; pub use self::actor::Actor; pub use self::collection::{Collection, CollectionExt, CollectionPage, CollectionPageExt}; -pub use self::error::{Error, Result}; pub use self::link::{Link, LinkExt}; pub use self::object::{Object, ObjectExt}; -pub use activitystreams_traits::properties; pub use activitystreams_types::context;