diff --git a/src/activity.rs b/src/activity.rs index 2cdca3f..d62e255 100644 --- a/src/activity.rs +++ b/src/activity.rs @@ -2456,10 +2456,7 @@ impl markers::IntransitiveActivity for ApObject where { } -impl Extends for Activity -where - Kind: serde::de::DeserializeOwned + serde::ser::Serialize, -{ +impl Extends for Activity { type Error = serde_json::Error; fn extends(base: Base) -> Result { @@ -2489,10 +2486,7 @@ impl TryFrom> for Object { } } -impl Extends for ActorAndObject -where - Kind: serde::de::DeserializeOwned + serde::ser::Serialize, -{ +impl Extends for ActorAndObject { type Error = serde_json::Error; fn extends(base: Base) -> Result { @@ -2612,10 +2606,7 @@ impl TryFrom for Object { } } -impl Extends for ActorAndObjectOptOriginAndTarget -where - Kind: serde::de::DeserializeOwned + serde::ser::Serialize, -{ +impl Extends for ActorAndObjectOptOriginAndTarget { type Error = serde_json::Error; fn extends(base: Base) -> Result { @@ -2645,10 +2636,7 @@ impl TryFrom> for Object { } } -impl Extends for ActorAndObjectOptTarget -where - Kind: serde::de::DeserializeOwned + serde::ser::Serialize, -{ +impl Extends for ActorAndObjectOptTarget { type Error = serde_json::Error; fn extends(base: Base) -> Result { diff --git a/src/actor.rs b/src/actor.rs index 7d7d0bd..775f422 100644 --- a/src/actor.rs +++ b/src/actor.rs @@ -594,33 +594,33 @@ pub trait ApActorExt: AsApActor { /// Describes a software application. /// -/// This is just an alias for `Object` because there's no fields inherent to -/// Application that aren't already present on an Object. -pub type Application = Object; +/// This is just an alias for `Actor` because there's no fields inherent to +/// Application that aren't already present on an Actor. +pub type Application = Actor; /// Represents a formal or informal collective of Actors. /// -/// This is just an alias for `Object` because there's no fields inherent to -/// Group that aren't already present on an Object. -pub type Group = Object; +/// This is just an alias for `Actor` because there's no fields inherent to +/// Group that aren't already present on an Actor. +pub type Group = Actor; /// Represents an organization. /// -/// This is just an alias for `Object` because there's no fields inherent to -/// Organization that aren't already present on an Object. -pub type Organization = Object; +/// This is just an alias for `Actor` because there's no fields inherent to +/// Organization that aren't already present on an Actor. +pub type Organization = Actor; /// Represents an individual person. /// -/// This is just an alias for `Object` because there's no fields inherent to -/// Person that aren't already present on an Object. -pub type Person = Object; +/// This is just an alias for `Actor` because there's no fields inherent to +/// Person that aren't already present on an Actor. +pub type Person = Actor; /// Represents a service of any kind. /// -/// This is just an alias for `Object` because there's no fields inherent to -/// Service that aren't already present on an Object. -pub type Service = Object; +/// This is just an alias for `Actor` because there's no fields inherent to +/// Service that aren't already present on an Actor. +pub type Service = Actor; /// Actor types are Object types that are capable of performing activities. /// @@ -790,6 +790,33 @@ pub struct Endpoints { pub shared_inbox: Option, } +/// A simple type to create an Actor out of any Object +/// +/// ```rust +/// # use activitystreams_new::{object::Object, actor::Actor, prelude::*}; +/// let object = Object::::new(); +/// let mut actor = Actor(object); +/// actor.set_kind("MyCustomActor".into()); +/// ``` +#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] +#[serde(transparent)] +pub struct Actor(pub Object); + +impl Actor { + /// Create a new Actor + /// + /// ```rust + /// # use activitystreams_new::actor::Actor; + /// let actor = Actor::::new(); + /// ``` + pub fn new() -> Self + where + Kind: Default, + { + Actor(Object::new()) + } +} + impl ApActor { /// Create a new ActivityPub Actor /// @@ -872,26 +899,24 @@ impl ApActor { } } -impl markers::Actor for Application {} -impl markers::Actor for Group {} -impl markers::Actor for Organization {} -impl markers::Actor for Person {} -impl markers::Actor for Service {} +impl markers::Base for Actor {} +impl markers::Object for Actor {} +impl markers::Actor for Actor {} impl markers::Base for ApActor where Inner: markers::Base {} impl markers::Object for ApActor where Inner: markers::Object {} impl markers::Actor for ApActor where Inner: markers::Actor {} -impl Extends for ApActor +impl Extends for ApActor where - Inner: Extends + UnparsedMut + markers::Actor, - Kind: serde::de::DeserializeOwned + serde::ser::Serialize, + Inner: Extends + UnparsedMut + markers::Actor, + Error: From + std::error::Error, { - type Error = serde_json::Error; + type Error = Error; fn extends(base: Base) -> Result { let inner = Inner::extends(base)?; - Self::extending(inner) + Ok(Self::extending(inner)?) } fn retracts(self) -> Result, Self::Error> { @@ -961,4 +986,42 @@ where } } +impl Extends for Actor { + type Error = serde_json::Error; + + fn extends(base: Base) -> Result { + Object::extends(base).map(Actor) + } + + fn retracts(self) -> Result, Self::Error> { + self.0.retracts() + } +} + +impl UnparsedMut for Actor { + fn unparsed_mut(&mut self) -> &mut Unparsed { + self.0.unparsed_mut() + } +} + +impl AsBase for Actor { + fn base_ref(&self) -> &Base { + self.0.base_ref() + } + + fn base_mut(&mut self) -> &mut Base { + self.0.base_mut() + } +} + +impl AsObject for Actor { + fn object_ref(&self) -> &Object { + self.0.object_ref() + } + + fn object_mut(&mut self) -> &mut Object { + self.0.object_mut() + } +} + impl ApActorExt for T where T: AsApActor {} diff --git a/src/collection.rs b/src/collection.rs index fab3f4d..f6fac4d 100644 --- a/src/collection.rs +++ b/src/collection.rs @@ -1202,10 +1202,7 @@ impl markers::CollectionPage for OrderedCollectionPage {} impl markers::Collection for ApObject where Inner: markers::Collection {} impl markers::CollectionPage for ApObject where Inner: markers::CollectionPage {} -impl Extends for Collection -where - Kind: serde::de::DeserializeOwned + serde::ser::Serialize, -{ +impl Extends for Collection { type Error = serde_json::Error; fn extends(base: Base) -> Result { @@ -1235,10 +1232,7 @@ impl TryFrom> for Collection { } } -impl Extends for CollectionPage -where - Kind: serde::de::DeserializeOwned + serde::ser::Serialize, -{ +impl Extends for CollectionPage { type Error = serde_json::Error; fn extends(base: Base) -> Result { diff --git a/src/link.rs b/src/link.rs index 7d7c10e..9630541 100644 --- a/src/link.rs +++ b/src/link.rs @@ -590,10 +590,7 @@ impl Link { impl markers::Base for Link {} impl markers::Link for Link {} -impl Extends for Link -where - Kind: serde::de::DeserializeOwned + serde::ser::Serialize, -{ +impl Extends for Link { type Error = serde_json::Error; fn extends(base: Base) -> Result { diff --git a/src/object.rs b/src/object.rs index 508d61d..4a4501d 100644 --- a/src/object.rs +++ b/src/object.rs @@ -4724,10 +4724,7 @@ impl Object { Object::builder().inner(Base::new()).build() } - fn extending(mut base: Base) -> Result - where - Kind: serde::de::DeserializeOwned, - { + fn extending(mut base: Base) -> Result { Ok(Object { attachment: base.remove("attachment")?, attributed_to: base.remove("attributedTo")?, @@ -4755,10 +4752,7 @@ impl Object { }) } - fn retracting(self) -> Result, serde_json::Error> - where - Kind: serde::ser::Serialize, - { + fn retracting(self) -> Result, serde_json::Error> { let Object { attachment, attributed_to, @@ -5031,10 +5025,7 @@ impl Tombstone { } } -impl Extends for Object -where - Kind: serde::de::DeserializeOwned + serde::ser::Serialize, -{ +impl Extends for Object { type Error = serde_json::Error; fn extends(base: Base) -> Result { @@ -5046,10 +5037,7 @@ where } } -impl TryFrom> for Object -where - Kind: serde::de::DeserializeOwned, -{ +impl TryFrom> for Object { type Error = serde_json::Error; fn try_from(base: Base) -> Result { @@ -5057,10 +5045,7 @@ where } } -impl TryFrom> for Base -where - Kind: serde::ser::Serialize, -{ +impl TryFrom> for Base { type Error = serde_json::Error; fn try_from(object: Object) -> Result { @@ -5071,7 +5056,6 @@ where impl Extends for ApObject where Inner: Extends + UnparsedMut + markers::Object, - Kind: serde::de::DeserializeOwned + serde::ser::Serialize, { type Error = serde_json::Error;