Use more specific types for activitystreams fields

This commit is contained in:
asonix 2020-03-09 22:22:48 -05:00
parent 2c0658d77e
commit ac4f1cd5d1
52 changed files with 1616 additions and 1942 deletions

View file

@ -20,6 +20,9 @@ serde_derive = "1.0"
serde_json = "1.0" serde_json = "1.0"
activitystreams-derive = { version = "0.3", path = "activitystreams-derive" } activitystreams-derive = { version = "0.3", path = "activitystreams-derive" }
[profile.dev.package.activitystreams-derive]
opt-level = 3
[workspace] [workspace]
members = [ members = [
"activitystreams-derive", "activitystreams-derive",

View file

@ -96,8 +96,6 @@ use syn::{
token, Attribute, Data, DeriveInput, Fields, Ident, LitStr, Result, Token, Type, token, Attribute, Data, DeriveInput, Fields, Ident, LitStr, Result, Token, Type,
}; };
use std::iter::FromIterator;
#[proc_macro_derive(PropRefs, attributes(activitystreams))] #[proc_macro_derive(PropRefs, attributes(activitystreams))]
pub fn ref_derive(input: TokenStream) -> TokenStream { pub fn ref_derive(input: TokenStream) -> TokenStream {
let input: DeriveInput = syn::parse(input).unwrap(); 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"), _ => panic!("Can only derive for named fields"),
}; };
let impls = fields let tokens: proc_macro2::TokenStream = fields
.named .named
.iter() .iter()
.filter_map(|field| { .filter_map(|field| {
@ -142,25 +140,31 @@ pub fn ref_derive(input: TokenStream) -> TokenStream {
let name = name.clone(); let name = name.clone();
let ext_trait = Ident::new(&format!("{}Ext", object), name.span()); 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! { quote! {
#[typetag::serde] #[typetag::serde]
}
} else {
quote! {}
};
let activity_impls = quote! {
#tt
impl #object for #name { impl #object for #name {
fn as_any(&self) -> &dyn std::any::Any { fn as_any(&self) -> &dyn std::any::Any {
self self
} }
fn as_any_mut(&self) -> &mut dyn std::any::Any { fn as_any_mut(&mut self) -> &mut dyn std::any::Any {
self self
} }
fn duplicate(&self) -> Box<dyn #object> {
Box::new(self.clone())
} }
}
}
} else {
quote! {
impl #object for #name {}
}
};
let activity_impls = quote! {
#base_impl
impl #ext_trait for #name { impl #ext_trait for #name {
fn props(&self) -> &#ty { fn props(&self) -> &#ty {
@ -195,9 +199,8 @@ pub fn ref_derive(input: TokenStream) -> TokenStream {
#activity_impls #activity_impls
} }
} }
}); })
.collect();
let tokens = proc_macro2::TokenStream::from_iter(impls);
let full = quote! { let full = quote! {
#tokens #tokens
@ -317,7 +320,15 @@ fn from_value(attr: Attribute) -> Ident {
#[proc_macro] #[proc_macro]
pub fn properties(tokens: TokenStream) -> TokenStream { 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()); 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 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, deps) = if field.description.types.len() == 1 {
let ty = Ident::new(&field.description.types.first().unwrap().to_token_stream().to_string(), fname.span()); let ty = Ident::new(&field.description.types.first().unwrap().to_token_stream().to_string(), fname.span());
if field.description.functional { if field.description.functional {
@ -342,6 +358,12 @@ pub fn properties(tokens: TokenStream) -> TokenStream {
Array(Vec<#ty>), Array(Vec<#ty>),
} }
impl Default for #enum_ty {
fn default() -> Self {
#enum_ty::Array(Vec::new())
}
}
impl From<#ty> for #enum_ty { impl From<#ty> for #enum_ty {
fn from(t: #ty) -> Self { fn from(t: #ty) -> Self {
#enum_ty::Term(t) #enum_ty::Term(t)
@ -360,7 +382,7 @@ pub fn properties(tokens: TokenStream) -> TokenStream {
} else { } else {
let ty = Ident::new(&camelize(&format!("{}_{}_enum", name, fname)), fname.span()); let ty = Ident::new(&camelize(&format!("{}_{}_enum", name, fname)), fname.span());
let v_tys: Vec<_> = field let v_tokens: proc_macro2::TokenStream = field
.description .description
.types .types
.iter() .iter()
@ -371,12 +393,12 @@ pub fn properties(tokens: TokenStream) -> TokenStream {
}) })
.collect(); .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 deps = if !field.description.functional {
let term_ty = Ident::new(&camelize(&format!("{}_{}_term_enum", name, fname)), fname.span()); 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 .description
.types .types
.iter() .iter()
@ -391,8 +413,6 @@ pub fn properties(tokens: TokenStream) -> TokenStream {
}) })
.collect(); .collect();
let from_tokens = proc_macro2::TokenStream::from_iter(froms);
quote! { quote! {
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
@ -409,6 +429,12 @@ pub fn properties(tokens: TokenStream) -> TokenStream {
Array(Vec<#term_ty>), Array(Vec<#term_ty>),
} }
impl Default for #ty {
fn default() -> Self {
#ty::Array(Vec::new())
}
}
impl From<#term_ty> for #ty { impl From<#term_ty> for #ty {
fn from(term: #term_ty) -> Self { fn from(term: #term_ty) -> Self {
#ty::Term(term) #ty::Term(term)
@ -424,7 +450,7 @@ pub fn properties(tokens: TokenStream) -> TokenStream {
#from_tokens #from_tokens
} }
} else { } else {
let froms: Vec<_> = field let from_tokens: proc_macro2::TokenStream = field
.description .description
.types .types
.iter() .iter()
@ -439,8 +465,6 @@ pub fn properties(tokens: TokenStream) -> TokenStream {
}) })
.collect(); .collect();
let from_tokens = proc_macro2::TokenStream::from_iter(froms);
quote! { quote! {
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
@ -449,6 +473,12 @@ pub fn properties(tokens: TokenStream) -> TokenStream {
#v_tokens #v_tokens
} }
impl Default for #ty {
fn default() -> Self {
#ty::#first_type(Default::default())
}
}
#from_tokens #from_tokens
} }
}; };
@ -456,30 +486,29 @@ pub fn properties(tokens: TokenStream) -> TokenStream {
(ty, Some(deps)) (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 { let field_tokens = if field.description.required {
if let Some(ref rename) = field.description.rename {
quote! {
#[serde(rename = #rename)]
pub #fname: #ty,
}
} else {
quote! { quote! {
pub #fname: #ty, 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 { } else {
quote! { quote! {
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub #fname: Option<#ty>, pub #fname: Option<#ty>,
} }
} };
let field_tokens = quote!{
#fdocs
#rename_tokens
#alias_tokens
#field_tokens
}; };
let fns = if field.description.types.len() == 1 { let fns = if field.description.types.len() == 1 {
@ -637,7 +666,7 @@ pub fn properties(tokens: TokenStream) -> TokenStream {
} }
} }
} else if field.description.functional { } else if field.description.functional {
let impls: Vec<_> = field let tokens: proc_macro2::TokenStream = field
.description .description
.types .types
.iter() .iter()
@ -701,14 +730,12 @@ pub fn properties(tokens: TokenStream) -> TokenStream {
}) })
.collect(); .collect();
let tokens = proc_macro2::TokenStream::from_iter(impls);
quote! { quote! {
#tokens #tokens
} }
} else { } else {
let term_ty = Ident::new(&camelize(&format!("{}_{}_term_enum", name, fname)), fname.span()); let term_ty = Ident::new(&camelize(&format!("{}_{}_term_enum", name, fname)), fname.span());
let impls: Vec<_> = field let tokens: proc_macro2::TokenStream = field
.description .description
.types .types
.iter() .iter()
@ -825,8 +852,6 @@ pub fn properties(tokens: TokenStream) -> TokenStream {
}) })
.collect(); .collect();
let tokens = proc_macro2::TokenStream::from_iter(impls);
let delete = if !field.description.required { let delete = if !field.description.required {
let delete_ident = let delete_ident =
Ident::new(&format!("delete_{}", fname), fname.span()); Ident::new(&format!("delete_{}", fname), fname.span());
@ -851,17 +876,13 @@ pub fn properties(tokens: TokenStream) -> TokenStream {
Some(((field_tokens, fns), deps)) Some(((field_tokens, fns), deps))
}).unzip(); }).unzip();
let (fields, fns): (Vec<_>, Vec<_>) = fields.into_iter().unzip(); let (field_tokens, fn_tokens): (proc_macro2::TokenStream, proc_macro2::TokenStream) =
let deps: Vec<_> = deps.into_iter().filter_map(|d| d).collect(); fields.into_iter().unzip();
let deps_tokens: proc_macro2::TokenStream = 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 q = quote! { let q = quote! {
#deps_tokens #docs
#[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize)]
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct #name { pub struct #name {
#field_tokens #field_tokens
@ -870,6 +891,8 @@ pub fn properties(tokens: TokenStream) -> TokenStream {
impl #name { impl #name {
#fn_tokens #fn_tokens
} }
#deps_tokens
}; };
q.into() q.into()
} }
@ -879,10 +902,13 @@ mod kw {
syn::custom_keyword!(functional); syn::custom_keyword!(functional);
syn::custom_keyword!(required); syn::custom_keyword!(required);
syn::custom_keyword!(rename); syn::custom_keyword!(rename);
syn::custom_keyword!(alias);
syn::custom_keyword!(docs);
} }
struct Properties { struct Properties {
name: Ident, name: Ident,
docs: Vec<String>,
fields: Punctuated<Field, Token![,]>, fields: Punctuated<Field, Token![,]>,
} }
@ -892,10 +918,12 @@ struct Field {
} }
struct Description { struct Description {
docs: Vec<String>,
types: Punctuated<Type, Token![,]>, types: Punctuated<Type, Token![,]>,
functional: bool, functional: bool,
required: bool, required: bool,
rename: Option<String>, rename: Option<String>,
aliases: Vec<String>,
} }
impl Parse for Properties { impl Parse for Properties {
@ -904,9 +932,12 @@ impl Parse for Properties {
let content; let content;
let _: token::Brace = braced!(content in input); let _: token::Brace = braced!(content in input);
let docs = parse_string_array::<_, kw::docs>(&&content, kw::docs)?;
let fields = Punctuated::<Field, Token![,]>::parse_terminated(&content)?; let fields = Punctuated::<Field, Token![,]>::parse_terminated(&content)?;
Ok(Properties { name, fields }) Ok(Properties { name, docs, fields })
} }
} }
@ -925,6 +956,8 @@ impl Parse for Field {
impl Parse for Description { impl Parse for Description {
fn parse(input: ParseStream) -> Result<Self> { fn parse(input: ParseStream) -> Result<Self> {
let docs = parse_string_array::<_, kw::docs>(&input, kw::docs)?;
let lookahead = input.lookahead1(); let lookahead = input.lookahead1();
if !lookahead.peek(kw::types) { if !lookahead.peek(kw::types) {
return Err(lookahead.error()); return Err(lookahead.error());
@ -938,13 +971,16 @@ impl Parse for Description {
let functional = parse_kw::<_, kw::functional>(&input, kw::functional)?; let functional = parse_kw::<_, kw::functional>(&input, kw::functional)?;
let required = parse_kw::<_, kw::required>(&input, kw::required)?; 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 { Ok(Description {
docs,
types, types,
functional, functional,
required, required,
rename, rename,
aliases,
}) })
} }
} }
@ -961,7 +997,25 @@ fn parse_kw<T: Peek + Copy, U: Parse>(input: &ParseStream, t: T) -> Result<bool>
Ok(false) Ok(false)
} }
fn parse_rename<T: Peek + Copy, U: Parse>(input: &ParseStream, t: T) -> Result<Option<String>> { fn parse_string_array<T: Peek + Copy, U: Parse>(input: &ParseStream, t: T) -> Result<Vec<String>> {
let lookahead = input.lookahead1();
if lookahead.peek(t) {
input.parse::<U>()?;
let content;
bracketed!(content in input);
let docs = Punctuated::<LitStr, Token![,]>::parse_terminated(&content)?;
optional_comma(&input)?;
Ok(docs.into_iter().map(|d| d.value()).collect())
} else {
Ok(vec![])
}
}
fn parse_string_group<T: Peek + Copy, U: Parse>(
input: &ParseStream,
t: T,
) -> Result<Option<String>> {
let lookahead = input.lookahead1(); let lookahead = input.lookahead1();
if lookahead.peek(t) { if lookahead.peek(t) {
input.parse::<U>()?; input.parse::<U>()?;

View file

@ -10,7 +10,6 @@ keywords = ["activitystreams", "activitypub"]
edition = "2018" edition = "2018"
[dependencies] [dependencies]
thiserror = "1.0"
typetag = "0.1.4" typetag = "0.1.4"
[dev-dependencies] [dev-dependencies]

View file

@ -32,4 +32,6 @@ pub trait Link: std::fmt::Debug {
fn as_any(&self) -> &dyn Any; fn as_any(&self) -> &dyn Any;
fn as_any_mut(&mut self) -> &mut dyn Any; fn as_any_mut(&mut self) -> &mut dyn Any;
fn duplicate(&self) -> Box<dyn Link>;
} }

View file

@ -29,4 +29,6 @@ pub trait Object: std::fmt::Debug {
fn as_any(&self) -> &dyn Any; fn as_any(&self) -> &dyn Any;
fn as_any_mut(&mut self) -> &mut dyn Any; fn as_any_mut(&mut self) -> &mut dyn Any;
fn duplicate(&self) -> Box<dyn Object>;
} }

View file

@ -17,9 +17,9 @@
* along with ActivityStreams Types. If not, see <http://www.gnu.org/licenses/>. * along with ActivityStreams Types. If not, see <http://www.gnu.org/licenses/>.
*/ */
use activitystreams_derive::Properties; use activitystreams_derive::PropRefs;
use activitystreams_traits::{Activity, Object}; use activitystreams_traits::{Activity, Object};
use serde_derive::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use super::{ use super::{
kind::AcceptType, 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 /// The target property can be used in certain circumstances to indicate the context into which the
/// object has been accepted. /// object has been accepted.
#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)] #[derive(Clone, Debug, Default, Deserialize, PropRefs, Serialize)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct Accept { pub struct Accept {
#[serde(rename = "type")] #[serde(rename = "type")]
@ -42,34 +42,16 @@ pub struct Accept {
/// Adds all valid accept properties to this struct /// Adds all valid accept properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(None)]
pub accept_props: AcceptProperties, pub accept_props: AcceptProperties,
/// Adds all valid object properties to this struct /// Adds all valid object properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(Object)]
pub object_props: ObjectProperties, pub object_props: ObjectProperties,
/// Adds all valid activity properties to this struct /// Adds all valid activity properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(Activity)]
pub activity_props: ActivityProperties, 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
}
}

View file

@ -17,9 +17,9 @@
* along with ActivityStreams Types. If not, see <http://www.gnu.org/licenses/>. * along with ActivityStreams Types. If not, see <http://www.gnu.org/licenses/>.
*/ */
use activitystreams_derive::Properties; use activitystreams_derive::PropRefs;
use activitystreams_traits::{Activity, Object}; use activitystreams_traits::{Activity, Object};
use serde_derive::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use super::{ use super::{
kind::AddType, 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 /// 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 /// implicitly by context. The origin can be used to identify the context from which the object
/// originated. /// originated.
#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)] #[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct Add { pub struct Add {
#[serde(rename = "type")] #[serde(rename = "type")]
@ -43,34 +43,16 @@ pub struct Add {
/// Adds all valid add properties to this struct /// Adds all valid add properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(None)]
pub add_props: AddProperties, pub add_props: AddProperties,
/// Adds all valid object properties to this struct /// Adds all valid object properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(Object)]
pub object_props: ObjectProperties, pub object_props: ObjectProperties,
/// Adds all valid activity properties to this struct /// Adds all valid activity properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(Activity)]
pub activity_props: ActivityProperties, 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
}
}

View file

@ -17,9 +17,9 @@
* along with ActivityStreams Types. If not, see <http://www.gnu.org/licenses/>. * along with ActivityStreams Types. If not, see <http://www.gnu.org/licenses/>.
*/ */
use activitystreams_derive::Properties; use activitystreams_derive::PropRefs;
use activitystreams_traits::{Activity, Object}; use activitystreams_traits::{Activity, Object};
use serde_derive::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use super::{ use super::{
kind::MoveType, kind::MoveType,
@ -31,7 +31,7 @@ use crate::object::{properties::ObjectProperties, ObjectExt};
/// Indicates that the actor has moved object from origin to target. /// 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. /// 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")] #[serde(rename_all = "camelCase")]
pub struct AMove { pub struct AMove {
#[serde(rename = "type")] #[serde(rename = "type")]
@ -41,34 +41,16 @@ pub struct AMove {
/// Adds all valid move properties to this struct /// Adds all valid move properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(None)]
pub move_props: MoveProperties, pub move_props: MoveProperties,
/// Adds all valid object properties to this struct /// Adds all valid object properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(Object)]
pub object_props: ObjectProperties, pub object_props: ObjectProperties,
/// Adds all valid activity properties to this struct /// Adds all valid activity properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(Activity)]
pub activity_props: ActivityProperties, 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
}
}

View file

@ -17,9 +17,9 @@
* along with ActivityStreams Types. If not, see <http://www.gnu.org/licenses/>. * along with ActivityStreams Types. If not, see <http://www.gnu.org/licenses/>.
*/ */
use activitystreams_derive::Properties; use activitystreams_derive::PropRefs;
use activitystreams_traits::{Activity, Object}; use activitystreams_traits::{Activity, Object};
use serde_derive::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use super::{ use super::{
kind::AnnounceType, kind::AnnounceType,
@ -31,7 +31,7 @@ use crate::object::{properties::ObjectProperties, ObjectExt};
/// Indicates that the actor is calling the target's attention the object. /// Indicates that the actor is calling the target's attention the object.
/// ///
/// The origin typically has no defined meaning. /// 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")] #[serde(rename_all = "camelCase")]
pub struct Announce { pub struct Announce {
#[serde(rename = "type")] #[serde(rename = "type")]
@ -41,34 +41,16 @@ pub struct Announce {
/// Adds all valid announce properties to this struct /// Adds all valid announce properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(None)]
pub announce_props: AnnounceProperties, pub announce_props: AnnounceProperties,
/// Adds all valid object properties to this struct /// Adds all valid object properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(Object)]
pub object_props: ObjectProperties, pub object_props: ObjectProperties,
/// Adds all valid activity properties to this struct /// Adds all valid activity properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(Activity)]
pub activity_props: ActivityProperties, 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
}
}

View file

@ -17,9 +17,9 @@
* along with ActivityStreams Types. If not, see <http://www.gnu.org/licenses/>. * along with ActivityStreams Types. If not, see <http://www.gnu.org/licenses/>.
*/ */
use activitystreams_derive::Properties; use activitystreams_derive::PropRefs;
use activitystreams_traits::{Activity, IntransitiveActivity, Object}; use activitystreams_traits::{Activity, IntransitiveActivity, Object};
use serde_derive::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use super::{ use super::{
kind::ArriveType, 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 /// The origin can be used to identify the context from which the actor originated. The target
/// typically has no defined meaning. /// typically has no defined meaning.
#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)] #[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct Arrive { pub struct Arrive {
#[serde(rename = "type")] #[serde(rename = "type")]
@ -42,35 +42,18 @@ pub struct Arrive {
/// Adds all valid arrive properties to this struct /// Adds all valid arrive properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(None)]
pub arrive_props: ArriveProperties, pub arrive_props: ArriveProperties,
/// Adds all valid object properties to this struct /// Adds all valid object properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(Object)]
pub object_props: ObjectProperties, pub object_props: ObjectProperties,
/// Adds all valid activity properties to this struct /// Adds all valid activity properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(Activity)]
pub activity_props: ActivityProperties, 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 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
}
}

View file

@ -17,9 +17,9 @@
* along with ActivityStreams Types. If not, see <http://www.gnu.org/licenses/>. * along with ActivityStreams Types. If not, see <http://www.gnu.org/licenses/>.
*/ */
use activitystreams_derive::Properties; use activitystreams_derive::PropRefs;
use activitystreams_traits::{Activity, Object}; use activitystreams_traits::{Activity, Object};
use serde_derive::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use super::{ use super::{
kind::BlockType, 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 /// 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 /// one user to block activities or content of other users. The target and origin typically have no
/// defined meaning. /// defined meaning.
#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)] #[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct Block { pub struct Block {
#[serde(rename = "type")] #[serde(rename = "type")]
@ -43,34 +43,16 @@ pub struct Block {
/// Adds all valid block properties to this struct /// Adds all valid block properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(None)]
pub block_props: BlockProperties, pub block_props: BlockProperties,
/// Adds all valid object properties to this struct /// Adds all valid object properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(Object)]
pub object_props: ObjectProperties, pub object_props: ObjectProperties,
/// Adds all valid activity properties to this struct /// Adds all valid activity properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(Activity)]
pub activity_props: ActivityProperties, 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
}
}

View file

@ -17,9 +17,9 @@
* along with ActivityStreams Types. If not, see <http://www.gnu.org/licenses/>. * along with ActivityStreams Types. If not, see <http://www.gnu.org/licenses/>.
*/ */
use activitystreams_derive::Properties; use activitystreams_derive::PropRefs;
use activitystreams_traits::{Activity, Object}; use activitystreams_traits::{Activity, Object};
use serde_derive::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use super::{ use super::{
kind::CreateType, kind::CreateType,
@ -29,7 +29,7 @@ use super::{
use crate::object::{properties::ObjectProperties, ObjectExt}; use crate::object::{properties::ObjectProperties, ObjectExt};
/// Indicates that the actor has created the object. /// 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")] #[serde(rename_all = "camelCase")]
pub struct Create { pub struct Create {
#[serde(rename = "type")] #[serde(rename = "type")]
@ -39,34 +39,16 @@ pub struct Create {
/// Adds all valid create properties to this struct /// Adds all valid create properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(None)]
pub create_props: CreateProperties, pub create_props: CreateProperties,
/// Adds all valid object properties to this struct /// Adds all valid object properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(Object)]
pub object_props: ObjectProperties, pub object_props: ObjectProperties,
/// Adds all valid activity properties to this struct /// Adds all valid activity properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(Activity)]
pub activity_props: ActivityProperties, 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
}
}

View file

@ -17,9 +17,9 @@
* along with ActivityStreams Types. If not, see <http://www.gnu.org/licenses/>. * along with ActivityStreams Types. If not, see <http://www.gnu.org/licenses/>.
*/ */
use activitystreams_derive::Properties; use activitystreams_derive::PropRefs;
use activitystreams_traits::{Activity, Object}; use activitystreams_traits::{Activity, Object};
use serde_derive::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use super::{ use super::{
kind::DeleteType, kind::DeleteType,
@ -31,7 +31,7 @@ use crate::object::{properties::ObjectProperties, ObjectExt};
/// Indicates that the actor has deleted the object. /// Indicates that the actor has deleted the object.
/// ///
/// If specified, the origin indicates the context from which the object was deleted. /// 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")] #[serde(rename_all = "camelCase")]
pub struct Delete { pub struct Delete {
#[serde(rename = "type")] #[serde(rename = "type")]
@ -41,34 +41,16 @@ pub struct Delete {
/// Adds all valid delete properties to this struct /// Adds all valid delete properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(None)]
pub delete_props: DeleteProperties, pub delete_props: DeleteProperties,
/// Adds all valid object properties to this struct /// Adds all valid object properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(Object)]
pub object_props: ObjectProperties, pub object_props: ObjectProperties,
/// Adds all valid activity properties to this struct /// Adds all valid activity properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(Activity)]
pub activity_props: ActivityProperties, 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
}
}

View file

@ -17,9 +17,9 @@
* along with ActivityStreams Types. If not, see <http://www.gnu.org/licenses/>. * along with ActivityStreams Types. If not, see <http://www.gnu.org/licenses/>.
*/ */
use activitystreams_derive::Properties; use activitystreams_derive::PropRefs;
use activitystreams_traits::{Activity, Object}; use activitystreams_traits::{Activity, Object};
use serde_derive::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use super::{ use super::{
kind::DislikeType, kind::DislikeType,
@ -29,7 +29,7 @@ use super::{
use crate::object::{properties::ObjectProperties, ObjectExt}; use crate::object::{properties::ObjectProperties, ObjectExt};
/// Indicates that the actor dislikes the object. /// 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")] #[serde(rename_all = "camelCase")]
pub struct Dislike { pub struct Dislike {
#[serde(rename = "type")] #[serde(rename = "type")]
@ -39,34 +39,16 @@ pub struct Dislike {
/// Adds all valid dislike properties to this struct /// Adds all valid dislike properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(None)]
pub dislike_props: DislikeProperties, pub dislike_props: DislikeProperties,
/// Adds all valid object properties to this struct /// Adds all valid object properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(Object)]
pub object_props: ObjectProperties, pub object_props: ObjectProperties,
/// Adds all valid activity properties to this struct /// Adds all valid activity properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(Activity)]
pub activity_props: ActivityProperties, 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
}
}

View file

@ -17,9 +17,9 @@
* along with ActivityStreams Types. If not, see <http://www.gnu.org/licenses/>. * along with ActivityStreams Types. If not, see <http://www.gnu.org/licenses/>.
*/ */
use activitystreams_derive::Properties; use activitystreams_derive::PropRefs;
use activitystreams_traits::{Activity, Object}; use activitystreams_traits::{Activity, Object};
use serde_derive::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use super::{ use super::{
kind::FlagType, 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 /// Flagging is defined in the sense common to many social platforms as reporting content as being
/// inappropriate for any number of reasons. /// inappropriate for any number of reasons.
#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)] #[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct Flag { pub struct Flag {
#[serde(rename = "type")] #[serde(rename = "type")]
@ -42,34 +42,16 @@ pub struct Flag {
/// Adds all valid flag properties to this struct /// Adds all valid flag properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(None)]
pub flag_props: FlagProperties, pub flag_props: FlagProperties,
/// Adds all valid object properties to this struct /// Adds all valid object properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(Object)]
pub object_props: ObjectProperties, pub object_props: ObjectProperties,
/// Adds all valid activity properties to this struct /// Adds all valid activity properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(Activity)]
pub activity_props: ActivityProperties, 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
}
}

View file

@ -17,9 +17,9 @@
* along with ActivityStreams Types. If not, see <http://www.gnu.org/licenses/>. * along with ActivityStreams Types. If not, see <http://www.gnu.org/licenses/>.
*/ */
use activitystreams_derive::Properties; use activitystreams_derive::PropRefs;
use activitystreams_traits::{Activity, Object}; use activitystreams_traits::{Activity, Object};
use serde_derive::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use super::{ use super::{
kind::FollowType, 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 /// 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 /// interested in any activity performed by or on the object. The target and origin typically have
/// no defined meaning. /// no defined meaning.
#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)] #[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct Follow { pub struct Follow {
#[serde(rename = "type")] #[serde(rename = "type")]
@ -43,34 +43,16 @@ pub struct Follow {
/// Adds all valid follow properties to this struct /// Adds all valid follow properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(None)]
pub follow_props: FollowProperties, pub follow_props: FollowProperties,
/// Adds all valid object properties to this struct /// Adds all valid object properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(Object)]
pub object_props: ObjectProperties, pub object_props: ObjectProperties,
/// Adds all valid activity properties to this struct /// Adds all valid activity properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(Activity)]
pub activity_props: ActivityProperties, 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
}
}

View file

@ -17,9 +17,9 @@
* along with ActivityStreams Types. If not, see <http://www.gnu.org/licenses/>. * along with ActivityStreams Types. If not, see <http://www.gnu.org/licenses/>.
*/ */
use activitystreams_derive::Properties; use activitystreams_derive::PropRefs;
use activitystreams_traits::{Activity, Object}; use activitystreams_traits::{Activity, Object};
use serde_derive::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use super::{ use super::{
kind::IgnoreType, kind::IgnoreType,
@ -31,7 +31,7 @@ use crate::object::{properties::ObjectProperties, ObjectExt};
/// Indicates that the actor is ignoring the object. /// Indicates that the actor is ignoring the object.
/// ///
/// The target and origin typically have no defined meaning. /// 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")] #[serde(rename_all = "camelCase")]
pub struct Ignore { pub struct Ignore {
#[serde(rename = "type")] #[serde(rename = "type")]
@ -41,34 +41,16 @@ pub struct Ignore {
/// Adds all valid ignore properties to this struct /// Adds all valid ignore properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(None)]
pub ignore_props: IgnoreProperties, pub ignore_props: IgnoreProperties,
/// Adds all valid object properties to this struct /// Adds all valid object properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(Object)]
pub object_props: ObjectProperties, pub object_props: ObjectProperties,
/// Adds all valid activity properties to this struct /// Adds all valid activity properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(Activity)]
pub activity_props: ActivityProperties, 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
}
}

View file

@ -17,9 +17,9 @@
* along with ActivityStreams Types. If not, see <http://www.gnu.org/licenses/>. * along with ActivityStreams Types. If not, see <http://www.gnu.org/licenses/>.
*/ */
use activitystreams_derive::Properties; use activitystreams_derive::PropRefs;
use activitystreams_traits::{Activity, Object}; use activitystreams_traits::{Activity, Object};
use serde_derive::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use super::{ use super::{
kind::InviteType, 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 /// A specialization of Offer in which the actor is extending an invitation for the object to the
/// target. /// target.
#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)] #[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct Invite { pub struct Invite {
#[serde(rename = "type")] #[serde(rename = "type")]
@ -40,34 +40,16 @@ pub struct Invite {
/// Adds all valid invite properties to this struct /// Adds all valid invite properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(None)]
pub invite_props: InviteProperties, pub invite_props: InviteProperties,
/// Adds all valid object properties to this struct /// Adds all valid object properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(Object)]
pub object_props: ObjectProperties, pub object_props: ObjectProperties,
/// Adds all valid activity properties to this struct /// Adds all valid activity properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(Activity)]
pub activity_props: ActivityProperties, 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
}
}

View file

@ -17,9 +17,9 @@
* along with ActivityStreams Types. If not, see <http://www.gnu.org/licenses/>. * along with ActivityStreams Types. If not, see <http://www.gnu.org/licenses/>.
*/ */
use activitystreams_derive::Properties; use activitystreams_derive::PropRefs;
use activitystreams_traits::{Activity, Object}; use activitystreams_traits::{Activity, Object};
use serde_derive::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use super::{ use super::{
kind::JoinType, kind::JoinType,
@ -31,7 +31,7 @@ use crate::object::{properties::ObjectProperties, ObjectExt};
/// Indicates that the actor has joined the object. /// Indicates that the actor has joined the object.
/// ///
/// The target and origin typically have no defined meaning /// 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")] #[serde(rename_all = "camelCase")]
pub struct Join { pub struct Join {
#[serde(rename = "type")] #[serde(rename = "type")]
@ -41,34 +41,16 @@ pub struct Join {
/// Adds all valid join properties to this struct /// Adds all valid join properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(None)]
pub join_props: JoinProperties, pub join_props: JoinProperties,
/// Adds all valid object properties to this struct /// Adds all valid object properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(Object)]
pub object_props: ObjectProperties, pub object_props: ObjectProperties,
/// Adds all valid activity properties to this struct /// Adds all valid activity properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(Activity)]
pub activity_props: ActivityProperties, 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
}
}

View file

@ -17,9 +17,9 @@
* along with ActivityStreams Types. If not, see <http://www.gnu.org/licenses/>. * along with ActivityStreams Types. If not, see <http://www.gnu.org/licenses/>.
*/ */
use activitystreams_derive::Properties; use activitystreams_derive::PropRefs;
use activitystreams_traits::{Activity, Object}; use activitystreams_traits::{Activity, Object};
use serde_derive::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use super::{ use super::{
kind::LeaveType, kind::LeaveType,
@ -31,7 +31,7 @@ use crate::object::{properties::ObjectProperties, ObjectExt};
/// Indicates that the actor has left the object. /// Indicates that the actor has left the object.
/// ///
/// The target and origin typically have no meaning. /// 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")] #[serde(rename_all = "camelCase")]
pub struct Leave { pub struct Leave {
#[serde(rename = "type")] #[serde(rename = "type")]
@ -41,34 +41,16 @@ pub struct Leave {
/// Adds all valid leave properties to this struct /// Adds all valid leave properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(None)]
pub leave_props: LeaveProperties, pub leave_props: LeaveProperties,
/// Adds all valid object properties to this struct /// Adds all valid object properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(Object)]
pub object_props: ObjectProperties, pub object_props: ObjectProperties,
/// Adds all valid activity properties to this struct /// Adds all valid activity properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(Activity)]
pub activity_props: ActivityProperties, 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
}
}

View file

@ -17,9 +17,9 @@
* along with ActivityStreams Types. If not, see <http://www.gnu.org/licenses/>. * along with ActivityStreams Types. If not, see <http://www.gnu.org/licenses/>.
*/ */
use activitystreams_derive::Properties; use activitystreams_derive::PropRefs;
use activitystreams_traits::{Activity, Object}; use activitystreams_traits::{Activity, Object};
use serde_derive::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use super::{ use super::{
kind::LikeType, kind::LikeType,
@ -31,7 +31,7 @@ use crate::object::{properties::ObjectProperties, ObjectExt};
/// Indicates that the actor likes, recommends or endorses the object. /// Indicates that the actor likes, recommends or endorses the object.
/// ///
/// The target and origin typically have no defined meaning. /// 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")] #[serde(rename_all = "camelCase")]
pub struct Like { pub struct Like {
#[serde(rename = "type")] #[serde(rename = "type")]
@ -41,34 +41,16 @@ pub struct Like {
/// Adds all valid like properties to this struct /// Adds all valid like properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(None)]
pub like_props: LikeProperties, pub like_props: LikeProperties,
/// Adds all valid object properties to this struct /// Adds all valid object properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(Object)]
pub object_props: ObjectProperties, pub object_props: ObjectProperties,
/// Adds all valid activity properties to this struct /// Adds all valid activity properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(Activity)]
pub activity_props: ActivityProperties, 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
}
}

View file

@ -17,9 +17,9 @@
* along with ActivityStreams Types. If not, see <http://www.gnu.org/licenses/>. * along with ActivityStreams Types. If not, see <http://www.gnu.org/licenses/>.
*/ */
use activitystreams_derive::Properties; use activitystreams_derive::PropRefs;
use activitystreams_traits::{Activity, Object}; use activitystreams_traits::{Activity, Object};
use serde_derive::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use super::{ use super::{
kind::ListenType, kind::ListenType,
@ -29,7 +29,7 @@ use super::{
use crate::object::{properties::ObjectProperties, ObjectExt}; use crate::object::{properties::ObjectProperties, ObjectExt};
/// Indicates that the actor has listened to the object. /// 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")] #[serde(rename_all = "camelCase")]
pub struct Listen { pub struct Listen {
#[serde(rename = "type")] #[serde(rename = "type")]
@ -39,34 +39,16 @@ pub struct Listen {
/// Adds all valid listen properties to this struct /// Adds all valid listen properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(None)]
pub listen_props: ListenProperties, pub listen_props: ListenProperties,
/// Adds all valid object properties to this struct /// Adds all valid object properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(Object)]
pub object_props: ObjectProperties, pub object_props: ObjectProperties,
/// Adds all valid activity properties to this struct /// Adds all valid activity properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(Activity)]
pub activity_props: ActivityProperties, 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
}
}

View file

@ -17,9 +17,9 @@
* along with ActivityStreams Types. If not, see <http://www.gnu.org/licenses/>. * along with ActivityStreams Types. If not, see <http://www.gnu.org/licenses/>.
*/ */
use activitystreams_derive::Properties; use activitystreams_derive::PropRefs;
use activitystreams_traits::{Activity, Object}; use activitystreams_traits::{Activity, Object};
use serde_derive::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use super::{ use super::{
kind::OfferType, kind::OfferType,
@ -31,7 +31,7 @@ use crate::object::{properties::ObjectProperties, ObjectExt};
/// Indicates that the actor is offering the object. /// Indicates that the actor is offering the object.
/// ///
/// If specified, the target indicates the entity to which the object is being offered. /// 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")] #[serde(rename_all = "camelCase")]
pub struct Offer { pub struct Offer {
#[serde(rename = "type")] #[serde(rename = "type")]
@ -41,34 +41,16 @@ pub struct Offer {
/// Adds all valid object properties to this struct /// Adds all valid object properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(None)]
pub offer_props: OfferProperties, pub offer_props: OfferProperties,
/// Adds all valid object properties to this struct /// Adds all valid object properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(Object)]
pub object_props: ObjectProperties, pub object_props: ObjectProperties,
/// Adds all valid activity properties to this struct /// Adds all valid activity properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(Activity)]
pub activity_props: ActivityProperties, 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
}
}

View file

@ -1,5 +1,4 @@
/* /* This file is part of ActivityStreams Types.
* This file is part of ActivityStreams Types.
* *
* Copyright © 2018 Riley Trautman * Copyright © 2018 Riley Trautman
* *
@ -27,9 +26,9 @@
//! activity::properties::ActivityProperties, //! activity::properties::ActivityProperties,
//! object::properties::ObjectProperties, //! 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")] //! #[serde(rename_all = "camelCase")]
//! pub struct MyActivity { //! pub struct MyActivity {
//! #[serde(rename = "type")] //! #[serde(rename = "type")]
@ -53,400 +52,582 @@
//! # fn main() {} //! # fn main() {}
//! ``` //! ```
use activitystreams_derive::Properties; use crate::{link::LinkBox, object::ObjectBox, primitives::*};
use activitystreams_traits::{Link, Object}; use activitystreams_derive::properties;
use serde_derive::{Deserialize, Serialize};
/// Activity objects are specializations of the base Object type that provide information about properties! {
/// actions that have either already occurred, are in the process of occurring, or may occur in the Activity {
/// future. docs [
#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)] "Activity objects are specializations of the base Object type that provide information about",
#[serde(rename_all = "camelCase")] "actions that have either already occurred, are in the process of occurring, or may occur in the",
pub struct ActivityProperties { "future.",
/// 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<serde_json::Value>,
/// Identifies one or more objects used (or to be used) in the completion of an `Activity`. result {
/// docs [
/// - Range: `Object` | `Link` "Describes the result of the activity.",
/// - Funcitonal: false "",
#[serde(skip_serializing_if = "Option::is_none")] "For instance, if a particular action results in the creation of a new resource, the result",
#[activitystreams(ab(Object, Link), concrete(String))] "property can be used to describe that new resource.",
pub instrument: Option<serde_json::Value>, "",
"- 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 properties! {
#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)] ActorOptOriginAndTarget {
#[serde(rename_all = "camelCase")] docs [ "Struct with `actor` and optional `origin` and `target` properties" ],
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,
/// Describes an indirect object of the activity from which the activity is directed. actor {
/// docs [
/// The precise meaning of the origin is the object of the English preposition "from". For "Describes one or more entities that either performed or are expected to perform the",
/// instance, in the activity "John moved an item to List B from List A", the origin of the "activity.",
/// activity is "List A". "",
/// "Any single activity can have multiple actors. The actor MAY be specified using an indirect",
/// - Range: `Object` | `Link` "Link.",
/// - Functional: false "",
#[serde(skip_serializing_if = "Option::is_none")] "- Range: `Object` | `Link`",
#[activitystreams(ab(Object, Link), concrete(String))] "- Functional: false",
pub origin: Option<serde_json::Value>, ],
types [
XsdAnyUri,
ObjectBox,
LinkBox,
],
required
},
/// Describes the indirect object, or target, of the activity. origin {
/// docs [
/// The precise meaning of the target is largely dependent on the type of action being "Describes an indirect object of the activity from which the activity is directed.",
/// 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 "The precise meaning of the origin is the object of the English preposition \"from\". For",
/// wishlist. An activity can have more than one target "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 "- Range: `Object` | `Link`",
#[serde(skip_serializing_if = "Option::is_none")] "- Functional: false",
#[activitystreams(ab(Object, Link), concrete(String))] ],
pub target: Option<serde_json::Value>, 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 properties! {
#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)] ActorAndObject {
#[serde(rename_all = "camelCase")] docs [ "Struct with `actor` and `object` properties" ],
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,
/// When used within an Activity, describes the direct object of the activity. actor {
/// docs [
/// For instance, in the activity "John added a movie to his wishlist", the object of the "Describes one or more entities that either performed or are expected to perform the",
/// activity is the movie added. "activity.",
/// "",
/// - Range: `Object` | `Link` "Any single activity can have multiple actors. The actor MAY be specified using an indirect",
/// - Functional: false "Link.",
#[activitystreams(ab(Object, Link), concrete(String))] "",
pub object: serde_json::Value, "- 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 properties! {
#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)] ActorObjectAndTarget {
#[serde(rename_all = "camelCase")] docs [ "Struct with `actor`, `object`, and `target` properties" ],
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,
/// When used within an Activity, describes the direct object of the activity. actor {
/// docs [
/// For instance, in the activity "John added a movie to his wishlist", the object of the "Describes one or more entities that either performed or are expected to perform the",
/// activity is the movie added. "activity.",
/// "",
/// - Range: `Object` | `Link` "Any single activity can have multiple actors. The actor MAY be specified using an indirect",
/// - Functional: false "Link.",
#[activitystreams(ab(Object, Link), concrete(String))] "",
pub object: serde_json::Value, "- Range: `Object` | `Link`",
"- Functional: false",
],
types [
XsdAnyUri,
ObjectBox,
LinkBox,
],
required,
},
/// Describes the indirect object, or target, of the activity. object {
/// docs [
/// The precise meaning of the target is largely dependent on the type of action being "When used within an Activity, describes the direct object of the activity.",
/// 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 "For instance, in the activity \"John added a movie to his wishlist\", the object of the",
/// wishlist. An activity can have more than one target "activity is the movie added.",
/// "",
/// - Range: `Object` | `Link` "- Range: `Object` | `Link`",
/// - Functional: false "- Functional: false",
#[activitystreams(ab(Object, Link), concrete(String))] ],
pub target: serde_json::Value, 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 properties! {
#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)] ActorAndObjectOptTarget {
#[serde(rename_all = "camelCase")] docs [ "Struct with `actor`, `object`, and optional `target` properties" ],
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,
/// When used within an Activity, describes the direct object of the activity. actor {
/// docs [
/// For instance, in the activity "John added a movie to his wishlist", the object of the "Describes one or more entities that either performed or are expected to perform the",
/// activity is the movie added. "activity.",
/// "",
/// - Range: `Object` | `Link` "Any single activity can have multiple actors. The actor MAY be specified using an indirect",
/// - Functional: false "Link.",
#[activitystreams(ab(Object, Link), concrete(String))] "",
pub object: serde_json::Value, "- Range: `Object` | `Link`",
"- Functional: false",
],
types [
XsdAnyUri,
ObjectBox,
LinkBox,
],
required,
},
/// Describes the indirect object, or target, of the activity. object {
/// docs [
/// The precise meaning of the target is largely dependent on the type of action being "When used within an Activity, describes the direct object of the activity.",
/// 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 "For instance, in the activity \"John added a movie to his wishlist\", the object of the",
/// wishlist. An activity can have more than one target "activity is the movie added.",
/// "",
/// - Range: `Object` | `Link` "- Range: `Object` | `Link`",
/// - Functional: false "- Functional: false",
#[serde(skip_serializing_if = "Option::is_none")] ],
#[activitystreams(ab(Object, Link), concrete(String))] types [
pub target: Option<serde_json::Value>, 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 properties! {
#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)] ActorAndObjectOptOrigin {
#[serde(rename_all = "camelCase")] docs [ "Struct with `actor`, `object`, and optional `origin` properties" ],
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,
/// When used within an Activity, describes the direct object of the activity. actor {
/// docs [
/// For instance, in the activity "John added a movie to his wishlist", the object of the "Describes one or more entities that either performed or are expected to perform the",
/// activity is the movie added. "activity.",
/// "",
/// - Range: `Object` | `Link` "Any single activity can have multiple actors. The actor MAY be specified using an indirect",
/// - Functional: false "Link.",
#[activitystreams(ab(Object, Link), concrete(String))] "",
pub object: serde_json::Value, "- Range: `Object` | `Link`",
"- Functional: false",
],
types [
XsdAnyUri,
ObjectBox,
LinkBox,
],
required,
},
/// Describes an indirect object of the activity from which the activity is directed. object {
/// docs [
/// The precise meaning of the origin is the object of the English preposition "from". For "When used within an Activity, describes the direct object of the activity.",
/// instance, in the activity "John moved an item to List B from List A", the origin of the "",
/// activity is "List A". "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 "- Range: `Object` | `Link`",
#[serde(skip_serializing_if = "Option::is_none")] "- Functional: false",
#[activitystreams(ab(Object, Link), concrete(String))] ],
pub origin: Option<serde_json::Value>, 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 properties! {
#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)] ActorAndObjectOptOthers {
#[serde(rename_all = "camelCase")] docs [ "Struct with `actor`, `object`, and optional `origin` and `target` properties" ],
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,
/// When used within an Activity, describes the direct object of the activity. actor {
/// docs [
/// For instance, in the activity "John added a movie to his wishlist", the object of the "Describes one or more entities that either performed or are expected to perform the",
/// activity is the movie added. "activity.",
/// "",
/// - Range: `Object` | `Link` "Any single activity can have multiple actors. The actor MAY be specified using an indirect",
/// - Functional: false "Link.",
#[activitystreams(ab(Object, Link), concrete(String))] "",
pub object: serde_json::Value, "- Range: `Object` | `Link`",
"- Functional: false",
],
types [
XsdAnyUri,
ObjectBox,
LinkBox,
],
required,
},
/// Describes an indirect object of the activity from which the activity is directed. object {
/// docs [
/// The precise meaning of the origin is the object of the English preposition "from". For "When used within an Activity, describes the direct object of the activity.",
/// instance, in the activity "John moved an item to List B from List A", the origin of the "",
/// activity is "List A". "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 "- Range: `Object` | `Link`",
#[serde(skip_serializing_if = "Option::is_none")] "- Functional: false",
#[activitystreams(ab(Object, Link), concrete(String))] ],
pub origin: Option<serde_json::Value>, types [
XsdAnyUri,
ObjectBox,
LinkBox,
],
required,
},
/// Describes the indirect object, or target, of the activity. origin {
/// docs [
/// The precise meaning of the target is largely dependent on the type of action being "Describes an indirect object of the activity from which the activity is directed.",
/// 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 "The precise meaning of the origin is the object of the English preposition \"from\". For",
/// wishlist. An activity can have more than one target "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 "- Range: `Object` | `Link`",
#[serde(skip_serializing_if = "Option::is_none")] "- Functional: false",
#[activitystreams(ab(Object, Link), concrete(String))] ],
pub target: Option<serde_json::Value>, 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 properties! {
#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)] ActorAndOrigin {
#[serde(rename_all = "camelCase")] docs [ "Struct with `actor` and `origin` properties" ],
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,
/// Describes an indirect object of the activity from which the activity is directed. actor {
/// docs [
/// The precise meaning of the origin is the object of the English preposition "from". For "Describes one or more entities that either performed or are expected to perform the",
/// instance, in the activity "John moved an item to List B from List A", the origin of the "activity.",
/// activity is "List A". "",
/// "Any single activity can have multiple actors. The actor MAY be specified using an indirect",
/// - Range: `Object` | `Link` "Link.",
/// - Functional: false "",
#[activitystreams(ab(Object, Link), concrete(String))] "- Range: `Object` | `Link`",
pub origin: serde_json::Value, "- 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 /// Properties for the Accept activity
pub type AcceptProperties = ActorAndObject; pub type AcceptProperties = ActorAndObjectProperties;
/// Properties for the Add activity /// Properties for the Add activity
pub type AddProperties = ActorAndObject; pub type AddProperties = ActorAndObjectProperties;
/// Properties for the Move activity /// Properties for the Move activity
pub type MoveProperties = ActorAndObjectOptOthers; pub type MoveProperties = ActorAndObjectOptOthersProperties;
/// Properties for the Announce activity /// Properties for the Announce activity
pub type AnnounceProperties = ActorAndObjectOptTarget; pub type AnnounceProperties = ActorAndObjectOptTargetProperties;
/// Properties for the Arrive activity /// Properties for the Arrive activity
pub type ArriveProperties = ActorAndOrigin; pub type ArriveProperties = ActorAndOriginProperties;
/// Properties for the Block activity /// Properties for the Block activity
pub type BlockProperties = ActorAndObject; pub type BlockProperties = ActorAndObjectProperties;
/// Properties for the Create activity /// Properties for the Create activity
pub type CreateProperties = ActorAndObject; pub type CreateProperties = ActorAndObjectProperties;
/// Properties for the Delete activity /// Properties for the Delete activity
pub type DeleteProperties = ActorAndObjectOptOrigin; pub type DeleteProperties = ActorAndObjectOptOriginProperties;
/// Properties for the Dislike activity /// Properties for the Dislike activity
pub type DislikeProperties = ActorAndObject; pub type DislikeProperties = ActorAndObjectProperties;
/// Properties for the Flag activity /// Properties for the Flag activity
pub type FlagProperties = ActorAndObject; pub type FlagProperties = ActorAndObjectProperties;
/// Properties for the Follow activity /// Properties for the Follow activity
pub type FollowProperties = ActorAndObject; pub type FollowProperties = ActorAndObjectProperties;
/// Properties for the Ignore activity /// Properties for the Ignore activity
pub type IgnoreProperties = ActorAndObject; pub type IgnoreProperties = ActorAndObjectProperties;
/// Properties for the Invite activity /// Properties for the Invite activity
pub type InviteProperties = ActorObjectAndTarget; pub type InviteProperties = ActorObjectAndTargetProperties;
/// Properties for the Join activity /// Properties for the Join activity
pub type JoinProperties = ActorAndObject; pub type JoinProperties = ActorAndObjectProperties;
/// Properties for the Leave activity /// Properties for the Leave activity
pub type LeaveProperties = ActorAndObject; pub type LeaveProperties = ActorAndObjectProperties;
/// Properties for the Like activity /// Properties for the Like activity
pub type LikeProperties = ActorAndObject; pub type LikeProperties = ActorAndObjectProperties;
/// Properties for the Listen activity /// Properties for the Listen activity
pub type ListenProperties = ActorAndObject; pub type ListenProperties = ActorAndObjectProperties;
/// Properties for the Offer activity /// Properties for the Offer activity
pub type OfferProperties = ActorAndObjectOptTarget; pub type OfferProperties = ActorAndObjectOptTargetProperties;
/// Properties for the Question activity properties! {
#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)] Question {
#[serde(rename_all = "camelCase")] docs [ "Properties for the Question activity" ],
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<serde_json::Value>,
/// Identifies an inclusive option for a Question. one_of {
/// docs [
/// Use of `any_of` implies that the Question can have multiple answers. To indicate that a "Identifies an exclusive option for a Question.",
/// `Question` can have only one answer, use `one_of`. "",
/// "Use of `one_of` implies that the Question can have only a single answer. To indicate that a",
/// - Range: `Object` | `Link` "`Question` can have multiple answers, use `any_of`.",
/// - Functional: false "",
#[serde(skip_serializing_if = "Option::is_none")] "- Range: `Object` | `Link`",
#[activitystreams(ab(Object, Link), concrete(String))] "- Functional: false",
pub any_of: Option<serde_json::Value>, ],
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 /// Properties for the Read activity
pub type ReadProperties = ActorAndObject; pub type ReadProperties = ActorAndObjectProperties;
/// Properties for the Reject activity /// Properties for the Reject activity
pub type RejectProperties = ActorAndObject; pub type RejectProperties = ActorAndObjectProperties;
/// Properties for the Remove activity /// Properties for the Remove activity
pub type RemoveProperties = ActorAndObjectOptOthers; pub type RemoveProperties = ActorAndObjectOptOthersProperties;
/// Properties for the TentativeAccept activity /// Properties for the TentativeAccept activity
pub type TentativeAcceptProperties = ActorAndObject; pub type TentativeAcceptProperties = ActorAndObjectProperties;
/// Properties for the TentativeReject activity /// Properties for the TentativeReject activity
pub type TentativeRejectProperties = ActorAndObject; pub type TentativeRejectProperties = ActorAndObjectProperties;
/// Properties for the Travel activity /// Properties for the Travel activity
pub type TravelProperties = ActorOptOriginAndTarget; pub type TravelProperties = ActorOptOriginAndTargetProperties;
/// Properties for the Undo activity /// Properties for the Undo activity
pub type UndoProperties = ActorAndObject; pub type UndoProperties = ActorAndObjectProperties;
/// Properties for the Update activity /// Properties for the Update activity
pub type UpdateProperties = ActorAndObject; pub type UpdateProperties = ActorAndObjectProperties;
/// Properties for the View activity /// Properties for the View activity
pub type ViewProperties = ActorAndObject; pub type ViewProperties = ActorAndObjectProperties;

View file

@ -17,9 +17,9 @@
* along with ActivityStreams Types. If not, see <http://www.gnu.org/licenses/>. * along with ActivityStreams Types. If not, see <http://www.gnu.org/licenses/>.
*/ */
use activitystreams_derive::Properties; use activitystreams_derive::PropRefs;
use activitystreams_traits::{Activity, IntransitiveActivity, Object}; use activitystreams_traits::{Activity, IntransitiveActivity, Object};
use serde_derive::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use super::{ use super::{
kind::QuestionType, 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 /// Either of the anyOf and oneOf properties MAY be used to express possible answers, but a
/// Question object MUST NOT have both properties. /// 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")] #[serde(rename_all = "camelCase")]
pub struct Question { pub struct Question {
#[serde(rename = "type")] #[serde(rename = "type")]
@ -46,35 +46,18 @@ pub struct Question {
/// Adds all valid question properties to this struct /// Adds all valid question properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(None)]
pub question_props: QuestionProperties, pub question_props: QuestionProperties,
/// Adds all valid object properties to this struct /// Adds all valid object properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(Object)]
pub object_props: ObjectProperties, pub object_props: ObjectProperties,
/// Adds all valid activity properties to this struct /// Adds all valid activity properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(Activity)]
pub activity_props: ActivityProperties, 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 {} impl IntransitiveActivity for Question {}

View file

@ -17,9 +17,9 @@
* along with ActivityStreams Types. If not, see <http://www.gnu.org/licenses/>. * along with ActivityStreams Types. If not, see <http://www.gnu.org/licenses/>.
*/ */
use activitystreams_derive::Properties; use activitystreams_derive::PropRefs;
use activitystreams_traits::{Activity, Object}; use activitystreams_traits::{Activity, Object};
use serde_derive::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use super::{ use super::{
kind::ReadType, kind::ReadType,
@ -29,7 +29,7 @@ use super::{
use crate::object::{properties::ObjectProperties, ObjectExt}; use crate::object::{properties::ObjectProperties, ObjectExt};
/// Indicates that the actor has read the object. /// 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")] #[serde(rename_all = "camelCase")]
pub struct Read { pub struct Read {
#[serde(rename = "type")] #[serde(rename = "type")]
@ -39,34 +39,16 @@ pub struct Read {
/// Adds all valid read properties to this struct /// Adds all valid read properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(None)]
pub read_props: ReadProperties, pub read_props: ReadProperties,
/// Adds all valid object properties to this struct /// Adds all valid object properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(Object)]
pub object_props: ObjectProperties, pub object_props: ObjectProperties,
/// Adds all valid activity properties to this struct /// Adds all valid activity properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(Activity)]
pub activity_props: ActivityProperties, 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
}
}

View file

@ -17,9 +17,9 @@
* along with ActivityStreams Types. If not, see <http://www.gnu.org/licenses/>. * along with ActivityStreams Types. If not, see <http://www.gnu.org/licenses/>.
*/ */
use activitystreams_derive::Properties; use activitystreams_derive::PropRefs;
use activitystreams_traits::{Activity, Object}; use activitystreams_traits::{Activity, Object};
use serde_derive::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use super::{ use super::{
kind::RejectType, kind::RejectType,
@ -31,7 +31,7 @@ use crate::object::{properties::ObjectProperties, ObjectExt};
/// Indicates that the actor is rejecting the object. /// Indicates that the actor is rejecting the object.
/// ///
/// The target and origin typically have no defined meaning. /// 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")] #[serde(rename_all = "camelCase")]
pub struct Reject { pub struct Reject {
#[serde(rename = "type")] #[serde(rename = "type")]
@ -41,34 +41,16 @@ pub struct Reject {
/// Adds all valid reject properties to this struct /// Adds all valid reject properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(None)]
pub reject_props: RejectProperties, pub reject_props: RejectProperties,
/// Adds all valid object properties to this struct /// Adds all valid object properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(Object)]
pub object_props: ObjectProperties, pub object_props: ObjectProperties,
/// Adds all valid activity properties to this struct /// Adds all valid activity properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(Activity)]
pub activity_props: ActivityProperties, 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
}
}

View file

@ -17,9 +17,9 @@
* along with ActivityStreams Types. If not, see <http://www.gnu.org/licenses/>. * along with ActivityStreams Types. If not, see <http://www.gnu.org/licenses/>.
*/ */
use activitystreams_derive::Properties; use activitystreams_derive::PropRefs;
use activitystreams_traits::{Activity, Object}; use activitystreams_traits::{Activity, Object};
use serde_derive::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use super::{ use super::{
kind::RemoveType, kind::RemoveType,
@ -31,7 +31,7 @@ use crate::object::{properties::ObjectProperties, ObjectExt};
/// Indicates that the actor is removing the object. /// Indicates that the actor is removing the object.
/// ///
/// If specified, the origin indicates the context from which the object is being removed. /// 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")] #[serde(rename_all = "camelCase")]
pub struct Remove { pub struct Remove {
#[serde(rename = "type")] #[serde(rename = "type")]
@ -41,34 +41,16 @@ pub struct Remove {
/// Adds all valid remove properties to this struct /// Adds all valid remove properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(None)]
pub remove_props: RemoveProperties, pub remove_props: RemoveProperties,
/// Adds all valid object properties to this struct /// Adds all valid object properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(Object)]
pub object_props: ObjectProperties, pub object_props: ObjectProperties,
/// Adds all valid activity properties to this struct /// Adds all valid activity properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(Activity)]
pub activity_props: ActivityProperties, 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
}
}

View file

@ -17,9 +17,9 @@
* along with ActivityStreams Types. If not, see <http://www.gnu.org/licenses/>. * along with ActivityStreams Types. If not, see <http://www.gnu.org/licenses/>.
*/ */
use activitystreams_derive::Properties; use activitystreams_derive::PropRefs;
use activitystreams_traits::{Activity, Object}; use activitystreams_traits::{Activity, Object};
use serde_derive::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use super::{ use super::{
kind::TentativeAcceptType, kind::TentativeAcceptType,
@ -29,7 +29,7 @@ use super::{
use crate::object::{properties::ObjectProperties, ObjectExt}; use crate::object::{properties::ObjectProperties, ObjectExt};
/// A specialization of Accept indicating that the acceptance is tentative. /// 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")] #[serde(rename_all = "camelCase")]
pub struct TentativeAccept { pub struct TentativeAccept {
#[serde(rename = "type")] #[serde(rename = "type")]
@ -39,34 +39,16 @@ pub struct TentativeAccept {
/// Adds all valid tentative_accept properties to this struct /// Adds all valid tentative_accept properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(None)]
pub tentative_accept_props: TentativeAcceptProperties, pub tentative_accept_props: TentativeAcceptProperties,
/// Adds all valid object properties to this struct /// Adds all valid object properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(Object)]
pub object_props: ObjectProperties, pub object_props: ObjectProperties,
/// Adds all valid activity properties to this struct /// Adds all valid activity properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(Activity)]
pub activity_props: ActivityProperties, 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
}
}

View file

@ -17,9 +17,9 @@
* along with ActivityStreams Types. If not, see <http://www.gnu.org/licenses/>. * along with ActivityStreams Types. If not, see <http://www.gnu.org/licenses/>.
*/ */
use activitystreams_derive::Properties; use activitystreams_derive::PropRefs;
use activitystreams_traits::{Activity, Object}; use activitystreams_traits::{Activity, Object};
use serde_derive::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use super::{ use super::{
kind::TentativeRejectType, kind::TentativeRejectType,
@ -29,7 +29,7 @@ use super::{
use crate::object::{properties::ObjectProperties, ObjectExt}; use crate::object::{properties::ObjectProperties, ObjectExt};
/// A specialization of Reject in which the rejection is considered tentative. /// 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")] #[serde(rename_all = "camelCase")]
pub struct TentativeReject { pub struct TentativeReject {
#[serde(rename = "type")] #[serde(rename = "type")]
@ -39,34 +39,16 @@ pub struct TentativeReject {
/// Adds all valid tentative_reject properties to this struct /// Adds all valid tentative_reject properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(None)]
pub tentative_reject_props: TentativeRejectProperties, pub tentative_reject_props: TentativeRejectProperties,
/// Adds all valid object properties to this struct /// Adds all valid object properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(Object)]
pub object_props: ObjectProperties, pub object_props: ObjectProperties,
/// Adds all valid activity properties to this struct /// Adds all valid activity properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(Activity)]
pub activity_props: ActivityProperties, 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
}
}

View file

@ -17,9 +17,9 @@
* along with ActivityStreams Types. If not, see <http://www.gnu.org/licenses/>. * along with ActivityStreams Types. If not, see <http://www.gnu.org/licenses/>.
*/ */
use activitystreams_derive::Properties; use activitystreams_derive::PropRefs;
use activitystreams_traits::{Activity, IntransitiveActivity, Object}; use activitystreams_traits::{Activity, IntransitiveActivity, Object};
use serde_derive::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use super::{ use super::{
kind::TravelType, 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 /// Travel is an IntransitiveObject whose actor specifies the direct object. If the target or
/// origin are not specified, either can be determined by context. /// 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")] #[serde(rename_all = "camelCase")]
pub struct Travel { pub struct Travel {
#[serde(rename = "type")] #[serde(rename = "type")]
@ -42,35 +42,18 @@ pub struct Travel {
/// Adds all valid travel properties to this struct /// Adds all valid travel properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(None)]
pub travel_props: TravelProperties, pub travel_props: TravelProperties,
/// Adds all valid object properties to this struct /// Adds all valid object properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(Object)]
pub object_props: ObjectProperties, pub object_props: ObjectProperties,
/// Adds all valid activity properties to this struct /// Adds all valid activity properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(Activity)]
pub activity_props: ActivityProperties, 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 {} impl IntransitiveActivity for Travel {}

View file

@ -17,9 +17,9 @@
* along with ActivityStreams Types. If not, see <http://www.gnu.org/licenses/>. * along with ActivityStreams Types. If not, see <http://www.gnu.org/licenses/>.
*/ */
use activitystreams_derive::Properties; use activitystreams_derive::PropRefs;
use activitystreams_traits::{Activity, Object}; use activitystreams_traits::{Activity, Object};
use serde_derive::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use super::{ use super::{
kind::UndoType, kind::UndoType,
@ -35,7 +35,7 @@ use crate::object::{properties::ObjectProperties, ObjectExt};
/// choose to undo that like at some later point in time). /// choose to undo that like at some later point in time).
/// ///
/// The target and origin typically have no defined meaning. /// 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")] #[serde(rename_all = "camelCase")]
pub struct Undo { pub struct Undo {
#[serde(rename = "type")] #[serde(rename = "type")]
@ -45,34 +45,16 @@ pub struct Undo {
/// Adds all valid undo properties to this struct /// Adds all valid undo properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(None)]
pub undo_props: UndoProperties, pub undo_props: UndoProperties,
/// Adds all valid object properties to this struct /// Adds all valid object properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(Object)]
pub object_props: ObjectProperties, pub object_props: ObjectProperties,
/// Adds all valid activity properties to this struct /// Adds all valid activity properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(Activity)]
pub activity_props: ActivityProperties, 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
}
}

View file

@ -17,9 +17,9 @@
* along with ActivityStreams Types. If not, see <http://www.gnu.org/licenses/>. * along with ActivityStreams Types. If not, see <http://www.gnu.org/licenses/>.
*/ */
use activitystreams_derive::Properties; use activitystreams_derive::PropRefs;
use activitystreams_traits::{Activity, Object}; use activitystreams_traits::{Activity, Object};
use serde_derive::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use super::{ use super::{
kind::UpdateType, kind::UpdateType,
@ -34,7 +34,7 @@ use crate::object::{properties::ObjectProperties, ObjectExt};
/// of modifications made to object. /// of modifications made to object.
/// ///
/// The target and origin typically have no defined meaning. /// 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")] #[serde(rename_all = "camelCase")]
pub struct Update { pub struct Update {
#[serde(rename = "type")] #[serde(rename = "type")]
@ -44,34 +44,16 @@ pub struct Update {
/// Adds all valid update properties to this struct /// Adds all valid update properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(None)]
pub update_props: UpdateProperties, pub update_props: UpdateProperties,
/// Adds all valid object properties to this struct /// Adds all valid object properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(Object)]
pub object_props: ObjectProperties, pub object_props: ObjectProperties,
/// Adds all valid activity properties to this struct /// Adds all valid activity properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(Activity)]
pub activity_props: ActivityProperties, 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
}
}

View file

@ -17,9 +17,9 @@
* along with ActivityStreams Types. If not, see <http://www.gnu.org/licenses/>. * along with ActivityStreams Types. If not, see <http://www.gnu.org/licenses/>.
*/ */
use activitystreams_derive::Properties; use activitystreams_derive::PropRefs;
use activitystreams_traits::{Activity, Object}; use activitystreams_traits::{Activity, Object};
use serde_derive::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use super::{ use super::{
kind::ViewType, kind::ViewType,
@ -29,7 +29,7 @@ use super::{
use crate::object::{properties::ObjectProperties, ObjectExt}; use crate::object::{properties::ObjectProperties, ObjectExt};
/// Indicates that the actor has viewed the object. /// 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")] #[serde(rename_all = "camelCase")]
pub struct View { pub struct View {
#[serde(rename = "type")] #[serde(rename = "type")]
@ -39,34 +39,16 @@ pub struct View {
/// Adds all valid view properties to this struct /// Adds all valid view properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(None)]
pub view_props: ViewProperties, pub view_props: ViewProperties,
/// Adds all valid object properties to this struct /// Adds all valid object properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(Object)]
pub object_props: ObjectProperties, pub object_props: ObjectProperties,
/// Adds all valid activity properties to this struct /// Adds all valid activity properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(Activity)]
pub activity_props: ActivityProperties, 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
}
}

View file

@ -19,8 +19,9 @@
//! Namespace for Actor types //! Namespace for Actor types
use activitystreams_derive::PropRefs;
use activitystreams_traits::{Actor, Object}; use activitystreams_traits::{Actor, Object};
use serde_derive::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::object::{properties::ObjectProperties, ObjectExt}; use crate::object::{properties::ObjectProperties, ObjectExt};
@ -28,7 +29,7 @@ pub mod kind;
use self::kind::*; use self::kind::*;
/// Describes a software application. /// Describes a software application.
#[derive(Clone, Debug, Default, Deserialize, Serialize)] #[derive(Clone, Debug, Default, Deserialize, PropRefs, Serialize)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct Application { pub struct Application {
#[serde(rename = "type")] #[serde(rename = "type")]
@ -38,23 +39,14 @@ pub struct Application {
/// Adds all valid object properties to this struct /// Adds all valid object properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(Object)]
pub object_props: ObjectProperties, 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 {} impl Actor for Application {}
/// Represents a formal or informal collective of Actors. /// 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")] #[serde(rename_all = "camelCase")]
pub struct Group { pub struct Group {
#[serde(rename = "type")] #[serde(rename = "type")]
@ -64,23 +56,14 @@ pub struct Group {
/// Adds all valid object properties to this struct /// Adds all valid object properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(Object)]
pub object_props: ObjectProperties, 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 {} impl Actor for Group {}
/// Represents an organization. /// Represents an organization.
#[derive(Clone, Debug, Default, Deserialize, Serialize)] #[derive(Clone, Debug, Default, Deserialize, PropRefs, Serialize)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct Organization { pub struct Organization {
#[serde(rename = "type")] #[serde(rename = "type")]
@ -90,23 +73,14 @@ pub struct Organization {
/// Adds all valid object properties to this struct /// Adds all valid object properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(Object)]
pub object_props: ObjectProperties, 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 {} impl Actor for Organization {}
/// Represents an individual person. /// Represents an individual person.
#[derive(Clone, Debug, Default, Deserialize, Serialize)] #[derive(Clone, Debug, Default, Deserialize, PropRefs, Serialize)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct Person { pub struct Person {
#[serde(rename = "type")] #[serde(rename = "type")]
@ -116,23 +90,14 @@ pub struct Person {
/// Adds all valid object properties to this struct /// Adds all valid object properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(Object)]
pub object_props: ObjectProperties, 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 {} impl Actor for Person {}
/// Represents a service of any kind. /// Represents a service of any kind.
#[derive(Clone, Debug, Default, Deserialize, Serialize)] #[derive(Clone, Debug, Default, Deserialize, PropRefs, Serialize)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct Service { pub struct Service {
#[serde(rename = "type")] #[serde(rename = "type")]
@ -142,17 +107,8 @@ pub struct Service {
/// Adds all valid object properties to this struct /// Adds all valid object properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(Object)]
pub object_props: ObjectProperties, 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 {} impl Actor for Service {}

View file

@ -19,9 +19,9 @@
//! Namespace for Collection types //! Namespace for Collection types
use activitystreams_derive::Properties; use activitystreams_derive::PropRefs;
use activitystreams_traits::{Collection, CollectionPage, Object}; use activitystreams_traits::{Collection, CollectionPage, Object};
use serde_derive::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::object::{properties::ObjectProperties, ObjectExt}; use crate::object::{properties::ObjectProperties, ObjectExt};
@ -46,8 +46,16 @@ pub trait CollectionPageExt: CollectionPage {
fn props_mut(&mut self) -> &mut CollectionPageProperties; fn props_mut(&mut self) -> &mut CollectionPageProperties;
} }
#[derive(Debug, Deserialize, Serialize)]
#[serde(transparent)]
pub struct CollectionBox(pub Box<dyn Object>);
#[derive(Debug, Deserialize, Serialize)]
#[serde(transparent)]
pub struct CollectionPageBox(pub Box<dyn Object>);
/// The default `Collection` type. /// The default `Collection` type.
#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)] #[derive(Clone, Debug, Default, Deserialize, PropRefs, Serialize)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct UnorderedCollection { pub struct UnorderedCollection {
#[serde(rename = "type")] #[serde(rename = "type")]
@ -57,37 +65,18 @@ pub struct UnorderedCollection {
/// Adds all valid object properties to this struct /// Adds all valid object properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(Object)]
pub object_props: ObjectProperties, pub object_props: ObjectProperties,
/// Adds all valid collection properties to this struct /// Adds all valid collection properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(Collection)]
pub collection_props: CollectionProperties, 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 /// A subtype of `Collection` in which members of the logical collection are assumed to always be
/// strictly ordered. /// strictly ordered.
#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)] #[derive(Clone, Debug, Default, Deserialize, PropRefs, Serialize)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct OrderedCollection { pub struct OrderedCollection {
#[serde(rename = "type")] #[serde(rename = "type")]
@ -97,36 +86,17 @@ pub struct OrderedCollection {
/// Adds all valid object properties to this struct /// Adds all valid object properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(Object)]
pub object_props: ObjectProperties, pub object_props: ObjectProperties,
/// Adds all valid collection properties to this struct /// Adds all valid collection properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(Collection)]
pub collection_props: CollectionProperties, 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`. /// 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")] #[serde(rename_all = "camelCase")]
pub struct UnorderedCollectionPage { pub struct UnorderedCollectionPage {
#[serde(rename = "type")] #[serde(rename = "type")]
@ -136,50 +106,22 @@ pub struct UnorderedCollectionPage {
/// Adds all valid object properties to this struct /// Adds all valid object properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(Object)]
pub object_props: ObjectProperties, pub object_props: ObjectProperties,
/// Adds all valid collection properties to this struct /// Adds all valid collection properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(Collection)]
pub collection_props: CollectionProperties, pub collection_props: CollectionProperties,
/// Adds all valid collection page properties to this struct /// Adds all valid collection page properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(CollectionPage)]
pub collection_page_props: CollectionPageProperties, 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`. /// 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")] #[serde(rename_all = "camelCase")]
pub struct OrderedCollectionPage { pub struct OrderedCollectionPage {
#[serde(rename = "type")] #[serde(rename = "type")]
@ -189,48 +131,97 @@ pub struct OrderedCollectionPage {
/// Adds all valid object properties to this struct /// Adds all valid object properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(Object)]
pub object_props: ObjectProperties, pub object_props: ObjectProperties,
/// Adds all valid collection properties to this struct /// Adds all valid collection properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(Collection)]
pub collection_props: CollectionProperties, pub collection_props: CollectionProperties,
/// Adds all valid collection page properties to this struct /// Adds all valid collection page properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(CollectionPage)]
pub collection_page_props: CollectionPageProperties, pub collection_page_props: CollectionPageProperties,
/// Adds all valid ordered collection page properties to this struct /// Adds all valid ordered collection page properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(None)]
pub ordered_collection_page_props: OrderedCollectionPageProperties, pub ordered_collection_page_props: OrderedCollectionPageProperties,
} }
impl Object for OrderedCollectionPage {} impl CollectionBox {
impl ObjectExt for OrderedCollectionPage { pub fn is<T>(&self) -> bool
fn props(&self) -> &ObjectProperties { where
&self.object_props T: Collection + 'static,
{
self.0.as_any().is::<T>()
} }
fn props_mut(&mut self) -> &mut ObjectProperties { pub fn downcast_ref<T>(&self) -> Option<&T>
&mut self.object_props where
} T: Collection + 'static,
} {
impl Collection for OrderedCollectionPage {} self.0.as_any().downcast_ref()
impl CollectionExt for OrderedCollectionPage {
fn props(&self) -> &CollectionProperties {
&self.collection_props
} }
fn props_mut(&mut self) -> &mut CollectionProperties { pub fn downcast_mut<T>(&mut self) -> Option<&mut T>
&mut self.collection_props where
T: Collection + 'static,
{
self.0.as_any_mut().downcast_mut()
} }
} }
impl CollectionPage for OrderedCollectionPage {}
impl CollectionPageExt for OrderedCollectionPage { impl CollectionPageBox {
fn props(&self) -> &CollectionPageProperties { pub fn is<T>(&self) -> bool
&self.collection_page_props where
T: CollectionPage + 'static,
{
self.0.as_any().is::<T>()
} }
fn props_mut(&mut self) -> &mut CollectionPageProperties { pub fn downcast_ref<T>(&self) -> Option<&T>
&mut self.collection_page_props where
T: CollectionPage + 'static,
{
self.0.as_any().downcast_ref()
}
pub fn downcast_mut<T>(&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<T> From<T> for CollectionBox
where
T: Collection + 'static,
{
fn from(t: T) -> Self {
CollectionBox(Box::new(t))
}
}
impl<T> From<T> for CollectionPageBox
where
T: CollectionPage + 'static,
{
fn from(t: T) -> Self {
CollectionPageBox(Box::new(t))
} }
} }

View file

@ -27,15 +27,15 @@
//! collection::properties::CollectionProperties, //! collection::properties::CollectionProperties,
//! object::properties::ObjectProperties, //! 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")] //! #[serde(rename_all = "camelCase")]
//! pub struct MyCollection { //! pub struct MyCollection {
//! #[serde(rename = "type")] //! #[serde(rename = "type")]
//! pub kind: String, //! pub kind: String,
//! //!
//! /// Define a require property for the MyCollection type //! docs("Define a require property for the MyCollection type"),
//! pub my_property: String, //! pub my_property: String,
//! //!
//! #[serde(flatten)] //! #[serde(flatten)]
@ -51,105 +51,173 @@
//! # fn main() {} //! # fn main() {}
//! ``` //! ```
use activitystreams_derive::Properties; use crate::{
use activitystreams_traits::{Collection, CollectionPage, Link, Object}; collection::{CollectionBox, CollectionPageBox},
use serde_derive::{Deserialize, Serialize}; link::LinkBox,
object::ObjectBox,
primitives::*,
};
use activitystreams_derive::properties;
/// `Collection` objects are a specialization of the base `Object` that serve as a container for properties! {
/// other `Objects` or `Links`. Collection {
/// docs [
/// The items within a `Collection` can be ordered or unordered. The `OrderedCollection` type MAY be "`Collection` objects are a specialization of the base `Object` that serve as a container for",
/// used to identify a `Collection` whose items are always ordered. In the JSON serialization, the "other `Objects` or `Links`.",
/// unordered items of a `Collection` are represented using the `items` property while ordered items "",
/// are represented using the `ordered_items` property. "The items within a `Collection` can be ordered or unordered. The `OrderedCollection` type MAY be",
#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)] "used to identify a `Collection` whose items are always ordered. In the JSON serialization, the",
#[serde(rename_all = "camelCase")] "unordered items of a `Collection` are represented using the `items` property while ordered items",
pub struct CollectionProperties { "are represented using the `ordered_items` property.",
/// 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,
/// A non-negative integer specifying the total number of objects contained by the logical view items {
/// of the collection. docs [
/// "Identifies the items contained in a collection. The items might be ordered or unordered.",
/// This number might not reflect the actual number of items serialized within the `Collection` "",
/// object instance. "- Range: `Object` | `Link` | Ordered List of [ `Object` | `Link` ]",
/// "- Functional: false",
/// - Range: `xsd:nonNegativeInteger` ],
/// - Functional: true types [
#[serde(skip_serializing_if = "Option::is_none")] XsdString,
#[activitystreams(concrete(u64), functional)] ObjectBox,
pub total_items: Option<serde_json::Value>, LinkBox,
],
required,
},
/// In a paged `Collection`, indicates the page that contains the most recently updated member total_items {
/// items. docs [
/// "A non-negative integer specifying the total number of objects contained by the logical view",
/// - Range: `CollectionPage` | `Link` "of the collection.",
/// - Functional: true "",
#[serde(skip_serializing_if = "Option::is_none")] "This number might not reflect the actual number of items serialized within the `Collection`",
#[activitystreams(ab(Link, CollectionPage), concrete(String), functional)] "object instance.",
pub current: Option<serde_json::Value>, "",
"- Range: `xsd:nonNegativeInteger`",
"- Functional: true",
],
types [
XsdNonNegativeInteger,
],
functional,
},
/// In a paged `Collection`, indicates the furthest preceeding page of items in the collection. current {
/// docs [
/// - Range: `CollectionPage` | `Link` "In a paged `Collection`, indicates the page that contains the most recently updated member",
/// - Functional: true "items.",
#[serde(skip_serializing_if = "Option::is_none")] "",
#[activitystreams(ab(Link, CollectionPage), concrete(String), functional)] "- Range: `CollectionPage` | `Link`",
pub first: Option<serde_json::Value>, "- Functional: true",
],
types [
XsdAnyUri,
LinkBox,
CollectionPageBox,
],
functional,
},
/// In a paged `Collection`, indicates the furthest proceeding page of the collection. first {
/// docs [
/// - Range: `CollectionPage` | `Link` "In a paged `Collection`, indicates the furthest preceeding page of items in the collection.",
/// - Functional: true "",
#[serde(skip_serializing_if = "Option::is_none")] "- Range: `CollectionPage` | `Link`",
#[activitystreams(ab(Link, CollectionPage), concrete(String), functional)] "- Functional: true",
pub last: Option<serde_json::Value>, ],
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! {
/// properties. CollectionPage {
#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)] docs [
#[serde(rename_all = "camelCase")] "The `CollectionPage` type extends from the base `Collection` type and inherits all of it's",
pub struct CollectionPageProperties { "properties.",
/// 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<serde_json::Value>,
/// In a paged `Collection`, indicates the next page of items. part_of {
/// docs [
/// - Range: `CollectionPage` | `Link` "Identifies the `Collection` to which a `CollectionPage` objects items belong.",
/// - Functional: true "",
#[serde(skip_serializing_if = "Option::is_none")] "Range: `Collection` | `Link`",
#[activitystreams(ab(Link, CollectionPage), concrete(String), functional)] "Functional: true",
pub next: Option<serde_json::Value>, ],
types [
XsdAnyUri,
LinkBox,
CollectionBox,
],
functional,
},
/// In a paged `Collection`, identifies the previous page of items. next {
/// docs [
/// - Range: `CollectionPage` | `Link` "In a paged `Collection`, indicates the next page of items.",
/// - Functional: true "",
#[serde(skip_serializing_if = "Option::is_none")] "- Range: `CollectionPage` | `Link`",
#[activitystreams(ab(Link, CollectionPage), concrete(String), functional)] "- Functional: true",
pub prev: Option<serde_json::Value>, ],
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. properties! {
#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)] OrderedCollectionPage {
#[serde(rename_all = "camelCase")] docs ["The OrderedCollectionPage type MAY be used to identify a page whose items are strictly ordered." ],
pub struct OrderedCollectionPageProperties { start_index {
/// A non-negative integer value identifying the relative position within the logical view of a docs ["A non-negative integer value identifying the relative position within the logical view of a",
/// strictly ordered collection. "strictly ordered collection.",
/// "",
/// - Range: `xsd:nonNegativeInteger` "- Range: `xsd:nonNegativeInteger`",
/// - Functional: true "- Functional: true",
#[serde(skip_serializing_if = "Option::is_none")] ],
#[activitystreams(concrete(u64), functional)] types [
pub start_index: Option<serde_json::Value>, XsdNonNegativeInteger,
],
functional,
},
}
} }

View file

@ -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 <http://www.gnu.org/licenses/>.
*/
//! 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<C, L> {
#[serde(flatten)]
pub link: L,
#[serde(flatten)]
pub custom_props: C,
}
impl<C, L: Link> CustomLink<C, L> {
pub fn new(link: L, custom_props: C) -> Self {
CustomLink { link, custom_props }
}
}
impl<C, L> Link for CustomLink<C, L>
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<C, O> {
#[serde(flatten)]
pub object: O,
#[serde(flatten)]
pub custom_props: C,
}
impl<C, O: Object> CustomObject<C, O> {
pub fn new(object: O, custom_props: C) -> Self {
CustomObject {
object,
custom_props,
}
}
}
impl<C, O> Object for CustomObject<C, O>
where
C: DeserializeOwned + ser::Serialize,
O: Object,
{
}
impl<C, O> Actor for CustomObject<C, O>
where
C: DeserializeOwned + ser::Serialize,
O: Actor,
{
}
impl<C, O> Collection for CustomObject<C, O>
where
C: DeserializeOwned + ser::Serialize,
O: Collection,
{
}
impl<C, O> CollectionPage for CustomObject<C, O>
where
C: DeserializeOwned + ser::Serialize,
O: CollectionPage,
{
}
impl<C, O> Activity for CustomObject<C, O>
where
C: DeserializeOwned + ser::Serialize,
O: Activity,
{
}
impl<C, O> IntransitiveActivity for CustomObject<C, O>
where
C: DeserializeOwned + ser::Serialize,
O: IntransitiveActivity,
{
}

View file

@ -28,7 +28,7 @@
//! fn run() -> Result<(), anyhow::Error> { //! fn run() -> Result<(), anyhow::Error> {
//! /// A Mention is the only predefined Link type in the Activity Streams spec //! /// A Mention is the only predefined Link type in the Activity Streams spec
//! let mut mention = Mention::default(); //! 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)?; //! 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. /// The context associated with all of the Activity Streams types defined in the crate.
pub fn context() -> ContextObject { pub fn context() -> crate::primitives::XsdAnyUri {
ContextObject("https://www.w3.org/ns/activitystreams".to_owned()) "https://www.w3.org/ns/activitystreams".parse().unwrap()
} }
pub mod activity; pub mod activity;
pub mod actor; pub mod actor;
pub mod collection; pub mod collection;
mod custom_props;
pub mod link; pub mod link;
pub mod object; pub mod object;
pub mod primitives; pub mod primitives;
pub use self::custom_props::{CustomLink, CustomObject};

View file

@ -19,8 +19,9 @@
//! Namespace for Link types //! Namespace for Link types
use activitystreams_derive::PropRefs;
use activitystreams_traits::Link; use activitystreams_traits::Link;
use serde_derive::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
pub mod kind; pub mod kind;
pub mod properties; pub mod properties;
@ -35,8 +36,12 @@ pub trait LinkExt: Link {
fn props_mut(&mut self) -> &mut LinkProperties; fn props_mut(&mut self) -> &mut LinkProperties;
} }
#[derive(Debug, Deserialize, Serialize)]
#[serde(transparent)]
pub struct LinkBox(pub Box<dyn Link>);
/// A specialized Link that represents an @mention. /// A specialized Link that represents an @mention.
#[derive(Clone, Debug, Default, Deserialize, Serialize)] #[derive(Clone, Debug, Default, Deserialize, PropRefs, Serialize)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct Mention { pub struct Mention {
#[serde(rename = "type")] #[serde(rename = "type")]
@ -46,58 +51,42 @@ pub struct Mention {
/// Adds all valid link properties to this struct /// Adds all valid link properties to this struct
#[serde(flatten)] #[serde(flatten)]
#[activitystreams(Link)]
pub link_props: LinkProperties, 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<dyn Link>);
impl LinkBox { impl LinkBox {
pub fn is<T>(&self) -> bool pub fn is<T>(&self) -> bool
where where
T: Link, T: Link + 'static,
{ {
self.0.as_any().is::<T>() self.0.as_any().is::<T>()
} }
pub fn downcast_ref<T>(&self) -> Option<&T> pub fn downcast_ref<T>(&self) -> Option<&T>
where where
T: Link, T: Link + 'static,
{ {
self.0.as_any().downcast_ref() self.0.as_any().downcast_ref()
} }
pub fn downcast_mut<T>(&mut self) -> Option<&mut T> pub fn downcast_mut<T>(&mut self) -> Option<&mut T>
where where
T: Link, T: Link + 'static,
{ {
self.0.as_any_mut().downcast_mut() self.0.as_any_mut().downcast_mut()
} }
}
pub fn downcast<T>(self) -> Option<T> impl Clone for LinkBox {
where fn clone(&self) -> Self {
T: Link, LinkBox(self.0.duplicate())
{
let any: Box<dyn Any> = self;
any.downcast()
} }
} }
impl<T> From<T> for LinkBox impl<T> From<T> for LinkBox
where where
T: Link, T: Link + 'static,
{ {
fn from(t: T) -> Self { fn from(t: T) -> Self {
LinkBox(Box::new(t)) LinkBox(Box::new(t))

View file

@ -24,7 +24,7 @@
//! ```rust //! ```rust
//! use activitystreams_traits::Link; //! use activitystreams_traits::Link;
//! use activitystreams_types::link::properties::LinkProperties; //! use activitystreams_types::link::properties::LinkProperties;
//! use serde_derive::{Deserialize, Serialize}; //! use serde::{Deserialize, Serialize};
//! //!
//! #[derive(Clone, Debug, Serialize, Deserialize)] //! #[derive(Clone, Debug, Serialize, Deserialize)]
//! #[serde(rename_all = "camelCase")] //! #[serde(rename_all = "camelCase")]
@ -44,145 +44,185 @@
//! # fn main() {} //! # fn main() {}
//! ``` //! ```
use activitystreams_derive::Properties; use activitystreams_derive::properties;
use activitystreams_traits::{Error, Link, Object, Result};
use serde_derive::{Deserialize, Serialize};
/// Define all the properties of the Object base type as described by the Activity Streams use crate::{link::LinkBox, object::ObjectBox, primitives::*};
/// 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<serde_json::Value>,
/// Identifies the context within which the object exists or an activity was performed. properties! {
/// Link {
/// The notion of "context" used is intentionally vague. The intended function is to serve as a docs [
/// means of grouping objects and activities that share a common originating context or purpose. "Define all the properties of the Object base type as described by the Activity Streams vocabulary.",
/// An example could be all activities relating to a common project or event. "",
/// "The properties of the `Link` object are not the properties of the referenced resource, but are",
/// - Range: `Object` | `Link` "provided as hints for rendering agents to understand how to make use of the resource. For",
/// - Functional: false "example, height and width might represent the desired rendered size of a referenced image,",
#[serde(skip_serializing_if = "Option::is_none", rename = "@context")] "rather than the actual pixel dimensions of the referenced image.",
#[activitystreams(ab(Object, Link), concrete(String))] "",
pub context: Option<serde_json::Value>, "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 context {
/// A simple, human-readable, plain-text name for the object. docs [
/// "Identifies the context within which the object exists or an activity was performed.",
/// HTML markup MUST NOT be included. The name MAY be expressed using multiple language-tagged "",
/// values. "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.",
/// - Range: `xsd:string` | `rdf:langString` "An example could be all activities relating to a common project or event.",
/// - Functional: false "",
#[serde(skip_serializing_if = "Option::is_none")] "- Range: `Object` | `Link`",
#[activitystreams(concrete(String))] "- Functional: false",
pub name: Option<serde_json::Value>, ],
types [
XsdAnyUri,
ObjectBox,
LinkBox,
],
rename("@context"),
},
/// The target resource pointed to by a Link. name {
/// docs [
/// - Range: `xsd:anyUri` "A simple, human-readable, plain-text name for the object.",
/// - Functional: true "",
#[serde(skip_serializing_if = "Option::is_none")] "HTML markup MUST NOT be included. The name MAY be expressed using multiple language-tagged",
#[activitystreams(concrete(String), functional)] "values.",
pub href: Option<serde_json::Value>, "",
"- Range: `xsd:string` | `rdf:langString`",
"- Functional: false",
],
types [
XsdString,
RdfLangString,
],
},
// TODO: lang enum href {
/// Hints as to the language used by the target resource. docs [
/// "The target resource pointed to by a Link.",
/// Value MUST be a [[BCP47](https://tools.ietf.org/html/bcp47)] "",
/// Language-Tag. "- Range: `xsd:anyUri`",
/// "- Functional: true",
/// - Range: [[BCP47](https://tools.ietf.org/html/bcp47)] Language ],
/// Tag types [
/// - Functional: true XsdAnyUri,
#[serde(skip_serializing_if = "Option::is_none")] ],
#[activitystreams(concrete(String), functional)] functional,
pub hreflang: Option<serde_json::Value>, },
/// When used on a `Link`, identifies the MIME media type of the referenced resource. hreflang {
/// docs [
/// If not specified, the content property is assumed to contain text/html content. "Hints as to the language used by the target resource.",
/// "",
/// - Range: `Mime Media Type` "Value MUST be a [[BCP47](https://tools.ietf.org/html/bcp47)]",
/// - Functional: true "Language-Tag.",
#[serde(skip_serializing_if = "Option::is_none")] "",
#[activitystreams(concrete(String), functional)] "- Range: [[BCP47](https://tools.ietf.org/html/bcp47)] Language",
pub media_type: Option<serde_json::Value>, "Tag",
"- Functional: true",
],
types [
XsdString,
],
functional,
},
/// A link relation associated with a Link. media_type {
/// docs [
/// The value MUST conform to both the "When used on a `Link`, identifies the MIME media type of the referenced resource.",
/// [[HTML5](https://www.w3.org/TR/html5/)] and [[RFC5988](https://tools.ietf.org/html/rfc5988)] "",
/// "link relation" definitions. "If not specified, the content property is assumed to contain text/html content.",
/// "",
/// In the [[HTML5](https://www.w3.org/TR/html5/)], any string "- Range: `Mime Media Type`",
/// not containing the "space" U+0020, "tab" (U+0009), "LF" (U+000A), "FF" (U+000C), "CR" "- Functional: true",
/// (U+000D) or "," (U+002C) characters can be used as a valid link relation. ],
/// types [
/// - Range: MimeMediaType,
/// [[RFC5988](https://tools.ietf.org/html/rfc5988)] or ],
/// [[HTML5](https://www.w3.org/TR/html5/)] Link Relation functional,
/// - Functional: false },
#[serde(skip_serializing_if = "Option::is_none")]
#[activitystreams(concrete(String))]
pub rel: Option<serde_json::Value>,
/// On a `Link`, specifies a hint as to the rendering height in device-independent pixels of the rel {
/// linked resource. docs [
/// "A link relation associated with a Link.",
/// - Range: `xsd:nonNegativeInteger` "",
/// - Functional: true "The value MUST conform to both the",
#[serde(skip_serializing_if = "Option::is_none")] "[[HTML5](https://www.w3.org/TR/html5/)] and [[RFC5988](https://tools.ietf.org/html/rfc5988)]",
#[activitystreams(concrete(u64), functional)] "\"link relation\" definitions.",
pub height: Option<serde_json::Value>, "",
"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 height {
/// linked resource. 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 "- Range: `xsd:nonNegativeInteger`",
#[serde(skip_serializing_if = "Option::is_none")] "- Functional: true",
#[activitystreams(concrete(u64), functional)] ],
pub width: Option<serde_json::Value>, types [
XsdNonNegativeInteger,
],
functional,
},
/// Identifies an entity that provides a preview of this object. width {
/// docs [
/// - Range: `Object` | `Link` "On a `Link`, specifies a hint as to the rendering width in device-independent pixels of the",
/// - Functional: false "linked resource.",
#[serde(skip_serializing_if = "Option::is_none")] "",
#[activitystreams(ab(Object, Link), concrete(String))] "- Range: `xsd:nonNegativeInteger`",
pub preview: Option<serde_json::Value>, "- Functional: true",
} ],
types [
XsdNonNegativeInteger,
],
},
impl LinkProperties { preview {
/// Fetch a typed `Mime` struct from the `media_type` field. docs [
pub fn media_type(&self) -> Result<mime::Mime> { "Identifies an entity that provides a preview of this object.",
self.media_type_string() "",
.and_then(|s| s.parse().map_err(|_| Error::Deserialize)) "- Range: `Object` | `Link`",
"- Functional: false",
],
types [
XsdAnyUri,
ObjectBox,
LinkBox,
],
},
} }
} }

View file

@ -19,9 +19,9 @@
//! Namespace for Object types //! Namespace for Object types
use activitystreams_derive::{PropRefs, Properties}; use activitystreams_derive::PropRefs;
use activitystreams_traits::Object; use activitystreams_traits::Object;
use serde_derive::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
pub mod kind; pub mod kind;
pub mod properties; pub mod properties;
@ -36,6 +36,14 @@ pub trait ObjectExt: Object {
fn props_mut(&mut self) -> &mut ObjectProperties; fn props_mut(&mut self) -> &mut ObjectProperties;
} }
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(transparent)]
pub struct ImageBox(pub Box<Image>);
#[derive(Debug, Deserialize, Serialize)]
#[serde(transparent)]
pub struct ObjectBox(pub Box<dyn Object>);
/// Represents any kind of multi-paragraph written work. /// Represents any kind of multi-paragraph written work.
#[derive(Clone, Debug, Default, Deserialize, PropRefs, Serialize)] #[derive(Clone, Debug, Default, Deserialize, PropRefs, Serialize)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
@ -272,43 +280,27 @@ pub struct Video {
pub object_props: ObjectProperties, pub object_props: ObjectProperties,
} }
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(transparent)]
pub struct ImageBox(pub Box<Image>);
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(transparent)]
pub struct ObjectBox(pub Box<dyn Object>);
impl ObjectBox { impl ObjectBox {
pub fn is<T>(&self) -> bool pub fn is<T>(&self) -> bool
where where
T: Object, T: Object + 'static,
{ {
self.0.as_any().is::<T>() self.0.as_any().is::<T>()
} }
pub fn downcast_ref<T>(&self) -> Option<&T> pub fn downcast_ref<T>(&self) -> Option<&T>
where where
T: Object, T: Object + 'static,
{ {
self.0.as_any().downcast_ref() self.0.as_any().downcast_ref()
} }
pub fn downcast_mut<T>(&mut self) -> Option<&mut T> pub fn downcast_mut<T>(&mut self) -> Option<&mut T>
where where
T: Object, T: Object + 'static,
{ {
self.0.as_any_mut().downcast_mut() self.0.as_any_mut().downcast_mut()
} }
pub fn downcast<T>(self) -> Option<T>
where
T: Object,
{
let any: Box<dyn Any> = self;
any.downcast()
}
} }
impl From<Image> for ImageBox { impl From<Image> for ImageBox {
@ -323,9 +315,15 @@ impl From<ImageBox> for Image {
} }
} }
impl Clone for ObjectBox {
fn clone(&self) -> Self {
ObjectBox(self.0.duplicate())
}
}
impl<T> From<T> for ObjectBox impl<T> From<T> for ObjectBox
where where
T: Object, T: Object + 'static,
{ {
fn from(t: T) -> Self { fn from(t: T) -> Self {
ObjectBox(Box::new(t)) ObjectBox(Box::new(t))

View file

@ -24,7 +24,7 @@
//! ```rust //! ```rust
//! use activitystreams_traits::Object; //! use activitystreams_traits::Object;
//! use activitystreams_types::object::properties::ObjectProperties; //! use activitystreams_types::object::properties::ObjectProperties;
//! use serde_derive::{Deserialize, Serialize}; //! use serde::{Deserialize, Serialize};
//! use std::any::Any; //! use std::any::Any;
//! //!
//! #[derive(Clone, Debug, Serialize, Deserialize)] //! #[derive(Clone, Debug, Serialize, Deserialize)]
@ -54,53 +54,56 @@
//! ``` //! ```
use activitystreams_derive::properties; use activitystreams_derive::properties;
use activitystreams_traits::{Collection, Error, Link, Object, Result};
use chrono::{offset::Utc, DateTime};
use serde_derive::{Deserialize, Serialize};
use crate::{ use crate::{
link::LinkBox, link::LinkBox,
object::{Image, ObjectBox}, object::{ImageBox, ObjectBox},
primitives::*, 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! { properties! {
Object { 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 { id {
/// Provides the globally unique identifier for an Object or Link. 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. "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 "- Range: `xsd:anyUri`",
"- Functional: true",
],
types [ types [
XsdAnyUri, XsdAnyUri,
], ],
functional, functional,
alias [ "@id" ],
}, },
attachment { attachment {
/// Identifies a resource attached or related to an object that potentially requires special docs [
/// handling. "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. "The intent is to provide a model that is at least semantically similar to attachments in",
/// "email.",
/// - Range: `Object` | `Link` "",
/// - Functional: false "- Range: `Object` | `Link`",
"- Functional: false",
],
types [ types [
XsdAnyUri, XsdAnyUri,
ObjectBox, ObjectBox,
@ -109,13 +112,15 @@ properties! {
}, },
attributed_to { attributed_to {
/// Identifies one or more entities to which this object is attributed. 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. "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 "- Range: `Object` | `Link`",
"- Functional: false",
],
types [ types [
XsdAnyUri, XsdAnyUri,
ObjectBox, ObjectBox,
@ -124,11 +129,13 @@ properties! {
}, },
audience { audience {
/// Identifies one or more entities that represent the total population of entities for which docs [
/// the object can considered to be relevant. "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 "- Range: `Object` | `Link`",
"- Functional: false",
],
types [ types [
XsdAnyUri, XsdAnyUri,
ObjectBox, ObjectBox,
@ -137,15 +144,17 @@ properties! {
}, },
content { content {
/// The content or textual representation of the Object encoded as a JSON string. 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. "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. "",
/// "The content MAY be expressed using multiple language-tagged values.",
/// - Range: `xsd:string` | `rdf:langString` "",
/// - Functional: false "- Range: `xsd:string` | `rdf:langString`",
"- Functional: false",
],
types [ types [
XsdString, XsdString,
RdfLangString, RdfLangString,
@ -153,14 +162,16 @@ properties! {
}, },
context { context {
/// Identifies the context within which the object exists or an activity was performed. 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. "The notion of \"context\"used is intentionally vague. The intended function is to serve as a",
/// An example could be all activities relating to a common project or event. "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 "- Range: `Object` | `Link`",
"- Functional: false",
],
types [ types [
XsdAnyUri, XsdAnyUri,
ObjectBox, ObjectBox,
@ -169,28 +180,32 @@ properties! {
}, },
name { name {
/// A simple, human-readable, plain-text name for the object. 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. "HTML markup MUST NOT be included. The name MAY be expressed using multiple language-tagged",
/// "values.",
/// - Range: `xsd:string` | `rdf:langString` "",
/// - Functional: false "- Range: `xsd:string` | `rdf:langString`",
"- Functional: false",
],
types [ types [
XsdString, XsdString,
RdfLangString, RdfLangString,
], ],
alias("displayName"), alias [ "displayName" ],
}, },
end_time { end_time {
/// The date and time describing the actual or expected ending time of the object. 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. "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 "- Range: `xsd:dateTime`",
"- Functional: true",
],
types [ types [
XsdDateTime, XsdDateTime,
], ],
@ -198,10 +213,12 @@ properties! {
}, },
generator { generator {
/// Identifies the entity (e.g. an application) that generated the object. docs [
/// "Identifies the entity (e.g. an application) that generated the object.",
/// - Range: `Object` | `Link` "",
/// - Functional: false "- Range: `Object` | `Link`",
"- Functional: false",
],
types [ types [
XsdAnyUri, XsdAnyUri,
ObjectBox, ObjectBox,
@ -210,13 +227,15 @@ properties! {
}, },
icon { icon {
/// Indicates an entity that describes an icon for this object. 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. "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 "- Range: `Image` | `Link`",
"- Functional: false",
],
types [ types [
XsdAnyUri, XsdAnyUri,
ImageBox, ImageBox,
@ -225,12 +244,14 @@ properties! {
}, },
image { image {
/// Indicates an entity that describes an image for this object. 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. "",
/// "Unlike the icon property, there are no aspect ratio or display size limitations assumed.",
/// - Range: `Image` | `Link` "",
/// - Functional: false "- Range: `Image` | `Link`",
"- Functional: false",
],
types [ types [
XsdAnyUri, XsdAnyUri,
ImageBox, ImageBox,
@ -239,10 +260,12 @@ properties! {
}, },
in_reply_to { in_reply_to {
/// Indicates one or more entities for which this object is considered a response. docs [
/// "Indicates one or more entities for which this object is considered a response.",
/// - Range: `Object` | `Link` "",
/// - Functional: false "- Range: `Object` | `Link`",
"- Functional: false",
],
types [ types [
XsdAnyUri, XsdAnyUri,
ObjectBox, ObjectBox,
@ -251,10 +274,12 @@ properties! {
}, },
location { location {
/// Indicates one or more physical or logical locations associated with the object. docs [
/// "Indicates one or more physical or logical locations associated with the object.",
/// - Range: `Object` | `Link` "",
/// - Functional: false "- Range: `Object` | `Link`",
"- Functional: false",
],
types [ types [
XsdAnyUri, XsdAnyUri,
ObjectBox, ObjectBox,
@ -263,10 +288,12 @@ properties! {
}, },
preview { preview {
/// Identifies an entity that provides a preview of this object. docs [
/// "Identifies an entity that provides a preview of this object.",
/// - Range: `Object` | `Link` "",
/// - Functional: false "- Range: `Object` | `Link`",
"- Functional: false",
],
types [ types [
XsdAnyUri, XsdAnyUri,
ObjectBox, ObjectBox,
@ -275,10 +302,12 @@ properties! {
}, },
published { published {
/// The date and time at which the object was published. docs [
/// "The date and time at which the object was published.",
/// - Range: `xsd:dateTime` "",
/// - Functional: true "- Range: `xsd:dateTime`",
"- Functional: true",
],
types [ types [
XsdDateTime, XsdDateTime,
], ],
@ -286,10 +315,12 @@ properties! {
}, },
replies { replies {
/// Identifies a `Collection` containing objects considered to be responses to this object. docs [
/// "Identifies a `Collection` containing objects considered to be responses to this object.",
/// - Range: `Object` | `Link` "",
/// - Functional: false "- Range: `Object` | `Link`",
"- Functional: false",
],
types [ types [
XsdAnyUri, XsdAnyUri,
ObjectBox, ObjectBox,
@ -298,13 +329,15 @@ properties! {
}, },
start_time { start_time {
/// The date and time describing the actual or expected starting time of the object. 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. "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 "- Range: `xsd:DateTime`",
"- Functional: true",
],
types [ types [
XsdDateTime, XsdDateTime,
], ],
@ -312,12 +345,14 @@ properties! {
}, },
summary { summary {
/// A natural language summarization of the object encoded as HTML. docs [
/// "A natural language summarization of the object encoded as HTML.",
/// Multiple language tagged summaries MAY be provided. "",
/// "Multiple language tagged summaries MAY be provided.",
/// - Range: `xsd:string` | `rdf:langString` "",
/// - Functional: false "- Range: `xsd:string` | `rdf:langString`",
"- Functional: false",
],
types [ types [
XsdString, XsdString,
RdfLangString, RdfLangString,
@ -325,14 +360,16 @@ properties! {
}, },
tag { tag {
/// One or more "tags" that have been associated with an objects. A tag can be any kind of docs [
/// `Object`. "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. "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 "- Range: `Object` | `Link`",
"- Functional: false",
],
types [ types [
XsdAnyUri, XsdAnyUri,
ObjectBox, ObjectBox,
@ -341,10 +378,12 @@ properties! {
}, },
updated { updated {
/// The date and time at which the object was updated, docs [
/// "The date and time at which the object was updated,",
/// - Range: `xsd:dateTime` "",
/// - Functional: true "- Range: `xsd:dateTime`",
"- Functional: true",
],
types [ types [
XsdDateTime, XsdDateTime,
], ],
@ -352,10 +391,12 @@ properties! {
}, },
url { url {
/// Identifies one or more links to representations of the object. docs [
/// "Identifies one or more links to representations of the object.",
/// - Range: `xsd:anyUri` | `Link` "",
/// - Functional: false "- Range: `xsd:anyUri` | `Link`",
"- Functional: false",
],
types [ types [
XsdAnyUri, XsdAnyUri,
LinkBox, LinkBox,
@ -363,10 +404,12 @@ properties! {
}, },
to { to {
/// Identifies an entity considered to be part of the public primary audience of an `Object`. docs [
/// "Identifies an entity considered to be part of the public primary audience of an `Object`.",
/// - Range: `Object` | `Link` "",
/// - Functional: false "- Range: `Object` | `Link`",
"- Functional: false",
],
types [ types [
XsdAnyUri, XsdAnyUri,
ObjectBox, ObjectBox,
@ -375,10 +418,12 @@ properties! {
}, },
bto { bto {
/// Identifies an `Object` that is part of the private primary audience of this `Object`. docs [
/// "Identifies an `Object` that is part of the private primary audience of this `Object`.",
/// - Range: `Object` | `Link` "",
/// - Functional: false "- Range: `Object` | `Link`",
"- Functional: false",
],
types [ types [
XsdAnyUri, XsdAnyUri,
ObjectBox, ObjectBox,
@ -387,10 +432,12 @@ properties! {
}, },
cc { cc {
/// Identifies an `Object` that is part of the public secondary audience of this `Object`. docs [
/// "Identifies an `Object` that is part of the public secondary audience of this `Object`.",
/// - Range: `Object` | `Link` "",
/// - Functional: false "- Range: `Object` | `Link`",
"- Functional: false",
],
types [ types [
XsdAnyUri, XsdAnyUri,
ObjectBox, ObjectBox,
@ -399,11 +446,13 @@ properties! {
}, },
bcc { bcc {
/// Identifies one or more `Objects` that are part of the private secondary audience of this docs [
/// `Object`. "Identifies one or more `Objects` that are part of the private secondary audience of this",
/// "`Object`.",
/// - Range: `Object` | `Link` "",
/// - Functional: false "- Range: `Object` | `Link`",
"- Functional: false",
],
types [ types [
XsdAnyUri, XsdAnyUri,
ObjectBox, ObjectBox,
@ -412,13 +461,15 @@ properties! {
}, },
media_type { media_type {
/// When used on an `Object`, identifies the MIME media type of the value of the content docs [
/// property. "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. "",
/// "If not specified, the content property is assumed to contain text/html content.",
/// - Range: `Mime Media Type` "",
/// - Functional: true "- Range: `Mime Media Type`",
"- Functional: true",
],
types [ types [
MimeMediaType, MimeMediaType,
], ],
@ -426,15 +477,17 @@ properties! {
}, },
duration { duration {
/// When the object describes a time-bound resource, such as an audio or video, a meeting, etc, docs [
/// the duration property indicates the object's approximate 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 "The value MUST be expressed as an xsd:duration as defined by",
/// 3.3.6 (e.g. a period of 5 seconds is represented as "PT5S"). "[[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 "- Range: `xsd:duration`",
"- Functional: true",
],
types [ types [
XsdDuration, XsdDuration,
], ],
@ -443,16 +496,18 @@ properties! {
} }
} }
/// Define all the properties of the Location type as described by the Activity Streams vocabulary.
properties! { properties! {
Place { Place {
docs [ "Define all the properties of the Location type as described by the Activity Streams vocabulary." ],
accuracy { accuracy {
/// Indicates the accuracy of position coordinates on a `Place` objects. docs [
/// "Indicates the accuracy of position coordinates on a `Place` objects.",
/// Expressed in properties of percentage. e.g. "94.0" means "94.0% accurate". "",
/// "Expressed in properties of percentage. e.g. \"94.0\"means \"94.0% accurate\".",
/// - Range: `xsd:float` [>= 0.0f, <= 100.0f] "",
/// - Functional: true "- Range: `xsd:float` [>= 0.0f, <= 100.0f]",
"- Functional: true",
],
types [ types [
XsdFloat, XsdFloat,
], ],
@ -460,13 +515,15 @@ properties! {
}, },
altitude { altitude {
/// Indicates the altitude of a place. The measurement units is indicated using the units docs [
/// property. "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. "",
/// "If units is not specified, the default is assumed to be \"m\" indicating meters.",
/// - Range: `xsd:float` "",
/// - Functional: true "- Range: `xsd:float`",
"- Functional: true",
],
types [ types [
XsdFloat, XsdFloat,
], ],
@ -474,21 +531,25 @@ properties! {
}, },
latitude { latitude {
/// The latitude of a place. docs [
/// "The latitude of a place.",
/// - Range: `xsd:float` "",
/// - Functional: true "- Range: `xsd:float`",
"- Functional: true",
],
types [ types [
XsdFloat, XsdFloat,
], ],
functional, functional,
} },
logitude { longitude {
/// The longitude of a place. docs [
/// "The longitude of a place.",
/// - Range: `xsd:float` "",
/// - Functional: true "- Range: `xsd:float`",
"- Functional: true",
],
types [ types [
XsdFloat, XsdFloat,
], ],
@ -496,13 +557,15 @@ properties! {
}, },
radius { radius {
/// The radius from the given latitude and longitude for a Place. 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". "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 "- Range: `xsd:float`",
"- Functional: true",
],
types [ types [
XsdFloat, XsdFloat,
], ],
@ -510,13 +573,15 @@ properties! {
}, },
units { units {
/// Specifies the measurement units for the radius and altitude properties on a `Place` object. 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". "",
/// "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` "TODO: encode rage as any of `\"cm\"` | `\"feet\"` | `\"inches\"` | `\"km\"` | `\"m\"` | `xsd:anyUri`",
/// - Functional: true "- Range: `xsd:anyUri` | `xsd:string`",
"- Functional: true",
],
types [ types [
XsdAnyUri, XsdAnyUri,
XsdString, XsdString,
@ -526,15 +591,17 @@ properties! {
} }
} }
/// Define all the properties of the Profile type as described by the Activity Streams vocabulary.
properties! { properties! {
Profile { Profile {
docs [ "Define all the properties of the Profile type as described by the Activity Streams vocabulary." ],
describes { describes {
/// On a `Profile` object, the describes property identifies the object described by the docs [
/// `Profile`. "On a `Profile` object, the describes property identifies the object described by the",
/// "`Profile`.",
/// - Range: `Object` "",
/// - Functional: true "- Range: `Object`",
"- Functional: true",
],
types [ types [
XsdAnyUri, XsdAnyUri,
ObjectBox, ObjectBox,
@ -544,19 +611,23 @@ properties! {
} }
} }
/// Define all the properties of the Relationship type as described by the Activity Streams
/// vocabulary.
properties! { properties! {
Relationship { Relationship {
docs [
"Define all the properties of the Relationship type as described by the Activity Streams",
"vocabulary.",
],
subject { subject {
/// On a `Relationship` object, the subject property identifies one of the connected docs [
/// individuals. "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. "For instance, for a `Relationship` object describing \"John is related to Sally\", subject",
/// "would refer to John.",
/// - Range: `Object` | `Link` "",
/// - Functional: true "- Range: `Object` | `Link`",
"- Functional: true",
],
types [ types [
XsdAnyUri, XsdAnyUri,
ObjectBox, ObjectBox,
@ -566,10 +637,12 @@ properties! {
}, },
object { object {
/// When used within a `Relationship` describes the entity to which the subject is related. docs [
/// "When used within a `Relationship` describes the entity to which the subject is related.",
/// - Range: `Object` | `Link` "",
/// - Functional: false "- Range: `Object` | `Link`",
"- Functional: false",
],
types [ types [
XsdAnyUri, XsdAnyUri,
ObjectBox, ObjectBox,
@ -578,11 +651,13 @@ properties! {
}, },
relationship { relationship {
/// On a `Relationship` object, the relationship property identifies the kind of relationship docs [
/// that exists between subject and object. "On a `Relationship` object, the relationship property identifies the kind of relationship",
/// "that exists between subject and object.",
/// - Range: `Object` "",
/// - Functional: false "- Range: `Object`",
"- Functional: false",
],
types [ types [
XsdAnyUri, XsdAnyUri,
ObjectBox, ObjectBox,
@ -591,15 +666,17 @@ properties! {
} }
} }
/// Define all the properties of the Tombstone type as described by the Activity Streams vocabulary.
properties! { properties! {
Tombstone { Tombstone {
docs [ "Define all the properties of the Tombstone type as described by the Activity Streams vocabulary." ],
former_type { former_type {
/// On a `Tombstone` object, the formerType property identifies the type of the object that was docs [
/// deleted. "On a `Tombstone` object, the formerType property identifies the type of the object that was",
/// "deleted.",
/// - Range: `Object` "",
/// - Functional: false "- Range: `Object`",
"- Functional: false",
],
types [ types [
XsdAnyUri, XsdAnyUri,
ObjectBox, ObjectBox,
@ -607,11 +684,13 @@ properties! {
}, },
deleted { deleted {
/// On a `Tombstone` object, the deleted property is a timestamp for when the object was docs [
/// deleted. "On a `Tombstone` object, the deleted property is a timestamp for when the object was",
/// "deleted.",
/// - Range: `xsd:dateTime` "",
/// - Functional: true "- Range: `xsd:dateTime`",
"- Functional: true",
],
types [ types [
XsdDateTime, XsdDateTime,
], ],

View file

@ -10,8 +10,8 @@ mod xsd_string;
pub use self::{ pub use self::{
mime_media_type::{MimeMediaType, MimeMediaTypeError}, mime_media_type::{MimeMediaType, MimeMediaTypeError},
rdf_lang_string::RDFLangString, rdf_lang_string::RdfLangString,
xsd_any_uri::{XsdAnyURI, XsdAnyURIError}, xsd_any_uri::{XsdAnyUri, XsdAnyUriError},
xsd_datetime::{XsdDateTime, XsdDateTimeError}, xsd_datetime::{XsdDateTime, XsdDateTimeError},
xsd_duration::{XsdDuration, XsdDurationError}, xsd_duration::{XsdDuration, XsdDurationError},
xsd_float::{XsdFloat, XsdFloatError}, xsd_float::{XsdFloat, XsdFloatError},

View file

@ -1,5 +1,5 @@
#[derive(Clone, Debug, serde_derive::Deserialize, serde_derive::Serialize)] #[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize)]
pub struct RDFLangString { pub struct RdfLangString {
#[serde(rename = "@value")] #[serde(rename = "@value")]
pub value: String, pub value: String,
@ -7,7 +7,7 @@ pub struct RDFLangString {
pub language: String, 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 { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "{}:{}", self.language, self.value) write!(f, "{}:{}", self.language, self.value)
} }

View file

@ -1,44 +1,44 @@
#[derive(Clone, Debug, serde_derive::Deserialize, serde_derive::Serialize)] #[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize)]
#[serde(transparent)] #[serde(transparent)]
pub struct XsdAnyURI(String); pub struct XsdAnyUri(String);
#[derive(Clone, Debug, thiserror::Error)] #[derive(Clone, Debug, thiserror::Error)]
#[error("Could not parse XsdAnyURI")] #[error("Could not parse XsdAnyUri")]
pub struct XsdAnyURIError; pub struct XsdAnyUriError;
impl std::convert::TryFrom<String> for XsdAnyURI { impl std::convert::TryFrom<String> for XsdAnyUri {
type Error = XsdAnyURIError; type Error = XsdAnyUriError;
fn try_from(s: String) -> Result<Self, Self::Error> { fn try_from(s: String) -> Result<Self, Self::Error> {
Ok(XsdAnyURI(s)) Ok(XsdAnyUri(s))
} }
} }
impl std::convert::TryFrom<&str> for XsdAnyURI { impl std::convert::TryFrom<&str> for XsdAnyUri {
type Error = XsdAnyURIError; type Error = XsdAnyUriError;
fn try_from(s: &str) -> Result<Self, Self::Error> { fn try_from(s: &str) -> Result<Self, Self::Error> {
Ok(XsdAnyURI(s.to_owned())) Ok(XsdAnyUri(s.to_owned()))
} }
} }
impl std::convert::TryFrom<&mut str> for XsdAnyURI { impl std::convert::TryFrom<&mut str> for XsdAnyUri {
type Error = XsdAnyURIError; type Error = XsdAnyUriError;
fn try_from(s: &mut str) -> Result<Self, Self::Error> { fn try_from(s: &mut str) -> Result<Self, Self::Error> {
Ok(XsdAnyURI(s.to_owned())) Ok(XsdAnyUri(s.to_owned()))
} }
} }
impl std::str::FromStr for XsdAnyURI { impl std::str::FromStr for XsdAnyUri {
type Err = XsdAnyURIError; type Err = XsdAnyUriError;
fn from_str(s: &str) -> Result<Self, Self::Err> { fn from_str(s: &str) -> Result<Self, Self::Err> {
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 { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
std::fmt::Display::fmt(&self.0, f) std::fmt::Display::fmt(&self.0, f)
} }

View file

@ -1,4 +1,4 @@
#[derive(Clone, Debug, serde_derive::Deserialize, serde_derive::Serialize)] #[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize)]
#[serde(transparent)] #[serde(transparent)]
pub struct XsdFloat(f64); pub struct XsdFloat(f64);

View file

@ -1,4 +1,4 @@
#[derive(Clone, Debug, serde_derive::Deserialize, serde_derive::Serialize)] #[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize)]
#[serde(transparent)] #[serde(transparent)]
pub struct XsdNonNegativeFloat(f64); pub struct XsdNonNegativeFloat(f64);

View file

@ -1,4 +1,4 @@
#[derive(Clone, Debug, serde_derive::Deserialize, serde_derive::Serialize)] #[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize)]
#[serde(transparent)] #[serde(transparent)]
pub struct XsdNonNegativeInteger(u64); pub struct XsdNonNegativeInteger(u64);

View file

@ -1,4 +1,4 @@
#[derive(Clone, Debug, serde_derive::Deserialize, serde_derive::Serialize)] #[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize)]
#[serde(transparent)] #[serde(transparent)]
pub struct XsdString(String); pub struct XsdString(String);

View file

@ -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 <http://www.gnu.org/licenses/>.
*/
//! Error traits and types
pub use activitystreams_traits::{Error, Result};

View file

@ -125,15 +125,12 @@
pub mod activity; pub mod activity;
pub mod actor; pub mod actor;
pub mod collection; pub mod collection;
mod error;
pub mod link; pub mod link;
pub mod object; pub mod object;
pub use self::activity::{Activity, ActivityExt, IntransitiveActivity}; pub use self::activity::{Activity, ActivityExt, IntransitiveActivity};
pub use self::actor::Actor; pub use self::actor::Actor;
pub use self::collection::{Collection, CollectionExt, CollectionPage, CollectionPageExt}; pub use self::collection::{Collection, CollectionExt, CollectionPage, CollectionPageExt};
pub use self::error::{Error, Result};
pub use self::link::{Link, LinkExt}; pub use self::link::{Link, LinkExt};
pub use self::object::{Object, ObjectExt}; pub use self::object::{Object, ObjectExt};
pub use activitystreams_traits::properties;
pub use activitystreams_types::context; pub use activitystreams_types::context;