Remove extension traits

This commit is contained in:
asonix 2020-03-10 17:26:04 -05:00
parent a958b17f90
commit 119baceffa
43 changed files with 57 additions and 156 deletions

View file

@ -110,8 +110,7 @@ use syn::{
/// #[activitystreams(None)]
/// my_field: MyProperties,
///
/// /// Derive the above, plus Object (activitystreams-traits) and ObjectExt
/// /// (activitystreams-types)
/// /// Derive the above, plus Object (activitystreams-traits)
/// #[activitystreams(Object)]
/// obj_field: ObjectProperties,
/// }
@ -158,7 +157,6 @@ pub fn ref_derive(input: TokenStream) -> TokenStream {
.flat_map(move |(ident, ty, attr)| {
let object = from_value(attr);
let name = name.clone();
let ext_trait = Ident::new(&format!("{}Ext", object), name.span());
let base_impl = if object.to_string() == "Object" || object.to_string() == "Link" {
quote! {
@ -183,20 +181,6 @@ pub fn ref_derive(input: TokenStream) -> TokenStream {
}
};
let activity_impls = quote! {
#base_impl
impl #ext_trait for #name {
fn props(&self) -> &#ty {
self.as_ref()
}
fn props_mut(&mut self) -> &mut #ty {
self.as_mut()
}
}
};
let ref_impls = quote! {
impl AsRef<#ty> for #name {
fn as_ref(&self) -> &#ty {
@ -216,7 +200,7 @@ pub fn ref_derive(input: TokenStream) -> TokenStream {
} else {
quote! {
#ref_impls
#activity_impls
#base_impl
}
}
})

View file

@ -24,9 +24,8 @@ use serde::{Deserialize, Serialize};
use super::{
kind::AcceptType,
properties::{AcceptProperties, ActivityProperties},
ActivityExt,
};
use crate::object::{properties::ObjectProperties, ObjectExt};
use crate::object::properties::ObjectProperties;
/// Indicates that the actor accepts the object.
///

View file

@ -24,9 +24,8 @@ use serde::{Deserialize, Serialize};
use super::{
kind::AddType,
properties::{ActivityProperties, AddProperties},
ActivityExt,
};
use crate::object::{properties::ObjectProperties, ObjectExt};
use crate::object::properties::ObjectProperties;
/// Indicates that the actor has added the object to the target.
///

View file

@ -24,9 +24,8 @@ use serde::{Deserialize, Serialize};
use super::{
kind::MoveType,
properties::{ActivityProperties, MoveProperties},
ActivityExt,
};
use crate::object::{properties::ObjectProperties, ObjectExt};
use crate::object::properties::ObjectProperties;
/// Indicates that the actor has moved object from origin to target.
///

View file

@ -24,9 +24,8 @@ use serde::{Deserialize, Serialize};
use super::{
kind::AnnounceType,
properties::{ActivityProperties, AnnounceProperties},
ActivityExt,
};
use crate::object::{properties::ObjectProperties, ObjectExt};
use crate::object::properties::ObjectProperties;
/// Indicates that the actor is calling the target's attention the object.
///

View file

@ -24,9 +24,8 @@ use serde::{Deserialize, Serialize};
use super::{
kind::ArriveType,
properties::{ActivityProperties, ArriveProperties},
ActivityExt,
};
use crate::object::{properties::ObjectProperties, ObjectExt};
use crate::object::properties::ObjectProperties;
/// An IntransitiveActivity that indicates that the actor has arrived at the location.
///

View file

@ -24,9 +24,8 @@ use serde::{Deserialize, Serialize};
use super::{
kind::BlockType,
properties::{ActivityProperties, BlockProperties},
ActivityExt,
};
use crate::object::{properties::ObjectProperties, ObjectExt};
use crate::object::properties::ObjectProperties;
/// Indicates that the actor is blocking the object.
///

View file

@ -24,9 +24,8 @@ use serde::{Deserialize, Serialize};
use super::{
kind::CreateType,
properties::{ActivityProperties, CreateProperties},
ActivityExt,
};
use crate::object::{properties::ObjectProperties, ObjectExt};
use crate::object::properties::ObjectProperties;
/// Indicates that the actor has created the object.
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]

View file

@ -24,9 +24,8 @@ use serde::{Deserialize, Serialize};
use super::{
kind::DeleteType,
properties::{ActivityProperties, DeleteProperties},
ActivityExt,
};
use crate::object::{properties::ObjectProperties, ObjectExt};
use crate::object::properties::ObjectProperties;
/// Indicates that the actor has deleted the object.
///

View file

@ -24,9 +24,8 @@ use serde::{Deserialize, Serialize};
use super::{
kind::DislikeType,
properties::{ActivityProperties, DislikeProperties},
ActivityExt,
};
use crate::object::{properties::ObjectProperties, ObjectExt};
use crate::object::properties::ObjectProperties;
/// Indicates that the actor dislikes the object.
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]

View file

@ -24,9 +24,8 @@ use serde::{Deserialize, Serialize};
use super::{
kind::FlagType,
properties::{ActivityProperties, FlagProperties},
ActivityExt,
};
use crate::object::{properties::ObjectProperties, ObjectExt};
use crate::object::properties::ObjectProperties;
/// Indicates that the actor is "flagging" the object.
///

View file

@ -24,9 +24,8 @@ use serde::{Deserialize, Serialize};
use super::{
kind::FollowType,
properties::{ActivityProperties, FollowProperties},
ActivityExt,
};
use crate::object::{properties::ObjectProperties, ObjectExt};
use crate::object::properties::ObjectProperties;
/// Indicates that the actor is "following" the object.
///

View file

@ -24,9 +24,8 @@ use serde::{Deserialize, Serialize};
use super::{
kind::IgnoreType,
properties::{ActivityProperties, IgnoreProperties},
ActivityExt,
};
use crate::object::{properties::ObjectProperties, ObjectExt};
use crate::object::properties::ObjectProperties;
/// Indicates that the actor is ignoring the object.
///

View file

@ -24,9 +24,8 @@ use serde::{Deserialize, Serialize};
use super::{
kind::InviteType,
properties::{ActivityProperties, InviteProperties},
ActivityExt,
};
use crate::object::{properties::ObjectProperties, ObjectExt};
use crate::object::properties::ObjectProperties;
/// A specialization of Offer in which the actor is extending an invitation for the object to the
/// target.

View file

@ -24,9 +24,8 @@ use serde::{Deserialize, Serialize};
use super::{
kind::JoinType,
properties::{ActivityProperties, JoinProperties},
ActivityExt,
};
use crate::object::{properties::ObjectProperties, ObjectExt};
use crate::object::properties::ObjectProperties;
/// Indicates that the actor has joined the object.
///

View file

@ -24,9 +24,8 @@ use serde::{Deserialize, Serialize};
use super::{
kind::LeaveType,
properties::{ActivityProperties, LeaveProperties},
ActivityExt,
};
use crate::object::{properties::ObjectProperties, ObjectExt};
use crate::object::properties::ObjectProperties;
/// Indicates that the actor has left the object.
///

View file

@ -24,9 +24,8 @@ use serde::{Deserialize, Serialize};
use super::{
kind::LikeType,
properties::{ActivityProperties, LikeProperties},
ActivityExt,
};
use crate::object::{properties::ObjectProperties, ObjectExt};
use crate::object::properties::ObjectProperties;
/// Indicates that the actor likes, recommends or endorses the object.
///

View file

@ -24,9 +24,8 @@ use serde::{Deserialize, Serialize};
use super::{
kind::ListenType,
properties::{ActivityProperties, ListenProperties},
ActivityExt,
};
use crate::object::{properties::ObjectProperties, ObjectExt};
use crate::object::properties::ObjectProperties;
/// Indicates that the actor has listened to the object.
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]

View file

@ -49,20 +49,10 @@ mod update;
mod view;
pub use self::{
accept::*, add::*, amove::*, announce::*, arrive::*, block::*, create::*, delete::*,
dislike::*, flag::*, follow::*, ignore::*, invite::*, join::*, leave::*, like::*, listen::*,
offer::*, question::*, read::*, reject::*, remove::*, tentative_accept::*, tentative_reject::*,
travel::*, undo::*, update::*, view::*,
accept::Accept, add::Add, amove::AMove, announce::Announce, arrive::Arrive, block::Block,
create::Create, delete::Delete, dislike::Dislike, flag::Flag, follow::Follow, ignore::Ignore,
invite::Invite, join::Join, leave::Leave, like::Like, listen::Listen, offer::Offer,
question::Question, read::Read, reject::Reject, remove::Remove,
tentative_accept::TentativeAccept, tentative_reject::TentativeReject, travel::Travel,
undo::Undo, update::Update, view::View,
};
use activitystreams_traits::Activity;
use self::properties::ActivityProperties;
/// The Activity Extension Trait
///
/// This trait provides generic access to an activity's properties
pub trait ActivityExt: Activity {
fn props(&self) -> &ActivityProperties;
fn props_mut(&mut self) -> &mut ActivityProperties;
}

View file

@ -24,9 +24,8 @@ use serde::{Deserialize, Serialize};
use super::{
kind::OfferType,
properties::{ActivityProperties, OfferProperties},
ActivityExt,
};
use crate::object::{properties::ObjectProperties, ObjectExt};
use crate::object::properties::ObjectProperties;
/// Indicates that the actor is offering the object.
///

View file

@ -24,14 +24,8 @@
//! use activitystreams_derive::PropRefs;
//! use activitystreams_traits::{Activity, Object};
//! use activitystreams_types::{
//! activity::{
//! properties::ActivityProperties,
//! ActivityExt,
//! },
//! object::{
//! properties::ObjectProperties,
//! ObjectExt,
//! },
//! activity::properties::ActivityProperties,
//! object::properties::ObjectProperties,
//! };
//! use serde::{Deserialize, Serialize};
//!

View file

@ -24,9 +24,8 @@ use serde::{Deserialize, Serialize};
use super::{
kind::QuestionType,
properties::{ActivityProperties, QuestionProperties},
ActivityExt,
};
use crate::object::{properties::ObjectProperties, ObjectExt};
use crate::object::properties::ObjectProperties;
/// Represents a question being asked.
///

View file

@ -24,9 +24,8 @@ use serde::{Deserialize, Serialize};
use super::{
kind::ReadType,
properties::{ActivityProperties, ReadProperties},
ActivityExt,
};
use crate::object::{properties::ObjectProperties, ObjectExt};
use crate::object::properties::ObjectProperties;
/// Indicates that the actor has read the object.
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]

View file

@ -24,9 +24,8 @@ use serde::{Deserialize, Serialize};
use super::{
kind::RejectType,
properties::{ActivityProperties, RejectProperties},
ActivityExt,
};
use crate::object::{properties::ObjectProperties, ObjectExt};
use crate::object::properties::ObjectProperties;
/// Indicates that the actor is rejecting the object.
///

View file

@ -24,9 +24,8 @@ use serde::{Deserialize, Serialize};
use super::{
kind::RemoveType,
properties::{ActivityProperties, RemoveProperties},
ActivityExt,
};
use crate::object::{properties::ObjectProperties, ObjectExt};
use crate::object::properties::ObjectProperties;
/// Indicates that the actor is removing the object.
///

View file

@ -24,9 +24,8 @@ use serde::{Deserialize, Serialize};
use super::{
kind::TentativeAcceptType,
properties::{ActivityProperties, TentativeAcceptProperties},
ActivityExt,
};
use crate::object::{properties::ObjectProperties, ObjectExt};
use crate::object::properties::ObjectProperties;
/// A specialization of Accept indicating that the acceptance is tentative.
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]

View file

@ -24,9 +24,8 @@ use serde::{Deserialize, Serialize};
use super::{
kind::TentativeRejectType,
properties::{ActivityProperties, TentativeRejectProperties},
ActivityExt,
};
use crate::object::{properties::ObjectProperties, ObjectExt};
use crate::object::properties::ObjectProperties;
/// A specialization of Reject in which the rejection is considered tentative.
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]

View file

@ -24,9 +24,8 @@ use serde::{Deserialize, Serialize};
use super::{
kind::TravelType,
properties::{ActivityProperties, TravelProperties},
ActivityExt,
};
use crate::object::{properties::ObjectProperties, ObjectExt};
use crate::object::properties::ObjectProperties;
/// Indicates that the actor is traveling to target from origin.
///

View file

@ -24,9 +24,8 @@ use serde::{Deserialize, Serialize};
use super::{
kind::UndoType,
properties::{ActivityProperties, UndoProperties},
ActivityExt,
};
use crate::object::{properties::ObjectProperties, ObjectExt};
use crate::object::properties::ObjectProperties;
/// Indicates that the actor is undoing the object.
///

View file

@ -24,9 +24,8 @@ use serde::{Deserialize, Serialize};
use super::{
kind::UpdateType,
properties::{ActivityProperties, UpdateProperties},
ActivityExt,
};
use crate::object::{properties::ObjectProperties, ObjectExt};
use crate::object::properties::ObjectProperties;
/// Indicates that the actor has updated the object.
///

View file

@ -24,9 +24,8 @@ use serde::{Deserialize, Serialize};
use super::{
kind::ViewType,
properties::{ActivityProperties, ViewProperties},
ActivityExt,
};
use crate::object::{properties::ObjectProperties, ObjectExt};
use crate::object::properties::ObjectProperties;
/// Indicates that the actor has viewed the object.
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]

View file

@ -23,7 +23,7 @@ use activitystreams_derive::PropRefs;
use activitystreams_traits::{Actor, Object};
use serde::{Deserialize, Serialize};
use crate::object::{properties::ObjectProperties, ObjectExt};
use crate::object::properties::ObjectProperties;
pub mod kind;
use self::kind::*;

View file

@ -23,29 +23,13 @@ use activitystreams_derive::PropRefs;
use activitystreams_traits::{Collection, CollectionPage, Object};
use serde::{Deserialize, Serialize};
use crate::object::{properties::ObjectProperties, ObjectExt};
use crate::object::properties::ObjectProperties;
pub mod kind;
pub mod properties;
use self::kind::*;
use self::properties::*;
/// The Collection Extension Trait
///
/// This trait provides generic access to a collection's properties
pub trait CollectionExt: Collection {
fn props(&self) -> &CollectionProperties;
fn props_mut(&mut self) -> &mut CollectionProperties;
}
/// The Collection Page Extension Trait
///
/// This trait provides generic access to a collection page's properties
pub trait CollectionPageExt: CollectionPage {
fn props(&self) -> &CollectionPageProperties;
fn props_mut(&mut self) -> &mut CollectionPageProperties;
}
#[derive(Debug, Deserialize, Serialize)]
#[serde(transparent)]
pub struct CollectionBox(pub Box<dyn Object>);

View file

@ -25,14 +25,8 @@
//! use activitystreams_derive::PropRefs;
//! use activitystreams_traits::{Collection, Object};
//! use activitystreams_types::{
//! collection::{
//! properties::CollectionProperties,
//! CollectionExt,
//! },
//! object::{
//! properties::ObjectProperties,
//! ObjectExt,
//! },
//! collection::properties::CollectionProperties,
//! object::properties::ObjectProperties,
//! };
//! use serde::{Deserialize, Serialize};
//! use std::any::Any;

View file

@ -28,14 +28,6 @@ pub mod properties;
use self::kind::*;
use self::properties::*;
/// The Link Extension Trait
///
/// This trait provides generic access to a link's properties
pub trait LinkExt: Link {
fn props(&self) -> &LinkProperties;
fn props_mut(&mut self) -> &mut LinkProperties;
}
#[derive(Debug, Deserialize, Serialize)]
#[serde(transparent)]
pub struct LinkBox(pub Box<dyn Link>);

View file

@ -24,7 +24,7 @@
//! ```rust
//! use activitystreams_derive::PropRefs;
//! use activitystreams_traits::Link;
//! use activitystreams_types::link::{properties::LinkProperties, LinkExt};
//! use activitystreams_types::link::properties::LinkProperties;
//! use serde::{Deserialize, Serialize};
//! use std::any::Any;
//!

View file

@ -28,14 +28,6 @@ pub mod properties;
use self::kind::*;
use self::properties::*;
/// The Object Extension Trait
///
/// This trait provides generic access to an object's properties
pub trait ObjectExt: Object {
fn props(&self) -> &ObjectProperties;
fn props_mut(&mut self) -> &mut ObjectProperties;
}
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(transparent)]
pub struct ImageBox(pub Box<Image>);

View file

@ -24,7 +24,7 @@
//! ```rust
//! use activitystreams_derive::PropRefs;
//! use activitystreams_traits::Object;
//! use activitystreams_types::object::{properties::ObjectProperties, ObjectExt};
//! use activitystreams_types::object::properties::ObjectProperties;
//! use serde::{Deserialize, Serialize};
//! use std::any::Any;
//!

View file

@ -21,7 +21,7 @@
pub use activitystreams_traits::{Activity, IntransitiveActivity};
pub use activitystreams_types::activity::{
kind, properties, AMove, Accept, ActivityExt, 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,
kind, properties, 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,
};

View file

@ -21,6 +21,6 @@
pub use activitystreams_traits::{Collection, CollectionPage};
pub use activitystreams_types::collection::{
kind, properties, CollectionExt, CollectionPageExt, OrderedCollection, OrderedCollectionPage,
UnorderedCollection, UnorderedCollectionPage,
kind, properties, OrderedCollection, OrderedCollectionPage, UnorderedCollection,
UnorderedCollectionPage,
};

View file

@ -99,7 +99,6 @@
//! Mention,
//! },
//! Link,
//! LinkExt,
//! PropRefs,
//! UnitString,
//! };
@ -146,7 +145,7 @@
//! #[activitystreams(None)]
//! pub my_properties: MyProperties,
//!
//! /// Derive AsRef/AsMut/Link/LinkExt for My -> MyProperties
//! /// Derive AsRef/AsMut/Link for My -> MyProperties
//! #[activitystreams(Link)]
//! pub link_properties: LinkProperties,
//! }
@ -172,11 +171,11 @@ pub mod link;
pub mod object;
pub use self::{
activity::{Activity, ActivityExt, IntransitiveActivity},
activity::{Activity, IntransitiveActivity},
actor::Actor,
collection::{Collection, CollectionExt, CollectionPage, CollectionPageExt},
link::{Link, LinkExt},
object::{Object, ObjectExt},
collection::{Collection, CollectionPage},
link::Link,
object::Object,
};
pub use activitystreams_types::{context, primitives};

View file

@ -20,4 +20,4 @@
//! Link traits and types
pub use activitystreams_traits::Link;
pub use activitystreams_types::link::{kind, properties, LinkExt, Mention};
pub use activitystreams_types::link::{kind, properties, Mention};

View file

@ -21,6 +21,6 @@
pub use activitystreams_traits::Object;
pub use activitystreams_types::object::{
kind, properties, Article, Audio, Document, Event, Image, Note, ObjectExt, Page, Place,
Profile, Relationship, Tombstone, Video,
kind, properties, Article, Audio, Document, Event, Image, Note, Page, Place, Profile,
Relationship, Tombstone, Video,
};