Try extension method

This commit is contained in:
asonix 2020-03-18 17:36:16 -05:00
parent 843233811d
commit 7dda503c65
25 changed files with 523 additions and 1575 deletions

View file

@ -1,7 +1,7 @@
[package]
name = "activitystreams"
description = "Activity Streams in Rust"
version = "0.5.0-alpha.8"
version = "0.5.0-alpha.9"
license = "GPL-3.0"
authors = ["asonix <asonix@asonix.dog>"]
repository = "https://git.asonix.dog/Aardwolf/activitystreams"
@ -11,13 +11,13 @@ edition = "2018"
[features]
default = ["types"]
derive = ["activitystreams-derive"]
derive = ["activitystreams-derive", "serde", "serde_json"]
kinds = ["derive", "serde"]
primitives = ["chrono", "mime", "serde", "thiserror", "url"]
types = ["derive", "kinds", "primitives", "serde", "serde_json"]
types = ["derive", "kinds", "primitives"]
[dependencies]
activitystreams-derive = { version = "0.5.0-alpha.3", path = "activitystreams-derive", optional = true}
activitystreams-derive = { version = "0.5.0-alpha.4", path = "activitystreams-derive", optional = true}
chrono = { version = "0.4", optional = true }
mime = { version = "0.3", optional = true }
serde = { version = "1.0", features = ["derive"], optional = true }

View file

@ -9,7 +9,7 @@ __A set of Traits and Types that make up the ActivityStreams and ActivityPub spe
First, add ActivityStreams to your dependencies
```toml
activitystreams = "0.5.0-alpha.8"
activitystreams = "0.5.0-alpha.9"
```
### Types
@ -177,7 +177,7 @@ There are a number of features that can be disabled in this crate. By default, e
enabled.
```toml
activitystreams = { version = "0.5.0-alpha.8", default-features = "false", features = ["derive"] }
activitystreams = { version = "0.5.0-alpha.9", default-features = "false", features = ["derive"] }
```
| feature | what you get |

View file

@ -1,7 +1,7 @@
[package]
name = "activitystreams-derive"
description = "Derive macros for activitystreams"
version = "0.5.0-alpha.3"
version = "0.5.0-alpha.4"
license = "GPL-3.0"
authors = ["asonix <asonix.dev@gmail.com>"]
repository = "https://git.asonix.dog/Aardwolf/activitystreams"

View file

@ -23,8 +23,8 @@
//!
//! First, add `serde` and `activitystreams-derive` to your Cargo.toml
//! ```toml
//! activitystreams-derive = "0.5.0-alpha.3"
//! # or activitystreams = "0.5.0-alpha.4"
//! activitystreams-derive = "0.5.0-alpha.4"
//! # or activitystreams = "0.5.0-alpha.9"
//! serde = { version = "1.0", features = ["derive"] }
//! ```
//!
@ -103,6 +103,66 @@ use syn::{
token, Attribute, Data, DeriveInput, Fields, Ident, LitStr, Result, Token, Type,
};
/// Generate a type with default extensions
///
/// This derive
/// ```ignore
/// use activitystreams::{extensions::Ext, Extensible};
///
/// #[derive(Clone, Debug, Default, Extensible)]
/// #[extension(MyExtension)]
/// #[extension(MyOtherExtension)]
/// pub struct MyType;
/// ```
///
/// Produces this code
/// ```ignore
/// impl MyType {
/// pub fn full() -> Ext<Ext<MyType, MyExtension>, OtherExtension> {
/// Default::default()
/// }
/// }
/// ```
#[proc_macro_derive(Extensible, attributes(extension))]
pub fn extensible(input: TokenStream) -> TokenStream {
let input: DeriveInput = syn::parse(input).unwrap();
let name = input.ident;
let kind: proc_macro2::TokenStream = input
.attrs
.iter()
.filter_map(move |attr| {
if attr
.path
.segments
.last()
.map(|segment| segment.ident == "extension")
.unwrap_or(false)
{
Some(from_value(attr.clone()))
} else {
None
}
})
.fold(quote! {#name}, |acc, ident| {
quote! { Ext<#acc, #ident> }
});
let tokens = quote! {
impl #name {
/// Generate a fully extended type
///
/// This effect can be achieved with `Self::new().extend(SomeExtension::default())`
pub fn full() -> #kind {
Default::default()
}
}
};
tokens.into()
}
/// Derive implementations for activitystreams objects
///
/// ```ignore
@ -135,7 +195,18 @@ pub fn ref_derive(input: TokenStream) -> TokenStream {
};
let name2 = name.clone();
let base_impls: proc_macro2::TokenStream = input
let name3 = name.clone();
let base_impl = quote! {
impl Base for #name3 {}
impl #name3 {
/// Create from default
pub fn new() -> Self {
Default::default()
}
}
};
let trait_impls: proc_macro2::TokenStream = input
.attrs
.iter()
.filter_map(move |attr| {
@ -191,17 +262,56 @@ pub fn ref_derive(input: TokenStream) -> TokenStream {
}
}
impl<U> AsRef<#ty> for Ext<#name, U>
where
U: std::fmt::Debug,
{
fn as_ref(&self) -> &#ty {
self.base.as_ref()
}
}
impl<U, V> AsRef<#ty> for Ext<Ext<#name, U>, V>
where
U: std::fmt::Debug,
V: std::fmt::Debug,
{
fn as_ref(&self) -> &#ty {
self.base.as_ref()
}
}
impl AsMut<#ty> for #name {
fn as_mut(&mut self) -> &mut #ty {
&mut self.#ident
}
}
impl<U> AsMut<#ty> for Ext<#name, U>
where
U: std::fmt::Debug,
{
fn as_mut(&mut self) -> &mut #ty {
self.base.as_mut()
}
}
impl<U, V> AsMut<#ty> for Ext<Ext<#name, U>, V>
where
U: std::fmt::Debug,
V: std::fmt::Debug,
{
fn as_mut(&mut self) -> &mut #ty {
self.base.as_mut()
}
}
}
})
.collect();
let full = quote! {
#base_impls
#base_impl
#trait_impls
#tokens
};

View file

@ -1,827 +0,0 @@
/*
* This file is part of ActivityStreams.
*
* Copyright © 2020 Riley Trautman
*
* ActivityStreams is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ActivityStreams is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ActivityStreams. If not, see <http://www.gnu.org/licenses/>.
*/
//! Activity traits and types
use crate::{
activity::{
kind::*, properties::*, Activity, ActivityBox, IntransitiveActivity,
IntransitiveActivityBox,
},
object::{
properties::{ApObjectProperties, ObjectProperties},
Object, ObjectBox,
},
PropRefs,
};
use serde::{Deserialize, Serialize};
/// Indicates that the actor accepts the object.
///
/// The target property can be used in certain circumstances to indicate the context into which the
/// object has been accepted.
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[prop_refs(Activity)]
pub struct Accept {
#[serde(rename = "type")]
kind: AcceptType,
#[serde(flatten)]
#[prop_refs]
pub accept_props: AcceptProperties,
#[serde(flatten)]
#[prop_refs]
pub object_props: ObjectProperties,
#[serde(flatten)]
#[prop_refs]
pub ap_object_props: ApObjectProperties,
#[serde(flatten)]
#[prop_refs]
pub activity_props: ActivityProperties,
}
/// Indicates that the actor has added the object to the target.
///
/// If the target property is not explicitly specified, the target would need to be determined
/// implicitly by context. The origin can be used to identify the context from which the object
/// originated.
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[prop_refs(Activity)]
pub struct Add {
#[serde(rename = "type")]
kind: AddType,
#[serde(flatten)]
#[prop_refs]
pub add_props: AddProperties,
#[serde(flatten)]
#[prop_refs]
pub object_props: ObjectProperties,
#[serde(flatten)]
#[prop_refs]
pub ap_object_props: ApObjectProperties,
#[serde(flatten)]
#[prop_refs]
pub activity_props: ActivityProperties,
}
/// Indicates that the actor has moved object from origin to target.
///
/// If the origin or target are not specified, either can be determined by context.
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[prop_refs(Activity)]
pub struct AMove {
#[serde(rename = "type")]
kind: MoveType,
#[serde(flatten)]
#[prop_refs]
pub move_props: MoveProperties,
#[serde(flatten)]
#[prop_refs]
pub object_props: ObjectProperties,
#[serde(flatten)]
#[prop_refs]
pub ap_object_props: ApObjectProperties,
#[serde(flatten)]
#[prop_refs]
pub activity_props: ActivityProperties,
}
/// Indicates that the actor is calling the target's attention the object.
///
/// The origin typically has no defined meaning.
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[prop_refs(Activity)]
pub struct Announce {
#[serde(rename = "type")]
kind: AnnounceType,
#[serde(flatten)]
#[prop_refs]
pub announce_props: AnnounceProperties,
#[serde(flatten)]
#[prop_refs]
pub object_props: ObjectProperties,
#[serde(flatten)]
#[prop_refs]
pub ap_object_props: ApObjectProperties,
#[serde(flatten)]
#[prop_refs]
pub activity_props: ActivityProperties,
}
/// An IntransitiveActivity that indicates that the actor has arrived at the location.
///
/// The origin can be used to identify the context from which the actor originated. The target
/// typically has no defined meaning.
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[prop_refs(Activity)]
#[prop_refs(IntransitiveActivity)]
pub struct Arrive {
#[serde(rename = "type")]
kind: ArriveType,
#[serde(flatten)]
#[prop_refs]
pub arrive_props: ArriveProperties,
#[serde(flatten)]
#[prop_refs]
pub object_props: ObjectProperties,
#[serde(flatten)]
#[prop_refs]
pub ap_object_props: ApObjectProperties,
#[serde(flatten)]
#[prop_refs]
pub activity_props: ActivityProperties,
}
/// Indicates that the actor is blocking the object.
///
/// Blocking is a stronger form of Ignore. The typical use is to support social systems that allow
/// one user to block activities or content of other users. The target and origin typically have no
/// defined meaning.
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[prop_refs(Activity)]
pub struct Block {
#[serde(rename = "type")]
kind: BlockType,
#[serde(flatten)]
#[prop_refs]
pub block_props: BlockProperties,
#[serde(flatten)]
#[prop_refs]
pub object_props: ObjectProperties,
#[serde(flatten)]
#[prop_refs]
pub ap_object_props: ApObjectProperties,
#[serde(flatten)]
#[prop_refs]
pub activity_props: ActivityProperties,
}
/// Indicates that the actor has created the object.
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[prop_refs(Activity)]
pub struct Create {
#[serde(rename = "type")]
kind: CreateType,
#[serde(flatten)]
#[prop_refs]
pub create_props: CreateProperties,
#[serde(flatten)]
#[prop_refs]
pub object_props: ObjectProperties,
#[serde(flatten)]
#[prop_refs]
pub ap_object_props: ApObjectProperties,
#[serde(flatten)]
#[prop_refs]
pub activity_props: ActivityProperties,
}
/// Indicates that the actor has deleted the object.
///
/// If specified, the origin indicates the context from which the object was deleted.
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[prop_refs(Activity)]
pub struct Delete {
#[serde(rename = "type")]
kind: DeleteType,
#[serde(flatten)]
#[prop_refs]
pub delete_props: DeleteProperties,
#[serde(flatten)]
#[prop_refs]
pub object_props: ObjectProperties,
#[serde(flatten)]
#[prop_refs]
pub ap_object_props: ApObjectProperties,
#[serde(flatten)]
#[prop_refs]
pub activity_props: ActivityProperties,
}
/// Indicates that the actor dislikes the object.
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[prop_refs(Activity)]
pub struct Dislike {
#[serde(rename = "type")]
kind: DislikeType,
#[serde(flatten)]
#[prop_refs]
pub dislike_props: DislikeProperties,
#[serde(flatten)]
#[prop_refs]
pub object_props: ObjectProperties,
#[serde(flatten)]
#[prop_refs]
pub ap_object_props: ApObjectProperties,
#[serde(flatten)]
#[prop_refs]
pub activity_props: ActivityProperties,
}
/// Indicates that the actor is "flagging" the object.
///
/// Flagging is defined in the sense common to many social platforms as reporting content as being
/// inappropriate for any number of reasons.
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[prop_refs(Activity)]
pub struct Flag {
#[serde(rename = "type")]
kind: FlagType,
#[serde(flatten)]
#[prop_refs]
pub flag_props: FlagProperties,
#[serde(flatten)]
#[prop_refs]
pub object_props: ObjectProperties,
#[serde(flatten)]
#[prop_refs]
pub ap_object_props: ApObjectProperties,
#[serde(flatten)]
#[prop_refs]
pub activity_props: ActivityProperties,
}
/// Indicates that the actor is "following" the object.
///
/// Following is defined in the sense typically used within Social systems in which the actor is
/// interested in any activity performed by or on the object. The target and origin typically have
/// no defined meaning.
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[prop_refs(Activity)]
pub struct Follow {
#[serde(rename = "type")]
kind: FollowType,
#[serde(flatten)]
#[prop_refs]
pub follow_props: FollowProperties,
#[serde(flatten)]
#[prop_refs]
pub object_props: ObjectProperties,
#[serde(flatten)]
#[prop_refs]
pub ap_object_props: ApObjectProperties,
#[serde(flatten)]
#[prop_refs]
pub activity_props: ActivityProperties,
}
/// Indicates that the actor is ignoring the object.
///
/// The target and origin typically have no defined meaning.
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[prop_refs(Activity)]
pub struct Ignore {
#[serde(rename = "type")]
kind: IgnoreType,
#[serde(flatten)]
#[prop_refs]
pub ignore_props: IgnoreProperties,
#[serde(flatten)]
#[prop_refs]
pub object_props: ObjectProperties,
#[serde(flatten)]
#[prop_refs]
pub ap_object_props: ApObjectProperties,
#[serde(flatten)]
#[prop_refs]
pub activity_props: ActivityProperties,
}
/// A specialization of Offer in which the actor is extending an invitation for the object to the
/// target.
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[prop_refs(Activity)]
pub struct Invite {
#[serde(rename = "type")]
kind: InviteType,
#[serde(flatten)]
#[prop_refs]
pub invite_props: InviteProperties,
#[serde(flatten)]
#[prop_refs]
pub object_props: ObjectProperties,
#[serde(flatten)]
#[prop_refs]
pub ap_object_props: ApObjectProperties,
#[serde(flatten)]
#[prop_refs]
pub activity_props: ActivityProperties,
}
/// Indicates that the actor has joined the object.
///
/// The target and origin typically have no defined meaning
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[prop_refs(Activity)]
pub struct Join {
#[serde(rename = "type")]
kind: JoinType,
#[serde(flatten)]
#[prop_refs]
pub join_props: JoinProperties,
#[serde(flatten)]
#[prop_refs]
pub object_props: ObjectProperties,
#[serde(flatten)]
#[prop_refs]
pub ap_object_props: ApObjectProperties,
#[serde(flatten)]
#[prop_refs]
pub activity_props: ActivityProperties,
}
/// Indicates that the actor has left the object.
///
/// The target and origin typically have no meaning.
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[prop_refs(Activity)]
pub struct Leave {
#[serde(rename = "type")]
kind: LeaveType,
#[serde(flatten)]
#[prop_refs]
pub leave_props: LeaveProperties,
#[serde(flatten)]
#[prop_refs]
pub object_props: ObjectProperties,
#[serde(flatten)]
#[prop_refs]
pub ap_object_props: ApObjectProperties,
#[serde(flatten)]
#[prop_refs]
pub activity_props: ActivityProperties,
}
/// Indicates that the actor likes, recommends or endorses the object.
///
/// The target and origin typically have no defined meaning.
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[prop_refs(Activity)]
pub struct Like {
#[serde(rename = "type")]
kind: LikeType,
#[serde(flatten)]
#[prop_refs]
pub like_props: LikeProperties,
#[serde(flatten)]
#[prop_refs]
pub object_props: ObjectProperties,
#[serde(flatten)]
#[prop_refs]
pub ap_object_props: ApObjectProperties,
#[serde(flatten)]
#[prop_refs]
pub activity_props: ActivityProperties,
}
/// Indicates that the actor has listened to the object.
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[prop_refs(Activity)]
pub struct Listen {
#[serde(rename = "type")]
kind: ListenType,
#[serde(flatten)]
#[prop_refs]
pub listen_props: ListenProperties,
#[serde(flatten)]
#[prop_refs]
pub object_props: ObjectProperties,
#[serde(flatten)]
#[prop_refs]
pub ap_object_props: ApObjectProperties,
#[serde(flatten)]
#[prop_refs]
pub activity_props: ActivityProperties,
}
/// Indicates that the actor is offering the object.
///
/// If specified, the target indicates the entity to which the object is being offered.
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[prop_refs(Activity)]
pub struct Offer {
#[serde(rename = "type")]
kind: OfferType,
#[serde(flatten)]
#[prop_refs]
pub offer_props: OfferProperties,
#[serde(flatten)]
#[prop_refs]
pub object_props: ObjectProperties,
#[serde(flatten)]
#[prop_refs]
pub ap_object_props: ApObjectProperties,
#[serde(flatten)]
#[prop_refs]
pub activity_props: ActivityProperties,
}
/// Represents a question being asked.
///
/// Question objects are an extension of IntransitiveActivity. That is, the Question object is an
/// Activity, but the direct object is the question itself and therefore it would not contain an
/// object property.
///
/// Either of the anyOf and oneOf properties MAY be used to express possible answers, but a
/// Question object MUST NOT have both properties.
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[prop_refs(Activity)]
#[prop_refs(IntransitiveActivity)]
pub struct Question {
#[serde(rename = "type")]
kind: QuestionType,
#[serde(flatten)]
#[prop_refs]
pub question_props: QuestionProperties,
#[serde(flatten)]
#[prop_refs]
pub object_props: ObjectProperties,
#[serde(flatten)]
#[prop_refs]
pub ap_object_props: ApObjectProperties,
#[serde(flatten)]
#[prop_refs]
pub activity_props: ActivityProperties,
}
/// Indicates that the actor has read the object.
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[prop_refs(Activity)]
pub struct Read {
#[serde(rename = "type")]
kind: ReadType,
#[serde(flatten)]
#[prop_refs]
pub read_props: ReadProperties,
#[serde(flatten)]
#[prop_refs]
pub object_props: ObjectProperties,
#[serde(flatten)]
#[prop_refs]
pub ap_object_props: ApObjectProperties,
#[serde(flatten)]
#[prop_refs]
pub activity_props: ActivityProperties,
}
/// Indicates that the actor is rejecting the object.
///
/// The target and origin typically have no defined meaning.
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[prop_refs(Activity)]
pub struct Reject {
#[serde(rename = "type")]
kind: RejectType,
#[serde(flatten)]
#[prop_refs]
pub reject_props: RejectProperties,
#[serde(flatten)]
#[prop_refs]
pub object_props: ObjectProperties,
#[serde(flatten)]
#[prop_refs]
pub ap_object_props: ApObjectProperties,
#[serde(flatten)]
#[prop_refs]
pub activity_props: ActivityProperties,
}
/// Indicates that the actor is removing the object.
///
/// If specified, the origin indicates the context from which the object is being removed.
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[prop_refs(Activity)]
pub struct Remove {
#[serde(rename = "type")]
kind: RemoveType,
#[serde(flatten)]
#[prop_refs]
pub remove_props: RemoveProperties,
#[serde(flatten)]
#[prop_refs]
pub object_props: ObjectProperties,
#[serde(flatten)]
#[prop_refs]
pub ap_object_props: ApObjectProperties,
#[serde(flatten)]
#[prop_refs]
pub activity_props: ActivityProperties,
}
/// A specialization of Accept indicating that the acceptance is tentative.
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[prop_refs(Activity)]
pub struct TentativeAccept {
#[serde(rename = "type")]
kind: TentativeAcceptType,
#[serde(flatten)]
#[prop_refs]
pub tentative_accept_props: TentativeAcceptProperties,
#[serde(flatten)]
#[prop_refs]
pub object_props: ObjectProperties,
#[serde(flatten)]
#[prop_refs]
pub ap_object_props: ApObjectProperties,
#[serde(flatten)]
#[prop_refs]
pub activity_props: ActivityProperties,
}
/// A specialization of Reject in which the rejection is considered tentative.
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[prop_refs(Activity)]
pub struct TentativeReject {
#[serde(rename = "type")]
kind: TentativeRejectType,
#[serde(flatten)]
#[prop_refs]
pub tentative_reject_props: TentativeRejectProperties,
#[serde(flatten)]
#[prop_refs]
pub object_props: ObjectProperties,
#[serde(flatten)]
#[prop_refs]
pub ap_object_props: ApObjectProperties,
#[serde(flatten)]
#[prop_refs]
pub activity_props: ActivityProperties,
}
/// Indicates that the actor is traveling to target from origin.
///
/// Travel is an IntransitiveObject whose actor specifies the direct object. If the target or
/// origin are not specified, either can be determined by context.
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[prop_refs(Activity)]
#[prop_refs(IntransitiveActivity)]
pub struct Travel {
#[serde(rename = "type")]
kind: TravelType,
#[serde(flatten)]
#[prop_refs]
pub travel_props: TravelProperties,
#[serde(flatten)]
#[prop_refs]
pub object_props: ObjectProperties,
#[serde(flatten)]
#[prop_refs]
pub ap_object_props: ApObjectProperties,
#[serde(flatten)]
#[prop_refs]
pub activity_props: ActivityProperties,
}
/// Indicates that the actor is undoing the object.
///
/// In most cases, the object will be an Activity describing some previously performed action (for
/// instance, a person may have previously "liked" an article but, for whatever reason, might
/// choose to undo that like at some later point in time).
///
/// The target and origin typically have no defined meaning.
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[prop_refs(Activity)]
pub struct Undo {
#[serde(rename = "type")]
kind: UndoType,
#[serde(flatten)]
#[prop_refs]
pub undo_props: UndoProperties,
#[serde(flatten)]
#[prop_refs]
pub object_props: ObjectProperties,
#[serde(flatten)]
#[prop_refs]
pub ap_object_props: ApObjectProperties,
#[serde(flatten)]
#[prop_refs]
pub activity_props: ActivityProperties,
}
/// Indicates that the actor has updated the object.
///
/// Note, however, that this vocabulary does not define a mechanism for describing the actual set
/// of modifications made to object.
///
/// The target and origin typically have no defined meaning.
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[prop_refs(Activity)]
pub struct Update {
#[serde(rename = "type")]
kind: UpdateType,
#[serde(flatten)]
#[prop_refs]
pub update_props: UpdateProperties,
#[serde(flatten)]
#[prop_refs]
pub object_props: ObjectProperties,
#[serde(flatten)]
#[prop_refs]
pub ap_object_props: ApObjectProperties,
#[serde(flatten)]
#[prop_refs]
pub activity_props: ActivityProperties,
}
/// Indicates that the actor has viewed the object.
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[prop_refs(Activity)]
pub struct View {
#[serde(rename = "type")]
kind: ViewType,
#[serde(flatten)]
#[prop_refs]
pub view_props: ViewProperties,
#[serde(flatten)]
#[prop_refs]
pub object_props: ObjectProperties,
#[serde(flatten)]
#[prop_refs]
pub ap_object_props: ApObjectProperties,
#[serde(flatten)]
#[prop_refs]
pub activity_props: ActivityProperties,
}

View file

@ -17,17 +17,19 @@
* along with ActivityStreams. If not, see <http://www.gnu.org/licenses/>.
*/
#[cfg(feature = "types")]
pub mod apub;
#[cfg(feature = "kinds")]
pub mod kind;
#[cfg(feature = "types")]
pub mod properties;
#[cfg(feature = "types")]
pub mod streams;
mod types;
#[cfg(feature = "types")]
use crate::wrapper_type;
pub use self::types::{
AMove, Accept, Add, Announce, Arrive, Block, Create, Delete, Dislike, Flag, Follow, Ignore,
Invite, Join, Leave, Like, Listen, Offer, Question, Read, Reject, Remove, TentativeAccept,
TentativeReject, Travel, Undo, Update, View,
};
use crate::object::Object;
@ -37,12 +39,12 @@ use crate::object::Object;
/// The `Activity` type itself serves as an abstract base type for all types of activities. It is
/// important to note that the `Activity` type itself does not carry any specific semantics about
/// the kind of action being taken.
#[cfg_attr(feature = "types", wrapper_type)]
#[cfg_attr(feature = "derive", crate::wrapper_type)]
pub trait Activity: Object {}
/// Instances of `IntransitiveActivity` are a subtype of `Activity` representing intransitive
/// actions.
///
/// The `object` property is therefore inappropriate for these activities.
#[cfg_attr(feature = "types", wrapper_type)]
#[cfg_attr(feature = "derive", crate::wrapper_type)]
pub trait IntransitiveActivity: Activity {}

View file

@ -30,7 +30,7 @@
//! properties::ObjectProperties,
//! Object, ObjectBox,
//! },
//! PropRefs,
//! Base, BaseBox, PropRefs,
//! };
//! use serde::{Deserialize, Serialize};
//!
@ -59,7 +59,7 @@
//! # fn main() {}
//! ```
use crate::{link::LinkBox, object::ObjectBox, primitives::*, properties};
use crate::{primitives::*, properties, BaseBox};
properties! {
Activity {
@ -81,8 +81,7 @@ properties! {
],
types [
XsdAnyUri,
ObjectBox,
LinkBox,
BaseBox
],
},
@ -95,8 +94,7 @@ properties! {
],
types [
XsdAnyUri,
ObjectBox,
LinkBox,
BaseBox,
],
},
}
@ -119,8 +117,7 @@ properties! {
],
types [
XsdAnyUri,
ObjectBox,
LinkBox,
BaseBox,
],
required
},
@ -138,8 +135,7 @@ properties! {
],
types [
XsdAnyUri,
ObjectBox,
LinkBox,
BaseBox,
],
},
@ -157,8 +153,7 @@ properties! {
],
types [
XsdAnyUri,
ObjectBox,
LinkBox,
BaseBox,
],
},
}
@ -181,8 +176,7 @@ properties! {
],
types [
XsdAnyUri,
ObjectBox,
LinkBox,
BaseBox,
],
required,
},
@ -199,8 +193,7 @@ properties! {
],
types [
XsdAnyUri,
ObjectBox,
LinkBox,
BaseBox,
],
required,
},
@ -224,8 +217,7 @@ properties! {
],
types [
XsdAnyUri,
ObjectBox,
LinkBox,
BaseBox,
],
required,
},
@ -242,8 +234,7 @@ properties! {
],
types [
XsdAnyUri,
ObjectBox,
LinkBox,
BaseBox,
],
required,
},
@ -262,8 +253,7 @@ properties! {
],
types [
XsdAnyUri,
ObjectBox,
LinkBox,
BaseBox,
],
required,
},
@ -287,8 +277,7 @@ properties! {
],
types [
XsdAnyUri,
ObjectBox,
LinkBox,
BaseBox,
],
required,
},
@ -305,8 +294,7 @@ properties! {
],
types [
XsdAnyUri,
ObjectBox,
LinkBox,
BaseBox,
],
required,
},
@ -325,8 +313,7 @@ properties! {
],
types [
XsdAnyUri,
ObjectBox,
LinkBox,
BaseBox,
],
},
}
@ -349,8 +336,7 @@ properties! {
],
types [
XsdAnyUri,
ObjectBox,
LinkBox,
BaseBox,
],
required,
},
@ -367,8 +353,7 @@ properties! {
],
types [
XsdAnyUri,
ObjectBox,
LinkBox,
BaseBox,
],
required,
},
@ -386,8 +371,7 @@ properties! {
],
types [
XsdAnyUri,
ObjectBox,
LinkBox,
BaseBox,
],
},
}
@ -410,8 +394,7 @@ properties! {
],
types [
XsdAnyUri,
ObjectBox,
LinkBox,
BaseBox,
],
required,
},
@ -428,8 +411,7 @@ properties! {
],
types [
XsdAnyUri,
ObjectBox,
LinkBox,
BaseBox,
],
required,
},
@ -447,8 +429,7 @@ properties! {
],
types [
XsdAnyUri,
ObjectBox,
LinkBox,
BaseBox,
],
},
@ -466,8 +447,7 @@ properties! {
],
types [
XsdAnyUri,
ObjectBox,
LinkBox,
BaseBox,
],
},
}
@ -490,8 +470,7 @@ properties! {
],
types [
XsdString,
ObjectBox,
LinkBox,
BaseBox,
],
required,
},
@ -509,8 +488,7 @@ properties! {
],
types [
XsdAnyUri,
ObjectBox,
LinkBox,
BaseBox,
],
required,
},
@ -587,8 +565,7 @@ properties! {
],
types [
XsdAnyUri,
ObjectBox,
LinkBox,
BaseBox,
],
},
@ -604,8 +581,7 @@ properties! {
],
types [
XsdAnyUri,
ObjectBox,
LinkBox,
BaseBox,
],
},
}

View file

@ -22,19 +22,23 @@ use crate::{
kind::*, properties::*, Activity, ActivityBox, IntransitiveActivity,
IntransitiveActivityBox,
},
object::{properties::ObjectProperties, Object, ObjectBox},
PropRefs,
ext::Ext,
object::{
properties::{ApObjectProperties, ObjectProperties},
Object, ObjectBox,
},
Base, Extensible, PropRefs,
};
use serde::{Deserialize, Serialize};
/// Indicates that the actor accepts the object.
///
/// The target property can be used in certain circumstances to indicate the context into which the
/// object has been accepted.
#[derive(Clone, Debug, Default, Deserialize, PropRefs, Serialize)]
#[derive(Clone, Debug, Default, Extensible, PropRefs, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[prop_refs(Activity)]
#[extension(ApObjectProperties)]
pub struct Accept {
#[serde(rename = "type")]
#[serde(alias = "objectType")]
@ -62,10 +66,11 @@ pub struct Accept {
/// If the target property is not explicitly specified, the target would need to be determined
/// implicitly by context. The origin can be used to identify the context from which the object
/// originated.
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[derive(Clone, Debug, Default, Extensible, PropRefs, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[prop_refs(Activity)]
#[extension(ApObjectProperties)]
pub struct Add {
#[serde(rename = "type")]
#[serde(alias = "objectType")]
@ -91,10 +96,11 @@ pub struct Add {
/// Indicates that the actor has moved object from origin to target.
///
/// If the origin or target are not specified, either can be determined by context.
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[derive(Clone, Debug, Default, Extensible, PropRefs, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[prop_refs(Activity)]
#[extension(ApObjectProperties)]
pub struct AMove {
#[serde(rename = "type")]
#[serde(alias = "objectType")]
@ -120,10 +126,11 @@ pub struct AMove {
/// Indicates that the actor is calling the target's attention the object.
///
/// The origin typically has no defined meaning.
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[derive(Clone, Debug, Default, Extensible, PropRefs, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[prop_refs(Activity)]
#[extension(ApObjectProperties)]
pub struct Announce {
#[serde(rename = "type")]
#[serde(alias = "objectType")]
@ -150,10 +157,11 @@ pub struct Announce {
///
/// The origin can be used to identify the context from which the actor originated. The target
/// typically has no defined meaning.
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[derive(Clone, Debug, Default, Extensible, PropRefs, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[prop_refs(Activity)]
#[extension(ApObjectProperties)]
#[prop_refs(IntransitiveActivity)]
pub struct Arrive {
#[serde(rename = "type")]
@ -182,10 +190,11 @@ pub struct Arrive {
/// Blocking is a stronger form of Ignore. The typical use is to support social systems that allow
/// one user to block activities or content of other users. The target and origin typically have no
/// defined meaning.
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[derive(Clone, Debug, Default, Extensible, PropRefs, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[prop_refs(Activity)]
#[extension(ApObjectProperties)]
pub struct Block {
#[serde(rename = "type")]
#[serde(alias = "objectType")]
@ -209,10 +218,11 @@ pub struct Block {
}
/// Indicates that the actor has created the object.
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[derive(Clone, Debug, Default, Extensible, PropRefs, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[prop_refs(Activity)]
#[extension(ApObjectProperties)]
pub struct Create {
#[serde(rename = "type")]
#[serde(alias = "objectType")]
@ -238,10 +248,11 @@ pub struct Create {
/// Indicates that the actor has deleted the object.
///
/// If specified, the origin indicates the context from which the object was deleted.
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[derive(Clone, Debug, Default, Extensible, PropRefs, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[prop_refs(Activity)]
#[extension(ApObjectProperties)]
pub struct Delete {
#[serde(rename = "type")]
#[serde(alias = "objectType")]
@ -265,10 +276,11 @@ pub struct Delete {
}
/// Indicates that the actor dislikes the object.
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[derive(Clone, Debug, Default, Extensible, PropRefs, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[prop_refs(Activity)]
#[extension(ApObjectProperties)]
pub struct Dislike {
#[serde(rename = "type")]
#[serde(alias = "objectType")]
@ -295,10 +307,11 @@ pub struct Dislike {
///
/// Flagging is defined in the sense common to many social platforms as reporting content as being
/// inappropriate for any number of reasons.
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[derive(Clone, Debug, Default, Extensible, PropRefs, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[prop_refs(Activity)]
#[extension(ApObjectProperties)]
pub struct Flag {
#[serde(rename = "type")]
#[serde(alias = "objectType")]
@ -326,10 +339,11 @@ pub struct Flag {
/// Following is defined in the sense typically used within Social systems in which the actor is
/// interested in any activity performed by or on the object. The target and origin typically have
/// no defined meaning.
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[derive(Clone, Debug, Default, Extensible, PropRefs, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[prop_refs(Activity)]
#[extension(ApObjectProperties)]
pub struct Follow {
#[serde(rename = "type")]
#[serde(alias = "objectType")]
@ -355,10 +369,11 @@ pub struct Follow {
/// Indicates that the actor is ignoring the object.
///
/// The target and origin typically have no defined meaning.
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[derive(Clone, Debug, Default, Extensible, PropRefs, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[prop_refs(Activity)]
#[extension(ApObjectProperties)]
pub struct Ignore {
#[serde(rename = "type")]
#[serde(alias = "objectType")]
@ -383,10 +398,11 @@ pub struct Ignore {
/// A specialization of Offer in which the actor is extending an invitation for the object to the
/// target.
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[derive(Clone, Debug, Default, Extensible, PropRefs, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[prop_refs(Activity)]
#[extension(ApObjectProperties)]
pub struct Invite {
#[serde(rename = "type")]
#[serde(alias = "objectType")]
@ -412,10 +428,11 @@ pub struct Invite {
/// Indicates that the actor has joined the object.
///
/// The target and origin typically have no defined meaning
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[derive(Clone, Debug, Default, Extensible, PropRefs, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[prop_refs(Activity)]
#[extension(ApObjectProperties)]
pub struct Join {
#[serde(rename = "type")]
#[serde(alias = "objectType")]
@ -441,10 +458,11 @@ pub struct Join {
/// Indicates that the actor has left the object.
///
/// The target and origin typically have no meaning.
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[derive(Clone, Debug, Default, Extensible, PropRefs, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[prop_refs(Activity)]
#[extension(ApObjectProperties)]
pub struct Leave {
#[serde(rename = "type")]
#[serde(alias = "objectType")]
@ -470,10 +488,11 @@ pub struct Leave {
/// Indicates that the actor likes, recommends or endorses the object.
///
/// The target and origin typically have no defined meaning.
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[derive(Clone, Debug, Default, Extensible, PropRefs, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[prop_refs(Activity)]
#[extension(ApObjectProperties)]
pub struct Like {
#[serde(rename = "type")]
#[serde(alias = "objectType")]
@ -497,10 +516,11 @@ pub struct Like {
}
/// Indicates that the actor has listened to the object.
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[derive(Clone, Debug, Default, Extensible, PropRefs, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[prop_refs(Activity)]
#[extension(ApObjectProperties)]
pub struct Listen {
#[serde(rename = "type")]
#[serde(alias = "objectType")]
@ -526,10 +546,11 @@ pub struct Listen {
/// Indicates that the actor is offering the object.
///
/// If specified, the target indicates the entity to which the object is being offered.
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[derive(Clone, Debug, Default, Extensible, PropRefs, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[prop_refs(Activity)]
#[extension(ApObjectProperties)]
pub struct Offer {
#[serde(rename = "type")]
#[serde(alias = "objectType")]
@ -560,10 +581,11 @@ pub struct Offer {
///
/// Either of the anyOf and oneOf properties MAY be used to express possible answers, but a
/// Question object MUST NOT have both properties.
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[derive(Clone, Debug, Default, Extensible, PropRefs, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[prop_refs(Activity)]
#[extension(ApObjectProperties)]
#[prop_refs(IntransitiveActivity)]
pub struct Question {
#[serde(rename = "type")]
@ -588,10 +610,11 @@ pub struct Question {
}
/// Indicates that the actor has read the object.
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[derive(Clone, Debug, Default, Extensible, PropRefs, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[prop_refs(Activity)]
#[extension(ApObjectProperties)]
pub struct Read {
#[serde(rename = "type")]
#[serde(alias = "objectType")]
@ -617,10 +640,11 @@ pub struct Read {
/// Indicates that the actor is rejecting the object.
///
/// The target and origin typically have no defined meaning.
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[derive(Clone, Debug, Default, Extensible, PropRefs, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[prop_refs(Activity)]
#[extension(ApObjectProperties)]
pub struct Reject {
#[serde(rename = "type")]
#[serde(alias = "objectType")]
@ -646,10 +670,11 @@ pub struct Reject {
/// Indicates that the actor is removing the object.
///
/// If specified, the origin indicates the context from which the object is being removed.
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[derive(Clone, Debug, Default, Extensible, PropRefs, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[prop_refs(Activity)]
#[extension(ApObjectProperties)]
pub struct Remove {
#[serde(rename = "type")]
#[serde(alias = "objectType")]
@ -673,10 +698,11 @@ pub struct Remove {
}
/// A specialization of Accept indicating that the acceptance is tentative.
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[derive(Clone, Debug, Default, Extensible, PropRefs, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[prop_refs(Activity)]
#[extension(ApObjectProperties)]
pub struct TentativeAccept {
#[serde(rename = "type")]
#[serde(alias = "objectType")]
@ -700,10 +726,11 @@ pub struct TentativeAccept {
}
/// A specialization of Reject in which the rejection is considered tentative.
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[derive(Clone, Debug, Default, Extensible, PropRefs, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[prop_refs(Activity)]
#[extension(ApObjectProperties)]
pub struct TentativeReject {
#[serde(rename = "type")]
#[serde(alias = "objectType")]
@ -730,10 +757,11 @@ pub struct TentativeReject {
///
/// Travel is an IntransitiveObject whose actor specifies the direct object. If the target or
/// origin are not specified, either can be determined by context.
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[derive(Clone, Debug, Default, Extensible, PropRefs, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[prop_refs(Activity)]
#[extension(ApObjectProperties)]
#[prop_refs(IntransitiveActivity)]
pub struct Travel {
#[serde(rename = "type")]
@ -764,10 +792,11 @@ pub struct Travel {
/// choose to undo that like at some later point in time).
///
/// The target and origin typically have no defined meaning.
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[derive(Clone, Debug, Default, Extensible, PropRefs, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[prop_refs(Activity)]
#[extension(ApObjectProperties)]
pub struct Undo {
#[serde(rename = "type")]
#[serde(alias = "objectType")]
@ -796,10 +825,11 @@ pub struct Undo {
/// of modifications made to object.
///
/// The target and origin typically have no defined meaning.
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[derive(Clone, Debug, Default, Extensible, PropRefs, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[prop_refs(Activity)]
#[extension(ApObjectProperties)]
pub struct Update {
#[serde(rename = "type")]
#[serde(alias = "objectType")]
@ -823,10 +853,11 @@ pub struct Update {
}
/// Indicates that the actor has viewed the object.
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[derive(Clone, Debug, Default, Extensible, PropRefs, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[prop_refs(Activity)]
#[extension(ApObjectProperties)]
pub struct View {
#[serde(rename = "type")]
#[serde(alias = "objectType")]

View file

@ -1,153 +0,0 @@
/*
* This file is part of ActivityStreams.
*
* Copyright © 2020 Riley Trautman
*
* ActivityStreams is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ActivityStreams is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ActivityStreams. If not, see <http://www.gnu.org/licenses/>.
*/
use crate::{
actor::{kind::*, properties::*, Actor, ActorBox},
object::{
properties::{ApObjectProperties, ObjectProperties},
Object, ObjectBox,
},
PropRefs,
};
use serde::{Deserialize, Serialize};
/// Describes a software application.
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[prop_refs(Actor)]
pub struct Application {
#[serde(rename = "type")]
kind: ApplicationType,
/// Adds all valid object properties to this struct
#[serde(flatten)]
#[prop_refs]
pub object_props: ObjectProperties,
/// Adds all valid activitypub object properties to this struct
#[serde(flatten)]
#[prop_refs]
pub ap_object_props: ApObjectProperties,
/// Adds all valid activitypub actor properties to this struct
#[serde(flatten)]
#[prop_refs]
pub ap_actor_props: ApActorProperties,
}
/// Represents a formal or informal collective of Actors.
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[prop_refs(Actor)]
pub struct Group {
#[serde(rename = "type")]
kind: GroupType,
/// Adds all valid object properties to this struct
#[serde(flatten)]
#[prop_refs]
pub object_props: ObjectProperties,
/// Adds all valid activitypub object properties to this struct
#[serde(flatten)]
#[prop_refs]
pub ap_object_props: ApObjectProperties,
/// Adds all valid activitypub actor properties to this struct
#[serde(flatten)]
#[prop_refs]
pub ap_actor_props: ApActorProperties,
}
/// Represents an organization.
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[prop_refs(Actor)]
pub struct Organization {
#[serde(rename = "type")]
kind: OrganizationType,
/// Adds all valid object properties to this struct
#[serde(flatten)]
#[prop_refs]
pub object_props: ObjectProperties,
/// Adds all valid activitypub object properties to this struct
#[serde(flatten)]
#[prop_refs]
pub ap_object_props: ApObjectProperties,
/// Adds all valid activitypub actor properties to this struct
#[serde(flatten)]
#[prop_refs]
pub ap_actor_props: ApActorProperties,
}
/// Represents an individual person.
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[prop_refs(Actor)]
pub struct Person {
#[serde(rename = "type")]
kind: PersonType,
/// Adds all valid object properties to this struct
#[serde(flatten)]
#[prop_refs]
pub object_props: ObjectProperties,
/// Adds all valid activitypub object properties to this struct
#[serde(flatten)]
#[prop_refs]
pub ap_object_props: ApObjectProperties,
/// Adds all valid activitypub actor properties to this struct
#[serde(flatten)]
#[prop_refs]
pub ap_actor_props: ApActorProperties,
}
/// Represents a service of any kind.
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[prop_refs(Actor)]
pub struct Service {
#[serde(rename = "type")]
kind: ServiceType,
/// Adds all valid object properties to this struct
#[serde(flatten)]
#[prop_refs]
pub object_props: ObjectProperties,
/// Adds all valid activitypub object properties to this struct
#[serde(flatten)]
#[prop_refs]
pub ap_object_props: ApObjectProperties,
/// Adds all valid activitypub actor properties to this struct
#[serde(flatten)]
#[prop_refs]
pub ap_actor_props: ApActorProperties,
}

View file

@ -19,19 +19,17 @@
//! Namespace for Actor types
#[cfg(feature = "types")]
pub mod apub;
#[cfg(feature = "kinds")]
pub mod kind;
#[cfg(feature = "types")]
pub mod properties;
#[cfg(feature = "types")]
pub mod streams;
use crate::object::Object;
mod types;
#[cfg(feature = "types")]
use crate::wrapper_type;
pub use self::types::{Application, Group, Organization, Person, Service};
use crate::object::Object;
/// `Actor` types are `Object` types that are capable of performing activities.
///
@ -52,5 +50,5 @@ use crate::wrapper_type;
/// (e.g. VCard) define their own types for describing people. An implementation that wishes, for
/// example, to use a `vcard:Individual` as an `Actor` MUST also identify that `Actor` as a
/// `Person`.
#[cfg_attr(feature = "types", wrapper_type)]
#[cfg_attr(feature = "derive", crate::wrapper_type)]
pub trait Actor: Object {}

View file

@ -63,11 +63,15 @@
//! ```
use crate::{
actor::Actor,
endpoint::EndpointProperties,
ext::Extension,
primitives::{XsdAnyUri, XsdString},
properties,
};
impl<T> Extension<T> for ApActorProperties where T: Actor {}
properties! {
ApActor {
docs [

View file

@ -18,17 +18,22 @@
*/
use crate::{
actor::{kind::*, Actor, ActorBox},
object::{properties::ObjectProperties, Object, ObjectBox},
PropRefs,
actor::{kind::*, properties::ApActorProperties, Actor, ActorBox},
ext::Ext,
object::{
properties::{ApObjectProperties, ObjectProperties},
Object, ObjectBox,
},
Base, Extensible, PropRefs,
};
use serde::{Deserialize, Serialize};
/// Describes a software application.
#[derive(Clone, Debug, Default, Deserialize, PropRefs, Serialize)]
#[derive(Clone, Debug, Default, Extensible, PropRefs, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[prop_refs(Actor)]
#[extension(ApObjectProperties)]
#[extension(ApActorProperties)]
pub struct Application {
#[serde(rename = "type")]
#[serde(alias = "objectType")]
@ -42,10 +47,12 @@ pub struct Application {
}
/// Represents a formal or informal collective of Actors.
#[derive(Clone, Debug, Default, Deserialize, PropRefs, Serialize)]
#[derive(Clone, Debug, Default, Extensible, PropRefs, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[prop_refs(Actor)]
#[extension(ApObjectProperties)]
#[extension(ApActorProperties)]
pub struct Group {
#[serde(rename = "type")]
#[serde(alias = "objectType")]
@ -59,7 +66,7 @@ pub struct Group {
}
/// Represents an organization.
#[derive(Clone, Debug, Default, Deserialize, PropRefs, Serialize)]
#[derive(Clone, Debug, Default, Extensible, PropRefs, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Organization {
#[serde(rename = "type")]
@ -74,10 +81,12 @@ pub struct Organization {
}
/// Represents an individual person.
#[derive(Clone, Debug, Default, Deserialize, PropRefs, Serialize)]
#[derive(Clone, Debug, Default, Extensible, PropRefs, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[prop_refs(Actor)]
#[extension(ApObjectProperties)]
#[extension(ApActorProperties)]
pub struct Person {
#[serde(rename = "type")]
#[serde(alias = "objectType")]
@ -91,10 +100,12 @@ pub struct Person {
}
/// Represents a service of any kind.
#[derive(Clone, Debug, Default, Deserialize, PropRefs, Serialize)]
#[derive(Clone, Debug, Default, Extensible, PropRefs, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[prop_refs(Actor)]
#[extension(ApObjectProperties)]
#[extension(ApActorProperties)]
pub struct Service {
#[serde(rename = "type")]
#[serde(alias = "objectType")]

View file

@ -1,150 +0,0 @@
/*
* This file is part of ActivityStreams.
*
* Copyright © 2020 Riley Trautman
*
* ActivityStreams is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ActivityStreams is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ActivityStreams. If not, see <http://www.gnu.org/licenses/>.
*/
//! Collection traits and types
use crate::{
collection::{
kind::*, properties::*, Collection, CollectionBox, CollectionPage, CollectionPageBox,
},
object::{
properties::{ApObjectProperties, ObjectProperties},
Object, ObjectBox,
},
PropRefs,
};
use serde::{Deserialize, Serialize};
/// The default `Collection` type.
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[prop_refs(Collection)]
pub struct UnorderedCollection {
#[serde(rename = "type")]
kind: CollectionType,
/// Adds all valid object properties to this struct
#[serde(flatten)]
#[prop_refs]
pub object_props: ObjectProperties,
/// Adds all valid ap object properties to this struct
#[serde(flatten)]
#[prop_refs]
pub ap_object_props: ApObjectProperties,
/// Adds all valid collection properties to this struct
#[serde(flatten)]
#[prop_refs]
pub collection_props: CollectionProperties,
}
/// Used to represent distinct subsets of items from a `Collection`.
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[prop_refs(Collection)]
#[prop_refs(CollectionPage)]
pub struct UnorderedCollectionPage {
#[serde(rename = "type")]
kind: CollectionPageType,
/// Adds all valid object properties to this struct
#[serde(flatten)]
#[prop_refs]
pub object_props: ObjectProperties,
/// Adds all valid ap object properties to this struct
#[serde(flatten)]
#[prop_refs]
pub ap_object_props: ApObjectProperties,
/// Adds all valid collection properties to this struct
#[serde(flatten)]
#[prop_refs]
pub collection_props: CollectionProperties,
/// Adds all valid collection page properties to this struct
#[serde(flatten)]
#[prop_refs]
pub collection_page_props: CollectionPageProperties,
}
/// A subtype of `Collection` in which members of the logical collection are assumed to always be
/// strictly ordered.
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[prop_refs(Collection)]
pub struct OrderedCollection {
#[serde(rename = "type")]
kind: OrderedCollectionType,
/// Adds all valid object properties to this struct
#[serde(flatten)]
#[prop_refs]
pub object_props: ObjectProperties,
/// Adds all valid ap object properties to this struct
#[serde(flatten)]
#[prop_refs]
pub ap_object_props: ApObjectProperties,
/// Adds all valid collection properties to this struct
#[serde(flatten)]
#[prop_refs]
pub collection_props: CollectionProperties,
}
/// Used to represent ordered subsets of items from an `OrderedCollection`.
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[prop_refs(Collection)]
#[prop_refs(CollectionPage)]
pub struct OrderedCollectionPage {
#[serde(rename = "type")]
kind: OrderedCollectionPageType,
/// Adds all valid object properties to this struct
#[serde(flatten)]
#[prop_refs]
pub object_props: ObjectProperties,
/// Adds all valid ap object properties to this struct
#[serde(flatten)]
#[prop_refs]
pub ap_object_props: ApObjectProperties,
/// Adds all valid collection properties to this struct
#[serde(flatten)]
#[prop_refs]
pub collection_props: CollectionProperties,
/// Adds all valid collection page properties to this struct
#[serde(flatten)]
#[prop_refs]
pub collection_page_props: CollectionPageProperties,
/// Adds all valid ordered collection page properties to this struct
#[serde(flatten)]
#[prop_refs]
pub ordered_collection_page_props: OrderedCollectionPageProperties,
}

View file

@ -19,20 +19,20 @@
//! Namespace for Collection types
#[cfg(feature = "types")]
pub mod apub;
#[cfg(feature = "kinds")]
pub mod kind;
#[cfg(feature = "types")]
pub mod properties;
#[cfg(feature = "types")]
pub mod streams;
mod types;
#[cfg(features = "types")]
pub use self::types::{
OrderedCollection, OrderedCollectionPage, UnorderedCollection, UnorderedCollectionPage,
};
use crate::object::Object;
#[cfg(feature = "types")]
use crate::wrapper_type;
/// A Collection is a subtype of `Object` that represents ordered or unordered sets of `Object` or
/// `Link` instances.
///
@ -43,7 +43,7 @@ use crate::wrapper_type;
///
/// `UnorderedCollection` and `OrderedCollection` types are provided by the `activitystreams-types`
/// crate.
#[cfg_attr(feature = "types", wrapper_type)]
#[cfg_attr(feature = "derive", crate::wrapper_type)]
pub trait Collection: Object {}
/// Used to represent distinct subsets of items from a Collection.
@ -55,5 +55,5 @@ pub trait Collection: Object {}
///
/// `UnorderedCollectionPage` and `OrderedCollectionPage` types are provied by the
/// `activitystreams-types` crate.
#[cfg_attr(feature = "types", wrapper_type)]
#[cfg_attr(feature = "derive", crate::wrapper_type)]
pub trait CollectionPage: Collection {}

View file

@ -34,7 +34,6 @@
//! PropRefs,
//! };
//! use serde::{Deserialize, Serialize};
//! use std::any::Any;
//!
//! #[derive(Clone, Debug, Serialize, Deserialize, PropRefs)]
//! #[serde(rename_all = "camelCase")]

View file

@ -23,16 +23,20 @@ use crate::{
collection::{
kind::*, properties::*, Collection, CollectionBox, CollectionPage, CollectionPageBox,
},
object::{properties::ObjectProperties, Object, ObjectBox},
PropRefs,
ext::Ext,
object::{
properties::{ApObjectProperties, ObjectProperties},
Object, ObjectBox,
},
Base, Extensible, PropRefs,
};
use serde::{Deserialize, Serialize};
/// The default `Collection` type.
#[derive(Clone, Debug, Default, Deserialize, PropRefs, Serialize)]
#[derive(Clone, Debug, Default, Extensible, PropRefs, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[prop_refs(Collection)]
#[extension(ApObjectProperties)]
pub struct UnorderedCollection {
#[serde(rename = "type")]
#[serde(alias = "objectType")]
@ -52,10 +56,11 @@ pub struct UnorderedCollection {
/// A subtype of `Collection` in which members of the logical collection are assumed to always be
/// strictly ordered.
#[derive(Clone, Debug, Default, Deserialize, PropRefs, Serialize)]
#[derive(Clone, Debug, Default, Extensible, PropRefs, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[prop_refs(Collection)]
#[extension(ApObjectProperties)]
pub struct OrderedCollection {
#[serde(rename = "type")]
#[serde(alias = "objectType")]
@ -74,11 +79,12 @@ pub struct OrderedCollection {
}
/// Used to represent distinct subsets of items from a `Collection`.
#[derive(Clone, Debug, Default, Deserialize, PropRefs, Serialize)]
#[derive(Clone, Debug, Default, Extensible, PropRefs, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[prop_refs(Collection)]
#[prop_refs(CollectionPage)]
#[extension(ApObjectProperties)]
pub struct UnorderedCollectionPage {
#[serde(rename = "type")]
#[serde(alias = "objectType")]
@ -102,11 +108,12 @@ pub struct UnorderedCollectionPage {
}
/// Used to represent ordered subsets of items from an `OrderedCollection`.
#[derive(Clone, Debug, Default, Deserialize, PropRefs, Serialize)]
#[derive(Clone, Debug, Default, Extensible, PropRefs, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[prop_refs(Collection)]
#[prop_refs(CollectionPage)]
#[extension(ApObjectProperties)]
pub struct OrderedCollectionPage {
#[serde(rename = "type")]
#[serde(alias = "objectType")]

142
src/ext.rs Normal file
View file

@ -0,0 +1,142 @@
//! Defining extensibility in the ActivityStreams spec
use crate::{
activity::{Activity, IntransitiveActivity},
actor::Actor,
collection::{Collection, CollectionPage},
link::Link,
object::Object,
Base,
};
use std::fmt::Debug;
/// Defines an extension to an activitystreams object or link
///
/// This type provides two fields, the first field, `base`, should always the be base
/// ActivityStreams type. As long as `base` implements an ActivityStreams trait, Ext will also.
///
/// For example, the type `Ext<Video, HashMap<String, String>>` will implement the `Object` trait,
/// because `Video` implements that trait.
///
/// Additionally, some level of AsRef and AsMut have been derived for Ext. If type type
/// `Ext<Ext<Follow, SomeTime>, AnotherType>` exists, that will implement
/// `AsRef<ActivityProperties>` just like the innermost `Follow`. This only works for types
/// two levels deep, however.
#[derive(Clone, Debug, Default)]
#[cfg_attr(feature = "derive", derive(serde::Deserialize, serde::Serialize))]
pub struct Ext<T, U> {
/// The ActivityStreams base type, or another extension containing one
#[cfg_attr(feature = "derive", serde(flatten))]
pub base: T,
/// The extension being applied to the type
#[cfg_attr(feature = "derive", serde(flatten))]
pub extension: U,
}
/// A trait implemented by extensions to the ActivityStreams specification
///
/// This is implemented for a couple types by default, such as
/// ApObjectProperties, and ApActorProperties.
///
/// Extensions are not intended to be used as trait objects
pub trait Extension<T>
where
T: Base,
{
/// A default implementation that simply returns the Ext type with Self and the base type
/// inside of it.
fn extends(self, base: T) -> Ext<T, Self>
where
Self: Sized,
{
Ext {
base,
extension: self,
}
}
}
/// A trait implemented (automatically) by objects and links in the ActivityStreams specification
///
/// This is used to easily extend objects.
///
/// ```rust
/// # use activitystreams::object::{Video, properties::ApObjectProperties};
/// use activitystreams::ext::Extensible;
/// let vid = Video::new();
/// let ap_props = ApObjectProperties::default();
///
/// let extended_vid = vid.extend(ap_props);
/// ```
pub trait Extensible<U> {
fn extend(self, extension: U) -> Ext<Self, U>
where
Self: Sized;
}
impl<T, U> Extensible<U> for T
where
T: crate::Base,
U: Extension<T>,
{
fn extend(self, item: U) -> Ext<Self, U> {
item.extends(self)
}
}
impl<T, U> Base for Ext<T, U>
where
T: Base,
U: Debug,
{
}
impl<T, U> Object for Ext<T, U>
where
T: Object,
U: Debug,
{
}
impl<T, U> Link for Ext<T, U>
where
T: Link,
U: Debug,
{
}
impl<T, U> Actor for Ext<T, U>
where
T: Actor,
U: Debug,
{
}
impl<T, U> Collection for Ext<T, U>
where
T: Collection,
U: Debug,
{
}
impl<T, U> CollectionPage for Ext<T, U>
where
T: CollectionPage,
U: Debug,
{
}
impl<T, U> Activity for Ext<T, U>
where
T: Activity,
U: Debug,
{
}
impl<T, U> IntransitiveActivity for Ext<T, U>
where
T: IntransitiveActivity,
U: Debug,
{
}

View file

@ -25,34 +25,27 @@
//!
//! First, add ActivityStreams to your dependencies
//! ```toml
//! activitystreams = "0.5.0-alpha.8"
//! activitystreams = "0.5.0-alpha.9"
//! ```
//!
//! ### Types
//!
//! The project is laid out by Kind => vocabulary => Type
//! The project is laid out by Kind => Type
//!
//! So to use an ActivityStreams Video, you'd write
//! ```rust
//! use activitystreams::object::streams::Video;
//! use activitystreams::object::Video;
//! ```
//!
//! And to use an ActivityPub profile, you'd write
//! And to use an ActivityStreams profile, you'd write
//! ```rust
//! use activitystreams::object::apub::Profile;
//! ```
//!
//! Link is a little different, since there's only one defined link type, called Mention.
//! ```rust
//! use activitystreams::link::Mention;
//! use activitystreams::object::Profile;
//! ```
//!
//! ### Properties
//!
//! Each concrete type implements `AsRef<>` for each of their properties fields. A basic
//! ActivityStreams object will implement `AsRef<ObjectProperties>`, while an ActivityPub Actor
//! might implement `AsRef<ObjectProperties>`, `AsRef<ApObjectProperties>`, and
//! `AsRef<ApActorProperties>`.
//! ActivityStreams object will implement `AsRef<ObjectProperties>`.
//!
//! The Properties types can be found near the kind they're associated with. `ObjectProperties` and
//! `ApObjectProperties` are located in `activitystreams::object::properties`.
@ -188,12 +181,35 @@
//! ```
//! And this type would only deserialize for JSON where `"type":"Person"`
//!
//! ### Extensions
//!
//! In some cases, like when dealing with ActivityPub, it is neccessary to extend the
//! ActivityStreams specification. For this purpose, two traits and a type have been introduced.
//!
//! ```ignore
//! use activitystreams::ext::{Ext, Extensible, Extension};
//! ```
//!
//! The `Ext` type is a simple record containing first, the ActivityStreams type, and second, the
//! extension to that type.
//!
//! There are two provided extensions in the ActivityStreams library.
//! - ApObjectProperties, extra properties for all ActivityStreams objects in the ActivityPub spec
//! - ApActorProperties, extra properties specifically for Actors in the ActivityPub spec
//!
//! To use an object with its default extensions, the object's `full()` associated function may be
//! invoked.
//! ```rust
//! # use activitystreams::object::Video;
//! let video_with_extensions = Video::full();
//! ```
//!
//! ### Features
//! There are a number of features that can be disabled in this crate. By default, everything is
//! enabled.
//!
//! ```toml
//! activitystreams = { version = "0.5.0-alpha.8", default-features = "false", features = ["derive"] }
//! activitystreams = { version = "0.5.0-alpha.9", default-features = "false", features = ["derive"] }
//! ```
//!
//! | feature | what you get |
@ -209,7 +225,7 @@
//! ### Basic
//!
//! ```rust
//! use activitystreams::object::{streams::Video, properties::ObjectProperties};
//! use activitystreams::object::{Video, properties::ObjectProperties};
//! use anyhow::Error;
//!
//! // We perform configuration in a dedicated function to specify which Properties type we want to
@ -256,7 +272,7 @@
//! ObjectProperties,
//! ProfileProperties
//! },
//! apub::Profile,
//! Profile,
//! Object,
//! ObjectBox,
//! },
@ -279,7 +295,7 @@
//! }
//!
//! fn main() -> Result<(), anyhow::Error> {
//! let mut profile = Profile::default();
//! let mut profile = Profile::full();
//!
//! let pprops: &mut ProfileProperties = profile.as_mut();
//!
@ -379,6 +395,7 @@ pub mod actor;
pub mod collection;
#[cfg(feature = "types")]
pub mod endpoint;
pub mod ext;
pub mod link;
pub mod object;
#[cfg(feature = "primitives")]
@ -392,11 +409,28 @@ pub use self::{
object::Object,
};
#[cfg_attr(feature = "types", wrapper_type)]
pub trait Base: std::fmt::Debug {}
#[cfg(feature = "primitives")]
/// The context associated with all of the Activity Streams types defined in the crate.
pub fn context() -> crate::primitives::XsdAnyUri {
"https://www.w3.org/ns/activitystreams".parse().unwrap()
}
#[cfg(feature = "primitives")]
/// The 'security' extension used by some implementations
pub fn security() -> crate::primitives::XsdAnyUri {
"https://w3id.org/security/v1".parse().unwrap()
}
#[cfg(feature = "primitives")]
/// The 'public' actor, doesn't denote a real actor but describes a publicly available object.
pub fn public() -> crate::primitives::XsdAnyUri {
"https://www.w3.org/ns/activitystreams#Public"
.parse()
.unwrap()
}
#[cfg(feature = "derive")]
pub use activitystreams_derive::{properties, wrapper_type, PropRefs, UnitString};
pub use activitystreams_derive::{properties, wrapper_type, Extensible, PropRefs, UnitString};

View file

@ -29,9 +29,6 @@ mod types;
#[cfg(feature = "types")]
pub use self::types::Mention;
#[cfg(feature = "types")]
use crate::wrapper_type;
/// A Link is an indirect, qualified reference to a resource identified by a URL.
///
/// The fundamental model for links is established by
@ -40,5 +37,5 @@ use crate::wrapper_type;
/// used, it establishes a qualified relation connecting the subject (the containing object) to the
/// resource identified by the href. Properties of the Link are properties of the reference as
/// opposed to properties of the resource.
#[cfg_attr(feature = "types", wrapper_type)]
pub trait Link: std::fmt::Debug {}
#[cfg_attr(feature = "derive", crate::wrapper_type)]
pub trait Link: crate::Base {}

View file

@ -30,7 +30,6 @@
//! PropRefs,
//! };
//! use serde::{Deserialize, Serialize};
//! use std::any::Any;
//!
//! #[derive(Clone, Debug, Serialize, Deserialize, PropRefs)]
//! #[serde(rename_all = "camelCase")]

View file

@ -18,14 +18,14 @@
*/
use crate::{
ext::Ext,
link::{kind::*, properties::*, Link, LinkBox},
PropRefs,
Base, PropRefs,
};
use serde::{Deserialize, Serialize};
#[cfg(feature = "types")]
/// A specialized Link that represents an @mention.
#[derive(Clone, Debug, Default, Deserialize, PropRefs, Serialize)]
#[derive(Clone, Debug, Default, PropRefs, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Link)]
pub struct Mention {

View file

@ -1,232 +0,0 @@
/*
* This file is part of ActivityStreams.
*
* Copyright © 2020 Riley Trautman
*
* ActivityStreams is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ActivityStreams is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ActivityStreams. If not, see <http://www.gnu.org/licenses/>.
*/
use crate::{
object::{kind::*, properties::*, Object, ObjectBox},
PropRefs,
};
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
pub struct Article {
#[serde(rename = "type")]
kind: ArticleType,
#[serde(flatten)]
#[prop_refs]
pub object_props: ObjectProperties,
#[serde(flatten)]
#[prop_refs]
pub ap_object_props: ApObjectProperties,
}
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
pub struct Audio {
#[serde(rename = "type")]
kind: AudioType,
#[serde(flatten)]
#[prop_refs]
pub object_props: ObjectProperties,
#[serde(flatten)]
#[prop_refs]
pub ap_object_props: ApObjectProperties,
}
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
pub struct Document {
#[serde(rename = "type")]
kind: DocumentType,
#[serde(flatten)]
#[prop_refs]
pub object_props: ObjectProperties,
#[serde(flatten)]
#[prop_refs]
pub ap_object_props: ApObjectProperties,
}
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
pub struct Event {
#[serde(rename = "type")]
kind: EventType,
#[serde(flatten)]
#[prop_refs]
pub object_props: ObjectProperties,
#[serde(flatten)]
#[prop_refs]
pub ap_object_props: ApObjectProperties,
}
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
pub struct Image {
#[serde(rename = "type")]
kind: ImageType,
#[serde(flatten)]
#[prop_refs]
pub object_props: ObjectProperties,
#[serde(flatten)]
#[prop_refs]
pub ap_object_props: ApObjectProperties,
}
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
pub struct Note {
#[serde(rename = "type")]
kind: NoteType,
#[serde(flatten)]
#[prop_refs]
pub object_props: ObjectProperties,
#[serde(flatten)]
#[prop_refs]
pub ap_object_props: ApObjectProperties,
}
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
pub struct Page {
#[serde(rename = "type")]
kind: PageType,
#[serde(flatten)]
#[prop_refs]
pub object_props: ObjectProperties,
#[serde(flatten)]
#[prop_refs]
pub ap_object_props: ApObjectProperties,
}
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
pub struct Place {
#[serde(rename = "type")]
kind: PlaceType,
#[serde(flatten)]
#[prop_refs]
pub object_props: ObjectProperties,
#[serde(flatten)]
#[prop_refs]
pub ap_object_props: ApObjectProperties,
#[serde(flatten)]
#[prop_refs]
pub place_props: PlaceProperties,
}
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
pub struct Profile {
#[serde(rename = "type")]
kind: ProfileType,
#[serde(flatten)]
#[prop_refs]
pub object_props: ObjectProperties,
#[serde(flatten)]
#[prop_refs]
pub ap_object_props: ApObjectProperties,
#[serde(flatten)]
#[prop_refs]
pub profile_props: ProfileProperties,
}
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
pub struct Relationship {
#[serde(rename = "type")]
kind: RelationshipType,
#[serde(flatten)]
#[prop_refs]
pub object_props: ObjectProperties,
#[serde(flatten)]
#[prop_refs]
pub ap_object_props: ApObjectProperties,
#[serde(flatten)]
#[prop_refs]
pub relationship_props: RelationshipProperties,
}
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
pub struct Tombstone {
#[serde(rename = "type")]
kind: TombstoneType,
#[serde(flatten)]
#[prop_refs]
pub object_props: ObjectProperties,
#[serde(flatten)]
#[prop_refs]
pub ap_object_props: ApObjectProperties,
#[serde(flatten)]
#[prop_refs]
pub tombstone_props: TombstoneProperties,
}
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
pub struct Video {
#[serde(rename = "type")]
kind: VideoType,
#[serde(flatten)]
#[prop_refs]
pub object_props: ObjectProperties,
#[serde(flatten)]
#[prop_refs]
pub ap_object_props: ApObjectProperties,
}

View file

@ -19,25 +19,26 @@
//! Namespace for Object types
#[cfg(feature = "types")]
pub mod apub;
#[cfg(feature = "kinds")]
pub mod kind;
#[cfg(feature = "types")]
pub mod properties;
#[cfg(feature = "types")]
pub mod streams;
mod types;
#[cfg(feature = "types")]
use crate::wrapper_type;
pub use self::types::{
Article, Audio, Document, Event, Image, Note, Page, Place, Profile, Relationship, Tombstone,
Video,
};
/// Describes an object of any kind.
///
/// The Object type serves as the base type for most of the other kinds of objects defined in the
/// Activity Vocabulary, including other Core types such as `Activity`, `IntransitiveActivity`,
/// `Collection` and `OrderedCollection`.
#[cfg_attr(feature = "types", wrapper_type)]
pub trait Object: std::fmt::Debug {}
#[cfg_attr(feature = "derive", crate::wrapper_type)]
pub trait Object: crate::Base {}
#[cfg(feature = "types")]
/// Describes any kind of Image
@ -47,6 +48,7 @@ pub trait Object: std::fmt::Debug {}
/// deserialized, but allows any adjacent fields through
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
pub struct AnyImage {
#[serde(rename = "type")]
kind: self::kind::ImageType,
#[serde(flatten)]

View file

@ -27,10 +27,9 @@
//! properties::ObjectProperties,
//! Object, ObjectBox,
//! },
//! PropRefs,
//! Base, BaseBox, PropRefs,
//! };
//! use serde::{Deserialize, Serialize};
//! use std::any::Any;
//!
//! #[derive(Clone, Debug, Serialize, Deserialize, PropRefs)]
//! #[serde(rename_all = "camelCase")]
@ -51,12 +50,15 @@
//! ```
use crate::{
ext::Extension,
link::LinkBox,
object::{AnyImage, ObjectBox},
object::{AnyImage, Object, ObjectBox},
primitives::*,
properties,
properties, BaseBox,
};
impl<T> Extension<T> for ApObjectProperties where T: Object {}
properties! {
Object {
docs [
@ -103,8 +105,7 @@ properties! {
],
types [
XsdAnyUri,
ObjectBox,
LinkBox,
BaseBox,
],
},
@ -120,8 +121,7 @@ properties! {
],
types [
XsdAnyUri,
ObjectBox,
LinkBox,
BaseBox,
],
},
@ -135,8 +135,7 @@ properties! {
],
types [
XsdAnyUri,
ObjectBox,
LinkBox,
BaseBox,
],
},
@ -171,8 +170,7 @@ properties! {
],
types [
XsdAnyUri,
ObjectBox,
LinkBox,
BaseBox,
],
rename("@context"),
},
@ -219,8 +217,7 @@ properties! {
],
types [
XsdAnyUri,
ObjectBox,
LinkBox,
BaseBox,
],
},
@ -266,8 +263,7 @@ properties! {
],
types [
XsdAnyUri,
ObjectBox,
LinkBox,
BaseBox,
],
},
@ -280,8 +276,7 @@ properties! {
],
types [
XsdAnyUri,
ObjectBox,
LinkBox,
BaseBox,
],
},
@ -294,8 +289,7 @@ properties! {
],
types [
XsdAnyUri,
ObjectBox,
LinkBox,
BaseBox,
],
},
@ -321,8 +315,7 @@ properties! {
],
types [
XsdAnyUri,
ObjectBox,
LinkBox,
BaseBox,
],
},
@ -370,8 +363,7 @@ properties! {
],
types [
XsdAnyUri,
ObjectBox,
LinkBox,
BaseBox,
],
},
@ -410,8 +402,7 @@ properties! {
],
types [
XsdAnyUri,
ObjectBox,
LinkBox,
BaseBox,
],
},
@ -424,8 +415,7 @@ properties! {
],
types [
XsdAnyUri,
ObjectBox,
LinkBox,
BaseBox,
],
},
@ -438,8 +428,7 @@ properties! {
],
types [
XsdAnyUri,
ObjectBox,
LinkBox,
BaseBox,
],
},
@ -453,8 +442,7 @@ properties! {
],
types [
XsdAnyUri,
ObjectBox,
LinkBox,
BaseBox,
],
},
@ -627,8 +615,7 @@ properties! {
],
types [
XsdAnyUri,
ObjectBox,
LinkBox,
BaseBox,
],
functional,
},
@ -642,8 +629,7 @@ properties! {
],
types [
XsdAnyUri,
ObjectBox,
LinkBox,
BaseBox,
],
},

View file

@ -18,15 +18,16 @@
*/
use crate::{
ext::Ext,
object::{kind::*, properties::*, Object, ObjectBox},
PropRefs,
Base, Extensible, PropRefs,
};
use serde::{Deserialize, Serialize};
/// Represents any kind of multi-paragraph written work.
#[derive(Clone, Debug, Default, Deserialize, PropRefs, Serialize)]
#[derive(Clone, Debug, Default, Extensible, PropRefs, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[extension(ApObjectProperties)]
pub struct Article {
#[serde(rename = "type")]
#[serde(alias = "objectType")]
@ -40,9 +41,10 @@ pub struct Article {
}
/// Represents an audio document of any kind.
#[derive(Clone, Debug, Default, Deserialize, PropRefs, Serialize)]
#[derive(Clone, Debug, Default, Extensible, PropRefs, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[extension(ApObjectProperties)]
pub struct Audio {
#[serde(rename = "type")]
#[serde(alias = "objectType")]
@ -56,9 +58,10 @@ pub struct Audio {
}
/// Represents a document of any kind.
#[derive(Clone, Debug, Default, Deserialize, PropRefs, Serialize)]
#[derive(Clone, Debug, Default, Extensible, PropRefs, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[extension(ApObjectProperties)]
pub struct Document {
#[serde(rename = "type")]
#[serde(alias = "objectType")]
@ -72,9 +75,10 @@ pub struct Document {
}
/// Represents any kind of event.
#[derive(Clone, Debug, Default, Deserialize, PropRefs, Serialize)]
#[derive(Clone, Debug, Default, Extensible, PropRefs, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[extension(ApObjectProperties)]
pub struct Event {
#[serde(rename = "type")]
#[serde(alias = "objectType")]
@ -88,9 +92,10 @@ pub struct Event {
}
/// An image document of any kind
#[derive(Clone, Debug, Default, Deserialize, PropRefs, Serialize)]
#[derive(Clone, Debug, Default, Extensible, PropRefs, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[extension(ApObjectProperties)]
pub struct Image {
#[serde(rename = "type")]
#[serde(alias = "objectType")]
@ -104,9 +109,10 @@ pub struct Image {
}
/// Represents a short written work typically less than a single paragraph in length.
#[derive(Clone, Debug, Default, Deserialize, PropRefs, Serialize)]
#[derive(Clone, Debug, Default, Extensible, PropRefs, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[extension(ApObjectProperties)]
pub struct Note {
#[serde(rename = "type")]
#[serde(alias = "objectType")]
@ -120,9 +126,10 @@ pub struct Note {
}
/// Represents a Web Page.
#[derive(Clone, Debug, Default, Deserialize, PropRefs, Serialize)]
#[derive(Clone, Debug, Default, Extensible, PropRefs, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[extension(ApObjectProperties)]
pub struct Page {
#[serde(rename = "type")]
#[serde(alias = "objectType")]
@ -153,9 +160,10 @@ pub struct Page {
/// While publishers are not required to use these specific properties and MAY make use of other
/// mechanisms for describing locations, consuming implementations that support the Place object
/// MUST support the use of these properties.
#[derive(Clone, Debug, Default, Deserialize, PropRefs, Serialize)]
#[derive(Clone, Debug, Default, Extensible, PropRefs, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[extension(ApObjectProperties)]
pub struct Place {
#[serde(rename = "type")]
#[serde(alias = "objectType")]
@ -177,9 +185,10 @@ pub struct Place {
/// `Actor` Type objects.
///
/// The `describes` property is used to reference the object being described by the profile.
#[derive(Clone, Debug, Default, Deserialize, PropRefs, Serialize)]
#[derive(Clone, Debug, Default, Extensible, PropRefs, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[extension(ApObjectProperties)]
pub struct Profile {
#[serde(rename = "type")]
#[serde(alias = "objectType")]
@ -211,9 +220,10 @@ pub struct Profile {
/// individuals that are directly connected within a person's social graph. Suppose we have a user,
/// Sally, with direct relationships to users Joe and Jane. Sally follows Joe's updates while Sally
/// and Jane have a mutual relationship.
#[derive(Clone, Debug, Default, Deserialize, PropRefs, Serialize)]
#[derive(Clone, Debug, Default, Extensible, PropRefs, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[extension(ApObjectProperties)]
pub struct Relationship {
#[serde(rename = "type")]
#[serde(alias = "objectType")]
@ -235,9 +245,10 @@ pub struct Relationship {
///
/// It can be used in Collections to signify that there used to be an object at this position, but
/// it has been deleted.
#[derive(Clone, Debug, Default, Deserialize, PropRefs, Serialize)]
#[derive(Clone, Debug, Default, Extensible, PropRefs, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[extension(ApObjectProperties)]
pub struct Tombstone {
#[serde(rename = "type")]
#[serde(alias = "objectType")]
@ -256,9 +267,10 @@ pub struct Tombstone {
}
/// Represents a video document of any kind.
#[derive(Clone, Debug, Default, Deserialize, PropRefs, Serialize)]
#[derive(Clone, Debug, Default, Extensible, PropRefs, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
#[extension(ApObjectProperties)]
pub struct Video {
#[serde(rename = "type")]
#[serde(alias = "objectType")]