Finish documenting, closes #1

This commit is contained in:
asonix 2020-05-17 14:35:10 -05:00
parent 0bedf94797
commit e52b6a7fa7
8 changed files with 1172 additions and 226 deletions

View file

@ -15,28 +15,20 @@ The project is laid out by Kind => vocabulary => Type
So to use an ActivityStreams Video, you'd write
```rust
use activitystreams_new::object::Video;
let video = Video::builder()
.inner(Default::default())
.build();
let video = Video::new();
```
And to use an ActivityPub profile, you'd write
```rust
use activitystreams_new::object::{ApObject, Profile};
let inner = Profile::builder()
.inner(Default::default())
.build();
let profile = ApObject::builder()
.inner(inner)
.build();
let inner = Profile::new();
let profile = ApObject::new(inner);
```
There's only one kind of Link
```rust
use activitystreams_new::link::Mention;
let mention = Mention::builder()
.inner(Default::default())
.build();
let mention = Mention::new();
```
### Fields

View file

@ -9,11 +9,10 @@
//! primitives::XsdAnyUri,
//! };
//!
//! let mut create = Create::builder()
//! .object("https://example.com/notes/1234".parse::<XsdAnyUri>()?)
//! .actor("https://example.com/actors/abcd".parse::<XsdAnyUri>()?)
//! .inner(Default::default())
//! .build();
//! let mut create = Create::new(
//! "https://example.com/actors/abcd".parse::<XsdAnyUri>()?,
//! "https://example.com/notes/1234".parse::<XsdAnyUri>()?,
//! );
//!
//! create
//! .set_result("https://example.com/".parse::<XsdAnyUri>()?)
@ -421,11 +420,7 @@ pub trait ActorAndObjectRefExt: ActorAndObjectRef {
///
/// ```rust
/// # use activitystreams_new::{context, activity::Create};
/// # let mut create = Create::builder()
/// # .actor(context())
/// # .object(context())
/// # .inner(Default::default())
/// # .build();
/// # let mut create = Create::new(context(), context());
/// #
/// use activitystreams_new::prelude::*;
///
@ -448,11 +443,7 @@ pub trait ActorAndObjectRefExt: ActorAndObjectRef {
/// # activity::Create,
/// # primitives::XsdAnyUri
/// # };
/// # let mut create = Create::builder()
/// # .actor(context())
/// # .object(context())
/// # .inner(Default::default())
/// # .build();
/// # let mut create = Create::new(context(), context());
///
/// create.set_actor("https://example.com".parse::<XsdAnyUri>()?);
/// # Ok(())
@ -478,11 +469,7 @@ pub trait ActorAndObjectRefExt: ActorAndObjectRef {
/// # activity::Create,
/// # primitives::XsdAnyUri
/// # };
/// # let mut create = Create::builder()
/// # .actor(context())
/// # .object(context())
/// # .inner(Default::default())
/// # .build();
/// # let mut create = Create::new(context(), context());
///
/// create.set_many_actors(vec![
/// "https://example.com/one".parse::<XsdAnyUri>()?,
@ -513,11 +500,7 @@ pub trait ActorAndObjectRefExt: ActorAndObjectRef {
/// # activity::Create,
/// # primitives::XsdAnyUri
/// # };
/// # let mut create = Create::builder()
/// # .actor(context())
/// # .object(context())
/// # .inner(Default::default())
/// # .build();
/// # let mut create = Create::new(context(), context());
///
/// create
/// .add_actor("https://example.com/one".parse::<XsdAnyUri>()?)
@ -537,11 +520,7 @@ pub trait ActorAndObjectRefExt: ActorAndObjectRef {
///
/// ```rust
/// # use activitystreams_new::{context, activity::Create};
/// # let mut create = Create::builder()
/// # .actor(context())
/// # .object(context())
/// # .inner(Default::default())
/// # .build();
/// # let mut create = Create::new(context(), context());
/// #
/// use activitystreams_new::prelude::*;
///
@ -564,11 +543,7 @@ pub trait ActorAndObjectRefExt: ActorAndObjectRef {
/// # activity::Create,
/// # primitives::XsdAnyUri
/// # };
/// # let mut create = Create::builder()
/// # .actor(context())
/// # .object(context())
/// # .inner(Default::default())
/// # .build();
/// # let mut create = Create::new(context(), context());
///
/// create.set_object("https://example.com".parse::<XsdAnyUri>()?);
/// # Ok(())
@ -594,11 +569,7 @@ pub trait ActorAndObjectRefExt: ActorAndObjectRef {
/// # activity::Create,
/// # primitives::XsdAnyUri
/// # };
/// # let mut create = Create::builder()
/// # .actor(context())
/// # .object(context())
/// # .inner(Default::default())
/// # .build();
/// # let mut create = Create::new(context(), context());
///
/// create.set_many_objects(vec![
/// "https://example.com/one".parse::<XsdAnyUri>()?,
@ -629,11 +600,7 @@ pub trait ActorAndObjectRefExt: ActorAndObjectRef {
/// # activity::Create,
/// # primitives::XsdAnyUri
/// # };
/// # let mut create = Create::builder()
/// # .actor(context())
/// # .object(context())
/// # .inner(Default::default())
/// # .build();
/// # let mut create = Create::new(context(), context());
///
/// create
/// .add_object("https://example.com/one".parse::<XsdAnyUri>()?)
@ -658,12 +625,7 @@ pub trait TargetRefExt: TargetRef {
///
/// ```rust
/// # use activitystreams_new::{context, activity::Invite};
/// # let mut invite = Invite::builder()
/// # .actor(context())
/// # .object(context())
/// # .target(context())
/// # .inner(Default::default())
/// # .build();
/// # let mut invite = Invite::new(context(), context(), context());
/// #
/// use activitystreams_new::prelude::*;
///
@ -686,12 +648,7 @@ pub trait TargetRefExt: TargetRef {
/// # activity::Invite,
/// # primitives::XsdAnyUri
/// # };
/// # let mut invite = Invite::builder()
/// # .actor(context())
/// # .object(context())
/// # .target(context())
/// # .inner(Default::default())
/// # .build();
/// # let mut invite = Invite::new(context(), context(), context());
///
/// invite.set_target("https://example.com".parse::<XsdAnyUri>()?);
/// # Ok(())
@ -717,12 +674,7 @@ pub trait TargetRefExt: TargetRef {
/// # activity::Invite,
/// # primitives::XsdAnyUri
/// # };
/// # let mut invite = Invite::builder()
/// # .actor(context())
/// # .object(context())
/// # .target(context())
/// # .inner(Default::default())
/// # .build();
/// # let mut invite = Invite::new(context(), context(), context());
///
/// invite.set_many_targets(vec![
/// "https://example.com/one".parse::<XsdAnyUri>()?,
@ -753,12 +705,7 @@ pub trait TargetRefExt: TargetRef {
/// # activity::Invite,
/// # primitives::XsdAnyUri
/// # };
/// # let mut invite = Invite::builder()
/// # .actor(context())
/// # .object(context())
/// # .target(context())
/// # .inner(Default::default())
/// # .build();
/// # let mut invite = Invite::new(context(), context(), context());
///
/// invite
/// .add_target("https://example.com/one".parse::<XsdAnyUri>()?)
@ -783,11 +730,7 @@ pub trait OriginRefExt: OriginRef {
///
/// ```rust
/// # use activitystreams_new::{context, activity::Arrive};
/// # let mut arrive = Arrive::builder()
/// # .actor(context())
/// # .origin(context())
/// # .inner(Default::default())
/// # .build();
/// # let mut arrive = Arrive::new(context(), context());
/// #
/// use activitystreams_new::prelude::*;
///
@ -810,11 +753,7 @@ pub trait OriginRefExt: OriginRef {
/// # activity::Arrive,
/// # primitives::XsdAnyUri
/// # };
/// # let mut arrive = Arrive::builder()
/// # .actor(context())
/// # .origin(context())
/// # .inner(Default::default())
/// # .build();
/// # let mut arrive = Arrive::new(context(), context());
///
/// arrive.set_origin("https://example.com".parse::<XsdAnyUri>()?);
/// # Ok(())
@ -840,11 +779,7 @@ pub trait OriginRefExt: OriginRef {
/// # activity::Arrive,
/// # primitives::XsdAnyUri
/// # };
/// # let mut arrive = Arrive::builder()
/// # .actor(context())
/// # .origin(context())
/// # .inner(Default::default())
/// # .build();
/// # let mut arrive = Arrive::new(context(), context());
///
/// arrive.set_many_origins(vec![
/// "https://example.com/one".parse::<XsdAnyUri>()?,
@ -875,11 +810,7 @@ pub trait OriginRefExt: OriginRef {
/// # activity::Arrive,
/// # primitives::XsdAnyUri
/// # };
/// # let mut arrive = Arrive::builder()
/// # .actor(context())
/// # .origin(context())
/// # .inner(Default::default())
/// # .build();
/// # let mut arrive = Arrive::new(context(), context());
///
/// arrive
/// .add_origin("https://example.com/one".parse::<XsdAnyUri>()?)
@ -905,11 +836,7 @@ pub trait OptTargetRefExt: OptTargetRef {
///
/// ```rust
/// # use activitystreams_new::{context, activity::Announce};
/// # let mut announce = Announce::builder()
/// # .actor(context())
/// # .object(context())
/// # .inner(Default::default())
/// # .build();
/// # let mut announce = Announce::new(context(), context());
/// #
/// use activitystreams_new::prelude::*;
///
@ -933,11 +860,7 @@ pub trait OptTargetRefExt: OptTargetRef {
/// # activity::Announce,
/// # primitives::XsdAnyUri
/// # };
/// # let mut announce = Announce::builder()
/// # .actor(context())
/// # .object(context())
/// # .inner(Default::default())
/// # .build();
/// # let mut announce = Announce::new(context(), context());
///
/// announce.set_target("https://example.com".parse::<XsdAnyUri>()?);
/// # Ok(())
@ -963,11 +886,7 @@ pub trait OptTargetRefExt: OptTargetRef {
/// # activity::Announce,
/// # primitives::XsdAnyUri
/// # };
/// # let mut announce = Announce::builder()
/// # .actor(context())
/// # .object(context())
/// # .inner(Default::default())
/// # .build();
/// # let mut announce = Announce::new(context(), context());
///
/// announce.set_many_targets(vec![
/// "https://example.com/one".parse::<XsdAnyUri>()?,
@ -998,11 +917,7 @@ pub trait OptTargetRefExt: OptTargetRef {
/// # activity::Announce,
/// # primitives::XsdAnyUri
/// # };
/// # let mut announce = Announce::builder()
/// # .actor(context())
/// # .object(context())
/// # .inner(Default::default())
/// # .build();
/// # let mut announce = Announce::new(context(), context());
///
/// announce
/// .add_target("https://example.com/one".parse::<XsdAnyUri>()?)
@ -1035,11 +950,7 @@ pub trait OptTargetRefExt: OptTargetRef {
/// # activity::Announce,
/// # primitives::XsdAnyUri
/// # };
/// # let mut announce = Announce::builder()
/// # .actor(context())
/// # .object(context())
/// # .inner(Default::default())
/// # .build();
/// # let mut announce = Announce::new(context(), context());
///
/// if let Some(target) = announce.take_target() {
/// println!("{:?}", target);
@ -1061,11 +972,7 @@ pub trait OptTargetRefExt: OptTargetRef {
/// # activity::Announce,
/// # primitives::XsdAnyUri
/// # };
/// # let mut announce = Announce::builder()
/// # .actor(context())
/// # .object(context())
/// # .inner(Default::default())
/// # .build();
/// # let mut announce = Announce::new(context(), context());
/// # announce.set_target(context());
///
/// assert!(announce.target().is_some());
@ -1089,11 +996,7 @@ pub trait OptOriginRefExt: OptOriginRef {
///
/// ```rust
/// # use activitystreams_new::{context, activity::Delete};
/// # let mut delete = Delete::builder()
/// # .actor(context())
/// # .object(context())
/// # .inner(Default::default())
/// # .build();
/// # let mut delete = Delete::new(context(), context());
/// #
/// use activitystreams_new::prelude::*;
///
@ -1117,11 +1020,7 @@ pub trait OptOriginRefExt: OptOriginRef {
/// # activity::Delete,
/// # primitives::XsdAnyUri
/// # };
/// # let mut delete = Delete::builder()
/// # .actor(context())
/// # .object(context())
/// # .inner(Default::default())
/// # .build();
/// # let mut delete = Delete::new(context(), context());
///
/// delete.set_origin("https://example.com".parse::<XsdAnyUri>()?);
/// # Ok(())
@ -1147,11 +1046,7 @@ pub trait OptOriginRefExt: OptOriginRef {
/// # activity::Delete,
/// # primitives::XsdAnyUri
/// # };
/// # let mut delete = Delete::builder()
/// # .actor(context())
/// # .object(context())
/// # .inner(Default::default())
/// # .build();
/// # let mut delete = Delete::new(context(), context());
///
/// delete.set_many_origins(vec![
/// "https://example.com/one".parse::<XsdAnyUri>()?,
@ -1182,11 +1077,7 @@ pub trait OptOriginRefExt: OptOriginRef {
/// # activity::Delete,
/// # primitives::XsdAnyUri
/// # };
/// # let mut delete = Delete::builder()
/// # .actor(context())
/// # .object(context())
/// # .inner(Default::default())
/// # .build();
/// # let mut delete = Delete::new(context(), context());
///
/// delete
/// .add_origin("https://example.com/one".parse::<XsdAnyUri>()?)
@ -1219,11 +1110,7 @@ pub trait OptOriginRefExt: OptOriginRef {
/// # activity::Delete,
/// # primitives::XsdAnyUri
/// # };
/// # let mut delete = Delete::builder()
/// # .actor(context())
/// # .object(context())
/// # .inner(Default::default())
/// # .build();
/// # let mut delete = Delete::new(context(), context());
///
/// if let Some(origin) = delete.take_origin() {
/// println!("{:?}", origin);
@ -1245,11 +1132,7 @@ pub trait OptOriginRefExt: OptOriginRef {
/// # activity::Delete,
/// # primitives::XsdAnyUri
/// # };
/// # let mut delete = Delete::builder()
/// # .actor(context())
/// # .object(context())
/// # .inner(Default::default())
/// # .build();
/// # let mut delete = Delete::new(context(), context());
/// # delete.set_origin(context());
///
/// assert!(delete.origin().is_some());
@ -1544,7 +1427,7 @@ pub trait QuestionExt: AsQuestion {
/// object has been accepted.
///
/// This is just an alias for `Object<AcceptType>` because there's no fields inherent to
/// Accept that aren't already present on an Object.
/// Accept that aren't already present on an ActorAndObject.
pub type Accept = ActorAndObject<AcceptType>;
/// Indicates that the actor has added the object to the target.
@ -1553,7 +1436,7 @@ pub type Accept = ActorAndObject<AcceptType>;
/// implicitly by context. The origin can be used to identify the context from which the object originated.
///
/// This is just an alias for `Object<AddType>` because there's no fields inherent to
/// Add that aren't already present on an Object.
/// Add that aren't already present on an ActorAndObject.
pub type Add = ActorAndObject<AddType>;
/// Indicates that the actor is blocking the object.
@ -1563,19 +1446,19 @@ pub type Add = ActorAndObject<AddType>;
/// defined meaning.
///
/// This is just an alias for `Object<BlockType>` because there's no fields inherent to
/// Block that aren't already present on an Object.
/// Block that aren't already present on an ActorAndObject.
pub type Block = ActorAndObject<BlockType>;
/// Indicates that the actor has created the object.
///
/// This is just an alias for `Object<CreateType>` because there's no fields inherent to
/// Create that aren't already present on an Object.
/// Create that aren't already present on an ActorAndObject.
pub type Create = ActorAndObject<CreateType>;
/// Indicates that the actor dislikes the object.
///
/// This is just an alias for `Object<DislikeType>` because there's no fields inherent to
/// Dislike that aren't already present on an Object.
/// Dislike that aren't already present on an ActorAndObject.
pub type Dislike = ActorAndObject<DislikeType>;
/// Indicates that the actor is "flagging" the object.
@ -1584,7 +1467,7 @@ pub type Dislike = ActorAndObject<DislikeType>;
/// inappropriate for any number of reasons.
///
/// This is just an alias for `Object<FlagType>` because there's no fields inherent to
/// Flag that aren't already present on an Object.
/// Flag that aren't already present on an ActorAndObject.
pub type Flag = ActorAndObject<FlagType>;
/// Indicates that the actor is "following" the object.
@ -1594,7 +1477,7 @@ pub type Flag = ActorAndObject<FlagType>;
/// no defined meaning.
///
/// This is just an alias for `Object<FollowType>` because there's no fields inherent to Follow
/// that aren't already present on an Object.
/// that aren't already present on an ActorAndObject.
pub type Follow = ActorAndObject<FollowType>;
/// Indicates that the actor is ignoring the object.
@ -1602,7 +1485,7 @@ pub type Follow = ActorAndObject<FollowType>;
/// The target and origin typically have no defined meaning.
///
/// This is just an alias for `Object<IgnoreType>` because there's no fields inherent to Ignore
/// that aren't already present on an Object.
/// that aren't already present on an ActorAndObject.
pub type Ignore = ActorAndObject<IgnoreType>;
/// Indicates that the actor has joined the object.
@ -1610,7 +1493,7 @@ pub type Ignore = ActorAndObject<IgnoreType>;
/// The target and origin typically have no defined meaning
///
/// This is just an alias for `Object<JoinType>` because there's no fields inherent to Join that
/// aren't already present on an Object.
/// aren't already present on an ActorAndObject.
pub type Join = ActorAndObject<JoinType>;
/// Indicates that the actor has left the object.
@ -1618,7 +1501,7 @@ pub type Join = ActorAndObject<JoinType>;
/// The target and origin typically have no meaning.
///
/// This is just an alias for `Object<LeaveType>` because there's no fields inherent to Leave that
/// aren't already present on an Object.
/// aren't already present on an ActorAndObject.
pub type Leave = ActorAndObject<LeaveType>;
/// Indicates that the actor likes, recommends or endorses the object.
@ -1626,19 +1509,19 @@ pub type Leave = ActorAndObject<LeaveType>;
/// The target and origin typically have no defined meaning.
///
/// This is just an alias for `Object<LikeType>` because there's no fields inherent to Like that
/// aren't already present on an Object.
/// aren't already present on an ActorAndObject.
pub type Like = ActorAndObject<LikeType>;
/// Indicates that the actor has listened to the object.
///
/// This is just an alias for `Object<ListenType>` because there's no fields inherent to Listen
/// that aren't already present on an Object.
/// that aren't already present on an ActorAndObject.
pub type Listen = ActorAndObject<ListenType>;
/// Indicates that the actor has read the object.
///
/// This is just an alias for `Object<ReadType>` because there's no fields inherent to Read that
/// aren't already present on an Object.
/// aren't already present on an ActorAndObject.
pub type Read = ActorAndObject<ReadType>;
/// Indicates that the actor is rejecting the object.
@ -1646,19 +1529,19 @@ pub type Read = ActorAndObject<ReadType>;
/// The target and origin typically have no defined meaning.
///
/// This is just an alias for `Object<RejectType>` because there's no fields inherent to Reject
/// that aren't already present on an Object.
/// that aren't already present on an ActorAndObject.
pub type Reject = ActorAndObject<RejectType>;
/// A specialization of Accept indicating that the acceptance is tentative.
///
/// This is just an alias for `Object<TentativeAcceptType>` because there's no fields inherent to
/// TentativeAccept that aren't already present on an Object.
/// TentativeAccept that aren't already present on an ActorAndObject.
pub type TentativeAccept = ActorAndObject<TentativeAcceptType>;
/// A specialization of Reject in which the rejection is considered tentative.
///
/// This is just an alias for `Object<TentativeRejectType>` because there's no fields inherent to
/// TentativeReject that aren't already present on an Object.
/// TentativeReject that aren't already present on an ActorAndObject.
pub type TentativeReject = ActorAndObject<TentativeRejectType>;
/// Indicates that the actor is undoing the object.
@ -1670,7 +1553,7 @@ pub type TentativeReject = ActorAndObject<TentativeRejectType>;
/// The target and origin typically have no defined meaning.
///
/// This is just an alias for `Object<UndoType>` because there's no fields inherent to
/// Undo that aren't already present on an Object.
/// Undo that aren't already present on an ActorAndObject.
pub type Undo = ActorAndObject<UndoType>;
/// Indicates that the actor has updated the object.
@ -1681,13 +1564,13 @@ pub type Undo = ActorAndObject<UndoType>;
/// The target and origin typically have no defined meaning.
///
/// This is just an alias for `Object<UpdateType>` because there's no fields inherent to
/// Update that aren't already present on an Object.
/// Update that aren't already present on an ActorAndObject.
pub type Update = ActorAndObject<UpdateType>;
/// Indicates that the actor has viewed the object.
///
/// This is just an alias for `Object<ViewType>` because there's no fields inherent to
/// View that aren't already present on an Object.
/// View that aren't already present on an ActorAndObject.
pub type View = ActorAndObject<ViewType>;
/// Indicates that the actor is calling the target's attention the object.
@ -1695,7 +1578,7 @@ pub type View = ActorAndObject<ViewType>;
/// The origin typically has no defined meaning.
///
/// This is just an alias for `Object<AnnounceType>` because there's no fields inherent to
/// Announce that aren't already present on an Object.
/// Announce that aren't already present on an ActorAndObjectOptTarget.
pub type Announce = ActorAndObjectOptTarget<AnnounceType>;
/// Indicates that the actor is offering the object.
@ -1703,7 +1586,7 @@ pub type Announce = ActorAndObjectOptTarget<AnnounceType>;
/// If specified, the target indicates the entity to which the object is being offered.
///
/// This is just an alias for `Object<OfferType>` because there's no fields inherent to
/// Offer that aren't already present on an Object.
/// Offer that aren't already present on an ActorAndObjectOptTarget.
pub type Offer = ActorAndObjectOptTarget<OfferType>;
/// Indicates that the actor has moved object from origin to target.
@ -1711,7 +1594,7 @@ pub type Offer = ActorAndObjectOptTarget<OfferType>;
/// If the origin or target are not specified, either can be determined by context.
///
/// This is just an alias for `Object<MoveType>` because there's no fields inherent to
/// Move that aren't already present on an Object.
/// Move that aren't already present on an ActorAndObjectOptOriginAndTarget.
pub type Move = ActorAndObjectOptOriginAndTarget<MoveType>;
/// Indicates that the actor is removing the object.
@ -1719,7 +1602,7 @@ pub type Move = ActorAndObjectOptOriginAndTarget<MoveType>;
/// If specified, the origin indicates the context from which the object is being removed.
///
/// This is just an alias for `Object<RemoveType>` because there's no fields inherent to
/// Remove that aren't already present on an Object.
/// Remove that aren't already present on an ActorAndObjectOptOriginAndTarget.
pub type Remove = ActorAndObjectOptOriginAndTarget<RemoveType>;
/// Activity objects are specializations of the base Object type that provide information about
@ -1788,9 +1671,6 @@ pub struct ActorAndObject<Kind> {
///
/// The origin can be used to identify the context from which the actor originated. The target
/// typically has no defined meaning.
///
/// This is just an alias for `Object<ArriveType>` because there's no fields inherent to
/// Arrive that aren't already present on an Object.
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize, TypedBuilder)]
#[serde(rename_all = "camelCase")]
#[builder(doc)]
@ -1824,9 +1704,6 @@ pub struct Arrive {
/// A specialization of Offer in which the actor is extending an invitation for the object to the
/// target.
///
/// This is just an alias for `Object<InviteType>` because there's no fields inherent to
/// Invite that aren't already present on an Object.
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize, TypedBuilder)]
#[serde(rename_all = "camelCase")]
#[builder(doc)]
@ -1872,9 +1749,6 @@ pub struct Invite {
/// Indicates that the actor has deleted the object.
///
/// If specified, the origin indicates the context from which the object was deleted.
///
/// This is just an alias for `Object<DeleteType>` because there's no fields inherent to
/// Delete that aren't already present on an Object.
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize, TypedBuilder)]
#[serde(rename_all = "camelCase")]
#[builder(doc)]
@ -2021,9 +1895,6 @@ pub struct ActorAndObjectOptTarget<Kind> {
///
/// Travel is an IntransitiveObject whose actor specifies the direct object. If the target or
/// origin are not specified, either can be determined by context.
///
/// This is just an alias for `Object<TravelType>` because there's no fields inherent to
/// Travel that aren't already present on an Object.
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize, TypedBuilder)]
#[serde(rename_all = "camelCase")]
#[builder(doc)]
@ -2077,9 +1948,6 @@ pub struct Travel {
///
/// Either of the anyOf and oneOf properties MAY be used to express possible answers, but a
/// Question object MUST NOT have both properties.
///
/// This is just an alias for `Object<QuestionType>` because there's no fields inherent to
/// Question that aren't already present on an Object.
#[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize, TypedBuilder)]
#[serde(rename_all = "camelCase")]
#[builder(doc)]
@ -2112,6 +1980,20 @@ pub struct Question {
}
impl<Kind> Activity<Kind> {
/// Create a new Activity
///
/// ```rust
/// use activitystreams_new::activity::Activity;
///
/// let activity = Activity::<String>::new();
/// ```
pub fn new() -> Self
where
Kind: Default,
{
Activity::builder().inner(Object::new()).build()
}
fn extending(mut inner: Object<Kind>) -> Result<Self, serde_json::Error> {
let result = inner.remove("result")?;
let instrument = inner.remove("instrument")?;
@ -2139,6 +2021,26 @@ impl<Kind> Activity<Kind> {
}
impl<Kind> ActorAndObject<Kind> {
/// Create a new ActorAndObject Activity
///
/// ```rust
/// use activitystreams_new::activity::ActorAndObject;
///
/// let activity = ActorAndObject::<String>::new(vec![], vec![]);
/// ```
pub fn new<T, U>(actor: T, object: U) -> Self
where
T: Into<OneOrMany<AnyBase>>,
U: Into<OneOrMany<AnyBase>>,
Kind: Default,
{
Self::builder()
.actor(actor)
.object(object)
.inner(Activity::new())
.build()
}
fn extending(object: Object<Kind>) -> Result<Self, serde_json::Error> {
let mut inner = Activity::extending(object)?;
@ -2166,6 +2068,25 @@ impl<Kind> ActorAndObject<Kind> {
}
impl Arrive {
/// Create a new Arrive Activity
///
/// ```rust
/// use activitystreams_new::activity::Arrive;
///
/// let activity = Arrive::new(vec![], vec![]);
/// ```
pub fn new<T, U>(actor: T, origin: U) -> Self
where
T: Into<OneOrMany<AnyBase>>,
U: Into<OneOrMany<AnyBase>>,
{
Self::builder()
.actor(actor)
.origin(origin)
.inner(Activity::new())
.build()
}
fn extending(object: Object<ArriveType>) -> Result<Self, serde_json::Error> {
let mut inner = Activity::extending(object)?;
@ -2193,6 +2114,27 @@ impl Arrive {
}
impl Invite {
/// Create a new Invite Activity
///
/// ```rust
/// use activitystreams_new::activity::Invite;
///
/// let activity = Invite::new(vec![], vec![], vec![]);
/// ```
pub fn new<T, U, V>(actor: T, object: U, target: V) -> Self
where
T: Into<OneOrMany<AnyBase>>,
U: Into<OneOrMany<AnyBase>>,
V: Into<OneOrMany<AnyBase>>,
{
Self::builder()
.actor(actor)
.object(object)
.target(target)
.inner(Activity::new())
.build()
}
fn extending(object: Object<InviteType>) -> Result<Self, serde_json::Error> {
let mut inner = Activity::extending(object)?;
@ -2226,6 +2168,25 @@ impl Invite {
}
impl Delete {
/// Create a new Delete Activity
///
/// ```rust
/// use activitystreams_new::activity::Delete;
///
/// let activity = Delete::new(vec![], vec![]);
/// ```
pub fn new<T, U>(actor: T, object: U) -> Self
where
T: Into<OneOrMany<AnyBase>>,
U: Into<OneOrMany<AnyBase>>,
{
Self::builder()
.actor(actor)
.object(object)
.inner(Activity::new())
.build()
}
fn extending(object: Object<DeleteType>) -> Result<Self, serde_json::Error> {
let mut inner = Activity::extending(object)?;
@ -2259,6 +2220,29 @@ impl Delete {
}
impl<Kind> ActorAndObjectOptOriginAndTarget<Kind> {
/// Create a new ActorAndObjectOptOriginAndTarget Activity
///
/// ```rust
/// use activitystreams_new::activity::ActorAndObjectOptOriginAndTarget;
///
/// let activity = ActorAndObjectOptOriginAndTarget::<String>::new(
/// vec![],
/// vec![]
/// );
/// ```
pub fn new<T, U>(actor: T, object: U) -> Self
where
T: Into<OneOrMany<AnyBase>>,
U: Into<OneOrMany<AnyBase>>,
Kind: Default,
{
Self::builder()
.actor(actor)
.object(object)
.inner(Activity::new())
.build()
}
fn extending(object: Object<Kind>) -> Result<Self, serde_json::Error> {
let mut inner = Activity::extending(object)?;
@ -2296,6 +2280,29 @@ impl<Kind> ActorAndObjectOptOriginAndTarget<Kind> {
}
impl<Kind> ActorAndObjectOptTarget<Kind> {
/// Create a new ActorAndObjectOptTarget Activity
///
/// ```rust
/// use activitystreams_new::activity::ActorAndObjectOptTarget;
///
/// let activity = ActorAndObjectOptTarget::<String>::new(
/// vec![],
/// vec![]
/// );
/// ```
pub fn new<T, U>(actor: T, object: U) -> Self
where
T: Into<OneOrMany<AnyBase>>,
U: Into<OneOrMany<AnyBase>>,
Kind: Default,
{
Self::builder()
.actor(actor)
.object(object)
.inner(Activity::new())
.build()
}
fn extending(object: Object<Kind>) -> Result<Self, serde_json::Error> {
let mut inner = Activity::extending(object)?;
@ -2329,6 +2336,20 @@ impl<Kind> ActorAndObjectOptTarget<Kind> {
}
impl Travel {
/// Create a new Travel Activity
///
/// ```rust
/// use activitystreams_new::activity::Travel;
///
/// let activity = Travel::new(vec![]);
/// ```
pub fn new<T>(actor: T) -> Self
where
T: Into<OneOrMany<AnyBase>>,
{
Self::builder().actor(actor).inner(Activity::new()).build()
}
fn extending(object: Object<TravelType>) -> Result<Self, serde_json::Error> {
let mut inner = Activity::extending(object)?;
@ -2362,6 +2383,17 @@ impl Travel {
}
impl Question {
/// Create a new Question Activity
///
/// ```rust
/// use activitystreams_new::activity::Question;
///
/// let activity = Question::new();
/// ```
pub fn new() -> Self {
Question::builder().inner(Activity::new()).build()
}
fn extending(object: Object<QuestionType>) -> Result<Self, serde_json::Error> {
let mut inner = Activity::extending(object)?;

View file

@ -620,7 +620,24 @@ pub type Person = Object<PersonType>;
/// Service that aren't already present on an Object.
pub type Service = Object<ServiceType>;
/// Define activitypub properties for the Actor type as described by the Activity Pub vocabulary.
/// Actor types are Object types that are capable of performing activities.
///
/// This specification intentionally defines Actors in only the most generalized way, stopping
/// short of defining semantically specific properties for each. All Actor objects are
/// specializations of Object and inherit all of the core properties common to all Objects.
/// External vocabularies can be used to express additional detail not covered by the Activity
/// Vocabulary. VCard [vcard-rdf SHOULD be used to provide additional metadata for Person, Group,
/// and Organization instances.
///
/// While implementations are free to introduce new types of Actors beyond those defined by the
/// Activity Vocabulary, interoperability issues can arise when applications rely too much on
/// extension types that are not recognized by other implementations. Care should be taken to not
/// unduly overlap with or duplicate the existing Actor types.
///
/// When an implementation uses an extension type that overlaps with a core vocabulary type, the
/// implementation MUST also specify the core vocabulary type. For instance, some vocabularies
/// (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.
#[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize, TypedBuilder)]
#[serde(rename_all = "camelCase")]
#[builder(doc)]
@ -773,6 +790,31 @@ pub struct Endpoints {
}
impl<Inner> ApActor<Inner> {
/// Create a new ActivityPub Actor
///
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// use activitystreams_new::actor::{ApActor, Person};
///
/// let actor = ApActor::new(
/// "https://example.com/inbox".parse()?,
/// "https://example.com/outbox".parse()?,
/// Person::new(),
/// );
/// # Ok(())
/// # }
/// ```
pub fn new(inbox: XsdAnyUri, outbox: XsdAnyUri, inner: Inner) -> Self
where
Inner: markers::Actor,
{
Self::builder()
.inbox(inbox)
.outbox(outbox)
.inner(inner)
.build()
}
fn extending(mut inner: Inner) -> Result<Self, serde_json::Error>
where
Inner: UnparsedMut + markers::Actor,

View file

@ -851,6 +851,20 @@ impl Base<serde_json::Value> {
}
impl<Kind> Base<Kind> {
/// Create a new Base
///
/// ```rust
/// use activitystreams_new::base::Base;
///
/// let base = Base::<String>::new();
/// ```
pub fn new() -> Self
where
Kind: Default,
{
Base::builder().kind(Kind::default()).build()
}
/// Extend the Base into any other ActivityStreams type provided in this crate
///
/// ```rust
@ -1036,6 +1050,7 @@ impl AnyBase {
/// This method checks if the current object _is_ an ID, and then falls back on the `id` field
/// within the `Base<serde_json::Value>` if that exists
///
/// #### Get the ID from the nested video
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// # use activitystreams_new::{
@ -1052,6 +1067,7 @@ impl AnyBase {
/// # }
/// ```
///
/// #### Get the ID from the AnyBase
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// # use activitystreams_new::{

File diff suppressed because it is too large Load diff

View file

@ -15,28 +15,20 @@
//! So to use an ActivityStreams Video, you'd write
//! ```rust
//! use activitystreams_new::object::Video;
//! let video = Video::builder()
//! .inner(Default::default())
//! .build();
//! let video = Video::new();
//! ```
//!
//! And to use an ActivityPub profile, you'd write
//! ```rust
//! use activitystreams_new::object::{ApObject, Profile};
//! let inner = Profile::builder()
//! .inner(Default::default())
//! .build();
//! let profile = ApObject::builder()
//! .inner(inner)
//! .build();
//! let inner = Profile::new();
//! let profile = ApObject::new(inner);
//! ```
//!
//! There's only one kind of Link
//! ```rust
//! use activitystreams_new::link::Mention;
//! let mention = Mention::builder()
//! .inner(Default::default())
//! .build();
//! let mention = Mention::new();
//! ```
//!
//! ### Fields
@ -304,7 +296,6 @@ pub mod prelude {
//!
//! let mut person = ApActor::<Person>::default();
//! person
//! .set_kind(PersonType)
//! .set_inbox("https://localhost:8080/inbox".parse()?)
//! .set_outbox("https://localhost:8080/outbox".parse()?)
//! .set_name(XsdString::from("Demo Account"))
@ -315,7 +306,6 @@ pub mod prelude {
//! let mut preview = Image::default();
//!
//! preview
//! .set_kind(ImageType)
//! .set_url("https://localhost:8080/preview.png".parse::<XsdAnyUri>()?)
//! .set_media_type("image/png".parse()?)
//! .set_id("https://localhostst:8080/preview.png".parse()?);
@ -323,7 +313,6 @@ pub mod prelude {
//! let mut video = ApObject::<Video>::default();
//!
//! video
//! .set_kind(VideoType)
//! .set_id("http://localhost:8080/video.webm".parse()?)
//! .set_url("http://localhost:8080/video.webm".parse::<XsdAnyUri>()?)
//! .set_media_type("video/webm".parse()?)
@ -332,14 +321,12 @@ pub mod prelude {
//! .set_duration("PT4M20S".parse()?)
//! .set_shares("http://localhost:8080/video.webm#shares".parse()?);
//!
//! let mut activity = Create::builder()
//! .actor(person.into_any_base()?)
//! .object(video.into_any_base()?)
//! .inner(Default::default())
//! .build();
//! let mut activity = Create::new(
//! person.into_any_base()?,
//! video.into_any_base()?
//! );
//!
//! activity
//! .set_kind(CreateType)
//! .set_many_tos(vec![public()]);
//! #
//! # Ok(())

View file

@ -542,6 +542,20 @@ pub struct Link<Kind> {
}
impl<Kind> Link<Kind> {
/// Create a new Link
///
/// ```rust
/// use activitystreams_new::link::Link;
///
/// let link = Link::<String>::new();
/// ```
pub fn new() -> Self
where
Kind: Default,
{
Link::builder().inner(Base::new()).build()
}
fn extending(mut inner: Base<Kind>) -> Result<Self, serde_json::Error> {
Ok(Link {
href: inner.remove("href")?,

View file

@ -4245,8 +4245,11 @@ pub type Page = Object<PageType>;
/// that aren't already present on an Object.
pub type Video = Object<VideoType>;
/// Define all the properties of the Object base type as described by the Activity Streams
/// vocabulary.
/// 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.
#[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize, TypedBuilder)]
#[serde(rename_all = "camelCase")]
#[builder(doc)]
@ -4713,6 +4716,20 @@ pub struct Tombstone {
}
impl<Kind> Object<Kind> {
/// Create a new Object
///
/// ```rust
/// use activitystreams_new::object::Object;
///
/// let object = Object::<String>::new();
/// ```
pub fn new() -> Self
where
Kind: Default,
{
Object::builder().inner(Base::new()).build()
}
fn extending(mut base: Base<Kind>) -> Result<Self, serde_json::Error>
where
Kind: serde::de::DeserializeOwned,
@ -4803,6 +4820,20 @@ impl<Kind> Object<Kind> {
}
impl<Inner> ApObject<Inner> {
/// Create a new ActivityPub Object
///
/// ```rust
/// use activitystreams_new::object::{ApObject, Place};
///
/// let object = ApObject::new(Place::new());
/// ```
pub fn new(inner: Inner) -> Self
where
Inner: markers::Object,
{
ApObject::builder().inner(inner).build()
}
fn extending(mut inner: Inner) -> Result<Self, serde_json::Error>
where
Inner: UnparsedMut + markers::Object,
@ -4844,6 +4875,17 @@ impl<Inner> ApObject<Inner> {
}
impl Place {
/// Create a new ActivityPub Object
///
/// ```rust
/// use activitystreams_new::object::Place;
///
/// let object = Place::new();
/// ```
pub fn new() -> Self {
Place::builder().inner(Object::new()).build()
}
fn extending(mut inner: Object<PlaceType>) -> Result<Self, serde_json::Error> {
let accuracy = inner.remove("accuracy")?;
let altitude = inner.remove("altitude")?;
@ -4887,6 +4929,17 @@ impl Place {
}
impl Profile {
/// Create a new ActivityPub Object
///
/// ```rust
/// use activitystreams_new::object::Profile;
///
/// let object = Profile::new();
/// ```
pub fn new() -> Self {
Profile::builder().inner(Object::new()).build()
}
fn extending(mut inner: Object<ProfileType>) -> Result<Self, serde_json::Error> {
let describes = inner.remove("describes")?;
@ -4905,6 +4958,17 @@ impl Profile {
}
impl Relationship {
/// Create a new ActivityPub Object
///
/// ```rust
/// use activitystreams_new::object::Relationship;
///
/// let object = Relationship::new();
/// ```
pub fn new() -> Self {
Relationship::builder().inner(Object::new()).build()
}
fn extending(mut inner: Object<RelationshipType>) -> Result<Self, serde_json::Error> {
let subject = inner.remove("subject")?;
let object = inner.remove("object")?;
@ -4936,6 +5000,17 @@ impl Relationship {
}
impl Tombstone {
/// Create a new ActivityPub Object
///
/// ```rust
/// use activitystreams_new::object::Tombstone;
///
/// let object = Tombstone::new();
/// ```
pub fn new() -> Self {
Tombstone::builder().inner(Object::new()).build()
}
fn extending(mut inner: Object<TombstoneType>) -> Result<Self, serde_json::Error> {
let former_type = inner.remove("formerType")?;
let deleted = inner.remove("deleted")?;