Bring in new properties derive

This commit is contained in:
Aode 2020-03-09 12:56:59 -05:00
parent d738c5e8fa
commit 62c8d245ff
13 changed files with 1361 additions and 998 deletions

View file

@ -10,7 +10,7 @@ keywords = ["activitystreams", "activitypub"]
edition = "2018"
[dependencies]
activitystreams-traits = { version = "0.2", path = "activitystreams-traits" }
activitystreams-traits = { version = "0.3", path = "activitystreams-traits" }
activitystreams-types = { version = "0.3.0", path = "activitystreams-types" }
[dev-dependencies]
@ -18,7 +18,7 @@ anyhow = "1.0"
serde = "1.0"
serde_derive = "1.0"
serde_json = "1.0"
activitystreams-derive = { version = "0.2", path = "activitystreams-derive" }
activitystreams-derive = { version = "0.3", path = "activitystreams-derive" }
[workspace]
members = [

View file

@ -1,7 +1,7 @@
[package]
name = "activitystreams-derive"
description = "Derive macros for activitystreams"
version = "0.2.0"
version = "0.3.0"
license = "GPL-3.0"
authors = ["asonix <asonix.dev@gmail.com>"]
repository = "https://git.asonix.dog/Aardwolf/activitystreams"
@ -15,7 +15,7 @@ syn = "1.0"
proc-macro2 = "1.0"
[dev-dependencies]
activitystreams-traits = { version = "0.2", path = "../activitystreams-traits" }
activitystreams-traits = { version = "0.3", path = "../activitystreams-traits" }
serde = "1.0"
serde_derive = "1.0"
serde_json = "1.0"

File diff suppressed because it is too large Load diff

View file

@ -1,7 +1,7 @@
[package]
name = "activitystreams-traits"
description = "Traits for ActivityStreams objects"
version = "0.2.0"
description = "Traits for ActivityStreams 2.0 objects"
version = "0.3.0"
license = "GPL-3.0"
authors = ["asonix <asonix.dev@gmail.com>"]
repository = "https://git.asonix.dog/Aardwolf/activitystreams"
@ -10,9 +10,8 @@ keywords = ["activitystreams", "activitypub"]
edition = "2018"
[dependencies]
serde = "1.0"
serde_json = "1.0"
thiserror = "1.0"
typetag = "0.1.4"
[dev-dependencies]
serde_derive = "1.0"
serde = { version = "1.0", features = ["derive"] }

View file

@ -1,40 +0,0 @@
/*
* This file is part of ActivityStreams Traits.
*
* Copyright © 2018 Riley Trautman
*
* ActivityStreams Traits 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 Traits 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 Traits. If not, see <http://www.gnu.org/licenses/>.
*/
use std::result;
/// The Error type
#[derive(Copy, Clone, Debug, Eq, PartialEq, thiserror::Error)]
pub enum Error {
/// This error occurs when an Activity Streams type does not contain a requested value
#[error("Key not present")]
NotFound,
/// This error occurs when a requested value could not be deserialized into the requested type
#[error("Failed to deserialize data as requested type")]
Deserialize,
/// This error occurs when a provided item could not be serialized into an Activity Streams
/// type
#[error("Failed to serialize data")]
Serialize,
}
/// An alias for Result<T, Error>
pub type Result<T> = result::Result<T, Error>;

View file

@ -26,7 +26,7 @@
//!
//! ```rust
//! use activitystreams_traits::{Object, Actor};
//! use serde_derive::{Deserialize, Serialize};
//! use serde::{Deserialize, Serialize};
//!
//! #[derive(Clone, Debug, Default, Deserialize, Serialize)]
//! #[serde(rename_all = "camelCase")]
@ -38,7 +38,9 @@
//! kind: String,
//! }
//!
//! #[typetag::serde]
//! impl Object for Persona {}
//! #[typetag::serde]
//! impl Actor for Persona {}
//!
//! # fn main() {}
@ -47,14 +49,13 @@
mod activity;
mod actor;
mod collection;
mod error;
mod link;
mod object;
pub mod properties;
pub use self::activity::*;
pub use self::actor::*;
pub use self::collection::*;
pub use self::error::*;
pub use self::link::*;
pub use self::object::*;
pub use self::{
activity::{Activity, IntransitiveActivity},
actor::Actor,
collection::{Collection, CollectionPage},
link::Link,
object::Object,
};

View file

@ -17,7 +17,7 @@
* along with ActivityStreams Traits. If not, see <http://www.gnu.org/licenses/>.
*/
use serde::{de::DeserializeOwned, ser::Serialize};
use std::any::Any;
/// A Link is an indirect, qualified reference to a resource identified by a URL.
///
@ -27,4 +27,9 @@ use serde::{de::DeserializeOwned, ser::Serialize};
/// 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.
pub trait Link: DeserializeOwned + Serialize {}
#[typetag::serde(tag = "type")]
pub trait Link: std::fmt::Debug {
fn as_any(&self) -> &dyn Any;
fn as_any_mut(&mut self) -> &mut dyn Any;
}

View file

@ -17,11 +17,16 @@
* along with ActivityStreams Traits. If not, see <http://www.gnu.org/licenses/>.
*/
use serde::{de::DeserializeOwned, ser::Serialize};
use std::any::Any;
/// 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`.
pub trait Object: DeserializeOwned + Serialize {}
#[typetag::serde(tag = "type")]
pub trait Object: std::fmt::Debug {
fn as_any(&self) -> &dyn Any;
fn as_any_mut(&mut self) -> &mut dyn Any;
}

View file

@ -1,89 +0,0 @@
/*
* This file is part of ActivityStreams Traits.
*
* Copyright © 2018 Riley Trautman
*
* ActivityStreams Traits 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 Traits 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 Traits. If not, see <http://www.gnu.org/licenses/>.
*/
//! A module containing helpers for tranlsating common JSON representations to and from concrete
//! types
use serde::{de::DeserializeOwned, ser::Serialize};
use crate::error::{Error, Result};
/// Deserialize a `Value` into concrete type I
pub fn from_value<I>(item: &serde_json::Value) -> Result<I>
where
I: DeserializeOwned,
{
serde_json::from_value(item.clone()).map_err(|_| Error::Deserialize)
}
/// Serialize concrete type I into a `Value`
pub fn to_value<I>(item: I) -> Result<serde_json::Value>
where
I: Serialize,
{
serde_json::to_value(item).map_err(|_| Error::Serialize)
}
/// Deserialize an `Option<Value>` into concrete type I
pub fn from_item<I>(item: &Option<serde_json::Value>) -> Result<I>
where
I: DeserializeOwned,
{
if let &Some(ref item) = item {
from_value(item)
} else {
Err(Error::NotFound)
}
}
/// Serialize concrete type I into an `Option<Value>`
pub fn to_item<I>(item: I) -> Result<Option<serde_json::Value>>
where
I: Serialize,
{
to_value(item).map(Some)
}
/// Deserialize a `Vec<Value>` into a `Vec<I>`
pub fn from_vec<I>(v: &Vec<serde_json::Value>) -> Result<Vec<I>>
where
I: DeserializeOwned,
{
v.iter().fold(Ok(Vec::new()), |acc, item| match acc {
Ok(mut acc) => from_value(item).map(|item| {
acc.push(item);
acc
}),
e => e,
})
}
/// Serialize a `Vec<I>` into a `Vec<Value>`
pub fn to_vec<I>(v: Vec<I>) -> Result<Vec<serde_json::Value>>
where
I: Serialize,
{
v.into_iter().fold(Ok(Vec::new()), |acc, item| match acc {
Ok(mut acc) => to_value(item).map(|item| {
acc.push(item);
acc
}),
e => e,
})
}

View file

@ -11,13 +11,13 @@ edition = "2018"
[dependencies]
thiserror = "1.0.11"
activitystreams-derive = { version = "0.2", path = "../activitystreams-derive" }
activitystreams-traits = { version = "0.2", path = "../activitystreams-traits" }
activitystreams-derive = { version = "0.3", path = "../activitystreams-derive" }
activitystreams-traits = { version = "0.3", path = "../activitystreams-traits" }
chrono = { version = "0.4", features = ["serde"] }
mime = "0.3"
serde = "1.0"
serde_derive = "1.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
typetag = "0.1.4"
[dev-dependencies]
anyhow = "1.0"

View file

@ -59,3 +59,47 @@ impl LinkExt for Mention {
&mut self.link_props
}
}
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(transparent)]
pub struct LinkBox(pub Box<dyn Link>);
impl LinkBox {
pub fn is<T>(&self) -> bool
where
T: Link,
{
self.0.as_any().is::<T>()
}
pub fn downcast_ref<T>(&self) -> Option<&T>
where
T: Link,
{
self.0.as_any().downcast_ref()
}
pub fn downcast_mut<T>(&mut self) -> Option<&mut T>
where
T: Link,
{
self.0.as_any_mut().downcast_mut()
}
pub fn downcast<T>(self) -> Option<T>
where
T: Link,
{
let any: Box<dyn Any> = self;
any.downcast()
}
}
impl<T> From<T> for LinkBox
where
T: Link,
{
fn from(t: T) -> Self {
LinkBox(Box::new(t))
}
}

View file

@ -182,7 +182,7 @@ 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, Serialize, PropRefs, Properties)]
#[derive(Clone, Debug, Default, Deserialize, PropRefs, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Profile {
#[serde(rename = "type")]
@ -215,7 +215,7 @@ 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, Serialize, Properties, PropRefs)]
#[derive(Clone, Debug, Default, Deserialize, PropRefs, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Relationship {
#[serde(rename = "type")]
@ -271,3 +271,63 @@ pub struct Video {
#[activitystreams(Object)]
pub object_props: ObjectProperties,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(transparent)]
pub struct ImageBox(pub Box<Image>);
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(transparent)]
pub struct ObjectBox(pub Box<dyn Object>);
impl ObjectBox {
pub fn is<T>(&self) -> bool
where
T: Object,
{
self.0.as_any().is::<T>()
}
pub fn downcast_ref<T>(&self) -> Option<&T>
where
T: Object,
{
self.0.as_any().downcast_ref()
}
pub fn downcast_mut<T>(&mut self) -> Option<&mut T>
where
T: Object,
{
self.0.as_any_mut().downcast_mut()
}
pub fn downcast<T>(self) -> Option<T>
where
T: Object,
{
let any: Box<dyn Any> = self;
any.downcast()
}
}
impl From<Image> for ImageBox {
fn from(i: Image) -> Self {
ImageBox(Box::new(i))
}
}
impl From<ImageBox> for Image {
fn from(i: ImageBox) -> Self {
*i.0
}
}
impl<T> From<T> for ObjectBox
where
T: Object,
{
fn from(t: T) -> Self {
ObjectBox(Box::new(t))
}
}

View file

@ -32,7 +32,7 @@
//! #[serde(rename = "type")]
//! pub kind: String,
//!
//! /// Define a require property for the MyObject type
//! /// Define a required property for the MyObject type
//! pub my_property: String,
//!
//! #[serde(flatten)]
@ -44,15 +44,16 @@
//! # fn main() {}
//! ```
use activitystreams_derive::Properties;
use activitystreams_derive::properties;
use activitystreams_traits::{Collection, Error, Link, Object, Result};
use chrono::{offset::Utc, DateTime};
use serde_derive::{Deserialize, Serialize};
use crate::object::Image;
/// Alias chrono::DateTime<Utc> for use in derive macros
pub type UtcTime = DateTime<Utc>;
use crate::{
link::LinkBox,
object::{Image, ObjectBox},
primitives::*,
};
/// Define all the properties of the Object base type as described by the Activity Streams
/// vocabulary.
@ -66,22 +67,23 @@ pub type UtcTime = DateTime<Utc>;
/// own `type` properties as Unit Structs with custom serde behaviour.
///
/// All properties are optional (including the id and type).
#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)]
#[serde(rename_all = "camelCase")]
pub struct ObjectProperties {
// TODO: IRI type
properties! {
Object {
id {
/// Provides the globally unique identifier for an Object or Link.
///
/// The `id` property is expressed as an absolute IRI in the spec, but for now is represented
/// as a string.
///
/// - Range: `anyUri`
/// - Range: `xsd:anyUri`
/// - Functional: true
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(alias = "@id")]
#[activitystreams(concrete(String), functional)]
pub id: Option<serde_json::Value>,
types [
XsdAnyUri,
],
functional,
},
attachment {
/// Identifies a resource attached or related to an object that potentially requires special
/// handling.
///
@ -90,10 +92,14 @@ pub struct ObjectProperties {
///
/// - Range: `Object` | `Link`
/// - Functional: false
#[serde(skip_serializing_if = "Option::is_none")]
#[activitystreams(ab(Object, Link), concrete(String))]
pub attachment: Option<serde_json::Value>,
types [
XsdAnyUri,
ObjectBox,
LinkBox,
],
},
attributed_to {
/// Identifies one or more entities to which this object is attributed.
///
/// The attributed entities might not be Actors. For instance, an object might be attributed to
@ -101,20 +107,27 @@ pub struct ObjectProperties {
///
/// - Range: `Object` | `Link`
/// - Functional: false
#[serde(skip_serializing_if = "Option::is_none")]
#[activitystreams(ab(Object, Link), concrete(String))]
pub attributed_to: Option<serde_json::Value>,
types [
XsdAnyUri,
ObjectBox,
LinkBox,
],
},
audience {
/// Identifies one or more entities that represent the total population of entities for which
/// the object can considered to be relevant.
///
/// - Range: `Object` | `Link`
/// - Functional: false
#[serde(skip_serializing_if = "Option::is_none")]
#[activitystreams(ab(Object, Link), concrete(String))]
pub audience: Option<serde_json::Value>,
types [
XsdAnyUri,
ObjectBox,
LinkBox,
],
},
// TODO: rdf:langString
content {
/// The content or textual representation of the Object encoded as a JSON string.
///
/// By default, the value of content is HTML. The mediaType property can be used in the object
@ -124,10 +137,13 @@ pub struct ObjectProperties {
///
/// - Range: `xsd:string` | `rdf:langString`
/// - Functional: false
#[serde(skip_serializing_if = "Option::is_none")]
#[activitystreams(concrete(String))]
pub content: Option<serde_json::Value>,
types [
XsdString,
RdfLangString,
],
},
context {
/// Identifies the context within which the object exists or an activity was performed.
///
/// The notion of "context" used is intentionally vague. The intended function is to serve as a
@ -136,11 +152,14 @@ pub struct ObjectProperties {
///
/// - Range: `Object` | `Link`
/// - Functional: false
#[serde(skip_serializing_if = "Option::is_none", rename = "@context")]
#[activitystreams(ab(Object, Link), concrete(String))]
pub context: Option<serde_json::Value>,
types [
XsdAnyUri,
ObjectBox,
LinkBox,
],
},
// TODO: rdf:langString
name {
/// A simple, human-readable, plain-text name for the object.
///
/// HTML markup MUST NOT be included. The name MAY be expressed using multiple language-tagged
@ -148,11 +167,14 @@ pub struct ObjectProperties {
///
/// - Range: `xsd:string` | `rdf:langString`
/// - Functional: false
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(alias = "displayName")]
#[activitystreams(concrete(String))]
pub name: Option<serde_json::Value>,
types [
XsdString,
RdfLangString,
],
alias("displayName"),
},
end_time {
/// The date and time describing the actual or expected ending time of the object.
///
/// When used with an Activity object, for instance, the endTime property specifies the moment
@ -160,18 +182,25 @@ pub struct ObjectProperties {
///
/// - Range: `xsd:dateTime`
/// - Functional: true
#[serde(skip_serializing_if = "Option::is_none")]
#[activitystreams(concrete(String, UtcTime), functional)]
pub end_time: Option<serde_json::Value>,
types [
XsdDateTime,
],
functional,
},
generator {
/// Identifies the entity (e.g. an application) that generated the object.
///
/// - Range: `Object` | `Link`
/// - Functional: false
#[serde(skip_serializing_if = "Option::is_none")]
#[activitystreams(ab(Object, Link), concrete(String))]
pub generator: Option<serde_json::Value>,
types [
XsdAnyUri,
ObjectBox,
LinkBox,
],
},
icon {
/// Indicates an entity that describes an icon for this object.
///
/// The image should have an aspect ratio of one (horizontal) to one (vertical) and should be
@ -179,82 +208,114 @@ pub struct ObjectProperties {
///
/// - Range: `Image` | `Link`
/// - Functional: false
#[serde(skip_serializing_if = "Option::is_none")]
#[activitystreams(ab(Object, Link), concrete(Image, String))]
pub icon: Option<serde_json::Value>,
types [
XsdAnyUri,
ImageBox,
LinkBox,
],
},
image {
/// Indicates an entity that describes an image for this object.
///
/// Unlike the icon property, there are no aspect ratio or display size limitations assumed.
///
/// - Range: `Image` | `Link`
/// - Functional: false
#[serde(skip_serializing_if = "Option::is_none")]
#[activitystreams(ab(Object, Link), concrete(Image, String))]
pub image: Option<serde_json::Value>,
types [
XsdAnyUri,
ImageBox,
LinkBox,
],
},
in_reply_to {
/// Indicates one or more entities for which this object is considered a response.
///
/// - Range: `Object` | `Link`
/// - Functional: false
#[serde(skip_serializing_if = "Option::is_none")]
#[activitystreams(ab(Object, Link), concrete(String))]
pub in_reply_to: Option<serde_json::Value>,
types [
XsdAnyUri,
ObjectBox,
LinkBox,
],
},
location {
/// Indicates one or more physical or logical locations associated with the object.
///
/// - Range: `Object` | `Link`
/// - Functional: false
#[serde(skip_serializing_if = "Option::is_none")]
#[activitystreams(ab(Object, Link), concrete(String))]
pub location: Option<serde_json::Value>,
types [
XsdAnyUri,
ObjectBox,
LinkBox,
],
},
preview {
/// Identifies an entity that provides a preview of this object.
///
/// - Range: `Object` | `Link`
/// - Functional: false
#[serde(skip_serializing_if = "Option::is_none")]
#[activitystreams(ab(Object, Link), concrete(String))]
pub preview: Option<serde_json::Value>,
types [
XsdAnyUri,
ObjectBox,
LinkBox,
],
},
published {
/// The date and time at which the object was published.
///
/// - Range: `xsd:dateTime`
/// - Functional: true
#[serde(skip_serializing_if = "Option::is_none")]
#[activitystreams(concrete(String, UtcTime), functional)]
pub published: Option<serde_json::Value>,
types [
XsdDateTime,
],
functional,
},
replies {
/// Identifies a `Collection` containing objects considered to be responses to this object.
///
/// - Range: `Object` | `Link`
/// - Functional: false
#[serde(skip_serializing_if = "Option::is_none")]
#[activitystreams(ab(Collection), concrete(String), functional)]
pub replies: Option<serde_json::Value>,
types [
XsdAnyUri,
ObjectBox,
LinkBox,
],
},
start_time {
/// The date and time describing the actual or expected starting time of the object.
///
/// When used with an `Activity` object, for instance, the `start_time` property specifies the
/// moment the activity began or is scheduled to begin.
///
/// - Range: `Object` | `Link`
/// - Range: `xsd:DateTime`
/// - Functional: true
#[serde(skip_serializing_if = "Option::is_none")]
#[activitystreams(concrete(String, UtcTime), functional)]
pub start_time: Option<serde_json::Value>,
types [
XsdDateTime,
],
functional,
},
// TODO: rdf:langString
summary {
/// A natural language summarization of the object encoded as HTML.
///
/// Multiple language tagged summaries MAY be provided.
///
/// - Range: `xsd:string` | `rdf:langString`
/// - Functional: false
#[serde(skip_serializing_if = "Option::is_none")]
#[activitystreams(concrete(String))]
pub summary: Option<serde_json::Value>,
types [
XsdString,
RdfLangString,
],
},
tag {
/// One or more "tags" that have been associated with an objects. A tag can be any kind of
/// `Object`.
///
@ -263,59 +324,85 @@ pub struct ObjectProperties {
///
/// - Range: `Object` | `Link`
/// - Functional: false
#[serde(skip_serializing_if = "Option::is_none")]
#[activitystreams(ab(Object, Link), concrete(String))]
pub tag: Option<serde_json::Value>,
types [
XsdAnyUri,
ObjectBox,
LinkBox,
],
},
updated {
/// The date and time at which the object was updated,
///
/// - Range: `xsd:dateTime`
/// - Functional: true
#[serde(skip_serializing_if = "Option::is_none")]
#[activitystreams(concrete(String, UtcTime), functional)]
pub updated: Option<serde_json::Value>,
types [
XsdDateTime,
],
functional,
},
url {
/// Identifies one or more links to representations of the object.
///
/// - Range: `xsd:anyUri` | `Link`
/// - Functional: false
#[serde(skip_serializing_if = "Option::is_none")]
#[activitystreams(concrete(String), ab(Link))]
pub url: Option<serde_json::Value>,
types [
XsdAnyUri,
LinkBox,
],
},
to {
/// Identifies an entity considered to be part of the public primary audience of an `Object`.
///
/// - Range: `Object` | `Link`
/// - Functional: false
#[serde(skip_serializing_if = "Option::is_none")]
#[activitystreams(ab(Object, Link), concrete(String))]
pub to: Option<serde_json::Value>,
types [
XsdAnyUri,
ObjectBox,
LinkBox,
],
},
bto {
/// Identifies an `Object` that is part of the private primary audience of this `Object`.
///
/// - Range: `Object` | `Link`
/// - Functional: false
#[serde(skip_serializing_if = "Option::is_none")]
#[activitystreams(ab(Object, Link), concrete(String))]
pub bto: Option<serde_json::Value>,
types [
XsdAnyUri,
ObjectBox,
LinkBox,
],
},
cc {
/// Identifies an `Object` that is part of the public secondary audience of this `Object`.
///
/// - Range: `Object` | `Link`
/// - Functional: false
#[serde(skip_serializing_if = "Option::is_none")]
#[activitystreams(ab(Object, Link), concrete(String))]
pub cc: Option<serde_json::Value>,
types [
XsdAnyUri,
ObjectBox,
LinkBox,
],
},
bcc {
/// Identifies one or more `Objects` that are part of the private secondary audience of this
/// `Object`.
///
/// - Range: `Object` | `Link`
/// - Functional: false
#[serde(skip_serializing_if = "Option::is_none")]
#[activitystreams(ab(Object, Link), concrete(String))]
pub bcc: Option<serde_json::Value>,
types [
XsdAnyUri,
ObjectBox,
LinkBox,
],
},
media_type {
/// When used on an `Object`, identifies the MIME media type of the value of the content
/// property.
///
@ -323,11 +410,13 @@ pub struct ObjectProperties {
///
/// - Range: `Mime Media Type`
/// - Functional: true
#[serde(skip_serializing_if = "Option::is_none")]
#[activitystreams(concrete(String), functional)]
pub media_type: Option<serde_json::Value>,
types [
MimeMediaType,
],
functional,
},
// TODO: xsd:duration
duration {
/// When the object describes a time-bound resource, such as an audio or video, a meeting, etc,
/// the duration property indicates the object's approximate duration.
///
@ -337,33 +426,31 @@ pub struct ObjectProperties {
///
/// - Range: `xsd:duration`
/// - Functional: true
#[serde(skip_serializing_if = "Option::is_none")]
#[activitystreams(concrete(String), functional)]
pub duration: Option<serde_json::Value>,
}
impl ObjectProperties {
/// Fetch a typed `Mime` struct from the `media_type` field.
pub fn media_type(&self) -> Result<mime::Mime> {
self.media_type_string()
.and_then(|s| s.parse().map_err(|_| Error::Deserialize))
types [
XsdDuration,
],
functional,
},
}
}
/// Define all the properties of the Location type as described by the Activity Streams vocabulary.
#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)]
#[serde(rename_all = "camelCase")]
pub struct PlaceProperties {
properties! {
Place {
accuracy {
/// Indicates the accuracy of position coordinates on a `Place` objects.
///
/// Expressed in properties of percentage. e.g. "94.0" means "94.0% accurate".
///
/// - Range: `xsd:float` [>= 0.0f, <= 100.0f]
/// - Functional: true
#[serde(skip_serializing_if = "Option::is_none")]
#[activitystreams(concrete(f64), functional)]
pub accuracy: Option<serde_json::Value>,
types [
XsdFloat,
],
functional,
},
altitude {
/// Indicates the altitude of a place. The measurement units is indicated using the units
/// property.
///
@ -371,26 +458,35 @@ pub struct PlaceProperties {
///
/// - Range: `xsd:float`
/// - Functional: true
#[serde(skip_serializing_if = "Option::is_none")]
#[activitystreams(concrete(f64), functional)]
pub altitude: Option<serde_json::Value>,
types [
XsdFloat,
],
functional,
},
latitude {
/// The latitude of a place.
///
/// - Range: `xsd:float`
/// - Functional: true
#[serde(skip_serializing_if = "Option::is_none")]
#[activitystreams(concrete(f64), functional)]
pub latitude: Option<serde_json::Value>,
types [
XsdFloat,
],
functional,
}
logitude {
/// The longitude of a place.
///
/// - Range: `xsd:float`
/// - Functional: true
#[serde(skip_serializing_if = "Option::is_none")]
#[activitystreams(concrete(f64), functional)]
pub longitude: Option<serde_json::Value>,
types [
XsdFloat,
],
functional,
},
radius {
/// The radius from the given latitude and longitude for a Place.
///
/// The units is expressed by the units property. If units is not specified, the default is
@ -398,39 +494,52 @@ pub struct PlaceProperties {
///
/// - Range: `xsd:float`
/// - Functional: true
#[serde(skip_serializing_if = "Option::is_none")]
#[activitystreams(concrete(f64), functional)]
pub radius: Option<serde_json::Value>,
types [
XsdFloat,
],
functional,
},
units {
/// Specifies the measurement units for the radius and altitude properties on a `Place` object.
///
/// If not specified, the default is assumed to be "m" for "meters".
///
/// - Range: `xsd:float`
/// TODO: encode rage as any of `"cm"` | `"feet"` | `"inches"` | `"km"` | `"m"` | `xsd:anyUri`
/// - Range: `xsd:anyUri` | `xsd:string`
/// - Functional: true
#[serde(skip_serializing_if = "Option::is_none")]
#[activitystreams(concrete(String), functional)]
pub units: Option<serde_json::Value>,
types [
XsdAnyUri,
XsdString,
],
functional,
},
}
}
/// Define all the properties of the Profile type as described by the Activity Streams vocabulary.
#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)]
#[serde(rename_all = "camelCase")]
pub struct ProfileProperties {
properties! {
Profile {
describes {
/// On a `Profile` object, the describes property identifies the object described by the
/// `Profile`.
///
/// - Range: `Object`
/// - Functional: true
#[activitystreams(ab(Object), concrete(String), functional)]
pub describes: serde_json::Value,
types [
XsdAnyUri,
ObjectBox,
],
functional,
},
}
}
/// Define all the properties of the Relationship type as described by the Activity Streams
/// vocabulary.
#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)]
#[serde(rename_all = "camelCase")]
pub struct RelationshipProperties {
properties! {
Relationship {
subject {
/// On a `Relationship` object, the subject property identifies one of the connected
/// individuals.
///
@ -439,44 +548,65 @@ pub struct RelationshipProperties {
///
/// - Range: `Object` | `Link`
/// - Functional: true
#[activitystreams(ab(Object, Link), concrete(String), functional)]
subject: serde_json::Value,
types [
XsdAnyUri,
ObjectBox,
LinkBox,
],
functional,
},
object {
/// When used within a `Relationship` describes the entity to which the subject is related.
///
/// - Range: `Object` | `Link`
/// - Functional: false
#[activitystreams(ab(Object, Link), concrete(String))]
object: serde_json::Value,
types [
XsdAnyUri,
ObjectBox,
LinkBox,
],
},
relationship {
/// On a `Relationship` object, the relationship property identifies the kind of relationship
/// that exists between subject and object.
///
/// - Range: `Object`
/// - Functional: false
#[activitystreams(ab(Object), concrete(String))]
relationship: serde_json::Value,
types [
XsdAnyUri,
ObjectBox,
],
},
}
}
/// Define all the properties of the Tombstone type as described by the Activity Streams vocabulary.
#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)]
#[serde(rename_all = "camelCase")]
pub struct TombstoneProperties {
properties! {
Tombstone {
former_type {
/// On a `Tombstone` object, the formerType property identifies the type of the object that was
/// deleted.
///
/// - Range: `Object`
/// - Functional: false
#[serde(skip_serializing_if = "Option::is_none")]
#[activitystreams(ab(Object), concrete(String))]
pub former_type: Option<serde_json::Value>,
types [
XsdAnyUri,
ObjectBox,
],
},
deleted {
/// On a `Tombstone` object, the deleted property is a timestamp for when the object was
/// deleted.
///
/// - Range: `xsd:dateTime`
/// - Functional: true
#[serde(skip_serializing_if = "Option::is_none")]
#[activitystreams(concrete(String, UtcTime), functional)]
pub deleted: Option<serde_json::Value>,
types [
XsdDateTime,
],
functional,
},
}
}