mirror of
https://git.asonix.dog/asonix/activitystreams.git
synced 2024-11-22 03:40:59 +00:00
Use codegen to reduce library size by a lot
This commit is contained in:
parent
70d4bab312
commit
07f3d2add3
100 changed files with 1070 additions and 3998 deletions
|
@ -1,9 +1,10 @@
|
|||
[package]
|
||||
name = "activitypub"
|
||||
name = "activitystreams"
|
||||
version = "0.1.0"
|
||||
authors = ["asonix <asonix.dev@gmail.com>"]
|
||||
|
||||
[dependencies]
|
||||
activitystreams-derive = { version = "0.1", path = "activitystreams-derive" }
|
||||
failure = "0.1"
|
||||
mime = "0.3"
|
||||
serde = "1.0"
|
||||
|
|
3
activitystreams-derive/.gitignore
vendored
Normal file
3
activitystreams-derive/.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
/target
|
||||
**/*.rs.bk
|
||||
Cargo.lock
|
12
activitystreams-derive/Cargo.toml
Normal file
12
activitystreams-derive/Cargo.toml
Normal file
|
@ -0,0 +1,12 @@
|
|||
[package]
|
||||
name = "activitystreams-derive"
|
||||
version = "0.1.0"
|
||||
authors = ["asonix <asonix.dev@gmail.com>"]
|
||||
|
||||
[dependencies]
|
||||
quote = "0.5"
|
||||
syn = "0.13"
|
||||
proc-macro2 = "0.3"
|
||||
|
||||
[lib]
|
||||
proc-macro = true
|
351
activitystreams-derive/src/lib.rs
Normal file
351
activitystreams-derive/src/lib.rs
Normal file
|
@ -0,0 +1,351 @@
|
|||
extern crate proc_macro;
|
||||
extern crate proc_macro2;
|
||||
extern crate syn;
|
||||
|
||||
#[macro_use]
|
||||
extern crate quote;
|
||||
|
||||
use proc_macro::TokenStream;
|
||||
use proc_macro2::TokenTree;
|
||||
use quote::Tokens;
|
||||
use syn::{Attribute, Data, DeriveInput, Fields, Ident, Type};
|
||||
|
||||
#[proc_macro_derive(UnitString, attributes(activitystreams))]
|
||||
pub fn unit_string(input: TokenStream) -> TokenStream {
|
||||
let input: DeriveInput = syn::parse(input).unwrap();
|
||||
|
||||
let name = input.ident;
|
||||
|
||||
let attr = input
|
||||
.attrs
|
||||
.iter()
|
||||
.find(|attribute| {
|
||||
attribute
|
||||
.path
|
||||
.segments
|
||||
.last()
|
||||
.map(|segment| {
|
||||
let segment = segment.into_value();
|
||||
segment.ident == Ident::new("activitystreams", segment.ident.span())
|
||||
})
|
||||
.unwrap_or(false)
|
||||
})
|
||||
.unwrap()
|
||||
.clone();
|
||||
|
||||
let value = get_value(attr);
|
||||
|
||||
let visitor_name = Ident::from(format!("{}Visitor", value));
|
||||
|
||||
let serialize = quote! {
|
||||
impl Serialize for #name {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_str(#value)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let expecting = quote! {
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(formatter, "The string '{}'", #value)
|
||||
}
|
||||
};
|
||||
|
||||
let visit = quote! {
|
||||
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
if v == #value {
|
||||
Ok(#name)
|
||||
} else {
|
||||
Err(de::Error::custom("Invalid type"))
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let visitor = quote! {
|
||||
pub struct #visitor_name;
|
||||
|
||||
impl<'de> Visitor<'de> for #visitor_name {
|
||||
type Value = #name;
|
||||
|
||||
#expecting
|
||||
|
||||
#visit
|
||||
}
|
||||
};
|
||||
|
||||
let deserialize = quote! {
|
||||
impl<'de> Deserialize<'de> for #name {
|
||||
fn deserialize<D>(deserializer: D) -> Result<#name, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
deserializer.deserialize_str(#visitor_name)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let c = quote! {
|
||||
#serialize
|
||||
#visitor
|
||||
#deserialize
|
||||
};
|
||||
|
||||
c.into()
|
||||
}
|
||||
|
||||
fn get_value(attr: Attribute) -> String {
|
||||
let group = attr.tts
|
||||
.clone()
|
||||
.into_iter()
|
||||
.filter_map(|token_tree| match token_tree {
|
||||
TokenTree::Group(group) => Some(group),
|
||||
_ => None,
|
||||
})
|
||||
.next()
|
||||
.unwrap();
|
||||
|
||||
group
|
||||
.stream()
|
||||
.clone()
|
||||
.into_iter()
|
||||
.filter_map(|token_tree| match token_tree {
|
||||
TokenTree::Term(term) => Some(term.as_str().to_owned()),
|
||||
_ => None,
|
||||
})
|
||||
.next()
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
#[proc_macro_derive(Properties, attributes(activitystreams))]
|
||||
pub fn properties_derive(input: TokenStream) -> TokenStream {
|
||||
let input: DeriveInput = syn::parse(input).unwrap();
|
||||
|
||||
let name = input.ident;
|
||||
|
||||
let data = match input.data {
|
||||
Data::Struct(s) => s,
|
||||
_ => panic!("Can only derive for structs"),
|
||||
};
|
||||
|
||||
let fields = match data.fields {
|
||||
Fields::Named(fields) => fields,
|
||||
_ => panic!("Can only derive for named fields"),
|
||||
};
|
||||
|
||||
let getters = fields
|
||||
.named
|
||||
.iter()
|
||||
.filter_map(|field| {
|
||||
let our_attr = field.attrs.iter().find(|attribute| {
|
||||
attribute
|
||||
.path
|
||||
.segments
|
||||
.last()
|
||||
.map(|segment| {
|
||||
let segment = segment.into_value();
|
||||
segment.ident == Ident::new("activitystreams", segment.ident.span())
|
||||
})
|
||||
.unwrap_or(false)
|
||||
});
|
||||
|
||||
if our_attr.is_some() {
|
||||
let our_attr = our_attr.unwrap();
|
||||
|
||||
let is_option = match field.ty {
|
||||
Type::Path(ref path) => path.path
|
||||
.segments
|
||||
.last()
|
||||
.map(|seg| {
|
||||
let seg = seg.into_value();
|
||||
seg.ident == Ident::new("Option", seg.ident.span())
|
||||
})
|
||||
.unwrap_or(false),
|
||||
_ => false,
|
||||
};
|
||||
|
||||
let is_vec = match field.ty {
|
||||
Type::Path(ref path) => path.path
|
||||
.segments
|
||||
.last()
|
||||
.map(|seg| {
|
||||
let seg = seg.into_value();
|
||||
seg.ident == Ident::new("Vec", seg.ident.span())
|
||||
})
|
||||
.unwrap_or(false),
|
||||
_ => false,
|
||||
};
|
||||
|
||||
Some((
|
||||
field.ident.clone().unwrap(),
|
||||
is_option,
|
||||
is_vec,
|
||||
is_functional(our_attr.clone()),
|
||||
our_attr.clone(),
|
||||
))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.flat_map(|(ident, is_option, is_vec, is_functional, attr)| {
|
||||
variants(attr)
|
||||
.into_iter()
|
||||
.map(move |(variant, is_concrete)| {
|
||||
let lower_variant = variant.to_lowercase();
|
||||
let fn_name = Ident::from(format!("{}_{}", ident, lower_variant));
|
||||
let fn_plural = Ident::from(format!("{}_{}_vec", ident, lower_variant));
|
||||
let variant = Ident::from(variant);
|
||||
|
||||
if is_concrete && is_option && is_functional {
|
||||
quote! {
|
||||
pub fn #fn_name(&self) -> Result<#variant> {
|
||||
self.get_item(|t| &t.#ident)
|
||||
}
|
||||
}
|
||||
} else if is_concrete && is_option {
|
||||
quote! {
|
||||
pub fn #fn_name(&self) -> Result<#variant> {
|
||||
self.get_item(|t| &t.#ident)
|
||||
}
|
||||
|
||||
pub fn #fn_plural(&self) -> Result<Vec<#variant>> {
|
||||
self.get_item(|t| &t.#ident)
|
||||
}
|
||||
}
|
||||
} else if is_concrete && is_vec {
|
||||
quote! {
|
||||
pub fn #fn_name(&self) -> Result<Vec<#variant>> {
|
||||
self.get_vec(|t| &t.#ident)
|
||||
}
|
||||
}
|
||||
} else if is_concrete && is_functional {
|
||||
quote! {
|
||||
pub fn #fn_name(&self) -> Result<#variant> {
|
||||
self.get_value(|t| &t.#ident)
|
||||
}
|
||||
}
|
||||
} else if is_concrete {
|
||||
quote! {
|
||||
pub fn #fn_name(&self) -> Result<#variant> {
|
||||
self.get_value(|t| &t.#ident)
|
||||
}
|
||||
|
||||
pub fn #fn_plural(&self) -> Result<Vec<#variant>> {
|
||||
self.get_value(|t| &t.#ident)
|
||||
}
|
||||
}
|
||||
} else if is_option && is_functional {
|
||||
quote! {
|
||||
pub fn #fn_name<T: #variant>(&self) -> Result<T> {
|
||||
self.get_item(|t| &t.#ident)
|
||||
}
|
||||
}
|
||||
} else if is_option {
|
||||
quote! {
|
||||
pub fn #fn_name<T: #variant>(&self) -> Result<T> {
|
||||
self.get_item(|t| &t.#ident)
|
||||
}
|
||||
|
||||
pub fn #fn_plural<T: #variant>(&self) -> Result<Vec<T>> {
|
||||
self.get_item(|t| &t.#ident)
|
||||
}
|
||||
}
|
||||
} else if is_vec {
|
||||
quote! {
|
||||
pub fn #fn_name<T: #variant>(&self) -> Result<Vec<T>> {
|
||||
self.get_vec(|t| &t.#ident)
|
||||
}
|
||||
}
|
||||
} else if is_functional {
|
||||
quote! {
|
||||
pub fn #fn_name<T: #variant>(&self) -> Result<T> {
|
||||
self.get_value(|t| &t.#ident)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
quote! {
|
||||
pub fn #fn_name<T: #variant>(&self) -> Result<T> {
|
||||
self.get_value(|t| &t.#ident)
|
||||
}
|
||||
|
||||
pub fn #fn_plural<T: #variant>(&self) -> Result<Vec<T>> {
|
||||
self.get_value(|t| &t.#ident)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
let mut tokens = Tokens::new();
|
||||
tokens.append_all(getters);
|
||||
|
||||
let full = quote!{
|
||||
impl Properties for #name {}
|
||||
|
||||
impl #name {
|
||||
#tokens
|
||||
}
|
||||
};
|
||||
|
||||
full.into()
|
||||
}
|
||||
|
||||
fn variants(attr: Attribute) -> Vec<(String, bool)> {
|
||||
let group = attr.tts
|
||||
.clone()
|
||||
.into_iter()
|
||||
.filter_map(|token_tree| match token_tree {
|
||||
TokenTree::Group(group) => Some(group),
|
||||
_ => None,
|
||||
})
|
||||
.next()
|
||||
.unwrap();
|
||||
|
||||
let mut is_concrete = false;
|
||||
|
||||
group
|
||||
.stream()
|
||||
.clone()
|
||||
.into_iter()
|
||||
.filter_map(|token_tree| match token_tree {
|
||||
TokenTree::Term(term) => {
|
||||
is_concrete = term.as_str() == "concrete";
|
||||
None
|
||||
}
|
||||
TokenTree::Group(group) => Some(group.stream().into_iter().filter_map(
|
||||
move |token_tree| match token_tree {
|
||||
TokenTree::Term(term) => Some((term.as_str().to_owned(), is_concrete)),
|
||||
_ => None,
|
||||
},
|
||||
)),
|
||||
_ => None,
|
||||
})
|
||||
.flat_map(|i| i)
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn is_functional(attr: Attribute) -> bool {
|
||||
let group = attr.tts
|
||||
.clone()
|
||||
.into_iter()
|
||||
.filter_map(|token_tree| match token_tree {
|
||||
TokenTree::Group(group) => Some(group),
|
||||
_ => None,
|
||||
})
|
||||
.next()
|
||||
.unwrap();
|
||||
|
||||
group
|
||||
.stream()
|
||||
.clone()
|
||||
.into_iter()
|
||||
.any(|token_tree| match token_tree {
|
||||
TokenTree::Term(term) => term.as_str() == "functional",
|
||||
_ => false,
|
||||
})
|
||||
}
|
|
@ -2,48 +2,29 @@ use serde_json;
|
|||
|
||||
use super::{kind::AcceptType, properties::ActivityProperties, Activity};
|
||||
|
||||
use error::{Error, Result};
|
||||
use error::Result;
|
||||
use link::Link;
|
||||
use object::{Object, ObjectProperties};
|
||||
use Properties;
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, Properties)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Accept {
|
||||
#[serde(rename = "type")]
|
||||
kind: AcceptType,
|
||||
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
actor: serde_json::Value,
|
||||
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
object: serde_json::Value,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub object_props: ObjectProperties,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub activity_props: ActivityProperties,
|
||||
}
|
||||
|
||||
impl Accept {
|
||||
pub fn actor<O: Object>(&self) -> Result<O> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actors<O: Object>(&self) -> Result<Vec<O>> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actor_link<L: Link>(&self) -> Result<L> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actor_links<L: Link>(&self) -> Result<Vec<L>> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn object<O: Object>(&self) -> Result<O> {
|
||||
serde_json::from_value(self.object.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn objects<O: Object>(&self) -> Result<Vec<O>> {
|
||||
serde_json::from_value(self.object.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
}
|
||||
|
||||
impl Object for Accept {}
|
||||
impl Activity for Accept {}
|
||||
|
|
|
@ -2,48 +2,29 @@ use serde_json;
|
|||
|
||||
use super::{kind::AddType, properties::ActivityProperties, Activity};
|
||||
|
||||
use error::{Error, Result};
|
||||
use error::Result;
|
||||
use link::Link;
|
||||
use object::{Object, ObjectProperties};
|
||||
use Properties;
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, Properties)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Add {
|
||||
#[serde(rename = "type")]
|
||||
kind: AddType,
|
||||
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
actor: serde_json::Value,
|
||||
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
object: serde_json::Value,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub object_props: ObjectProperties,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub activity_props: ActivityProperties,
|
||||
}
|
||||
|
||||
impl Add {
|
||||
pub fn actor<O: Object>(&self) -> Result<O> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actors<O: Object>(&self) -> Result<Vec<O>> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actor_link<L: Link>(&self) -> Result<L> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actor_links<L: Link>(&self) -> Result<Vec<L>> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn object<O: Object>(&self) -> Result<O> {
|
||||
serde_json::from_value(self.object.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn objects<O: Object>(&self) -> Result<Vec<O>> {
|
||||
serde_json::from_value(self.object.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
}
|
||||
|
||||
impl Object for Add {}
|
||||
impl Activity for Add {}
|
||||
|
|
|
@ -2,87 +2,37 @@ use serde_json;
|
|||
|
||||
use super::{kind::MoveType, properties::ActivityProperties, Activity};
|
||||
|
||||
use error::{Error, Result};
|
||||
use error::Result;
|
||||
use link::Link;
|
||||
use object::{Object, ObjectProperties};
|
||||
use Properties;
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, Properties)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct AMove {
|
||||
#[serde(rename = "type")]
|
||||
kind: MoveType,
|
||||
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
actor: serde_json::Value,
|
||||
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
object: serde_json::Value,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
origin: Option<serde_json::Value>,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
target: Option<serde_json::Value>,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub object_props: ObjectProperties,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub activity_props: ActivityProperties,
|
||||
}
|
||||
|
||||
impl Properties for AMove {}
|
||||
|
||||
impl AMove {
|
||||
pub fn actor<O: Object>(&self) -> Result<O> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actors<O: Object>(&self) -> Result<Vec<O>> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actor_link<L: Link>(&self) -> Result<L> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actor_links<L: Link>(&self) -> Result<Vec<L>> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn object<O: Object>(&self) -> Result<O> {
|
||||
serde_json::from_value(self.object.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn objects<O: Object>(&self) -> Result<Vec<O>> {
|
||||
serde_json::from_value(self.object.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn origin<O: Object>(&self) -> Result<O> {
|
||||
self.get_item(|m| &m.origin)
|
||||
}
|
||||
|
||||
pub fn origins<O: Object>(&self) -> Result<Vec<O>> {
|
||||
self.get_item(|m| &m.origin)
|
||||
}
|
||||
|
||||
pub fn origin_link<L: Link>(&self) -> Result<L> {
|
||||
self.get_item(|m| &m.origin)
|
||||
}
|
||||
|
||||
pub fn origin_links<L: Link>(&self) -> Result<Vec<L>> {
|
||||
self.get_item(|m| &m.origin)
|
||||
}
|
||||
|
||||
pub fn target<O: Object>(&self) -> Result<O> {
|
||||
self.get_item(|m| &m.target)
|
||||
}
|
||||
|
||||
pub fn targets<O: Object>(&self) -> Result<Vec<O>> {
|
||||
self.get_item(|m| &m.target)
|
||||
}
|
||||
|
||||
pub fn target_link<L: Link>(&self) -> Result<L> {
|
||||
self.get_item(|m| &m.target)
|
||||
}
|
||||
|
||||
pub fn target_links<L: Link>(&self) -> Result<Vec<L>> {
|
||||
self.get_item(|m| &m.target)
|
||||
}
|
||||
}
|
||||
|
||||
impl Object for AMove {}
|
||||
impl Activity for AMove {}
|
||||
|
|
|
@ -2,69 +2,33 @@ use serde_json;
|
|||
|
||||
use super::{kind::AnnounceType, properties::ActivityProperties, Activity};
|
||||
|
||||
use error::{Error, Result};
|
||||
use error::Result;
|
||||
use link::Link;
|
||||
use object::{Object, ObjectProperties};
|
||||
use Properties;
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, Properties)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Announce {
|
||||
#[serde(rename = "type")]
|
||||
kind: AnnounceType,
|
||||
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
actor: serde_json::Value,
|
||||
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
object: serde_json::Value,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
target: Option<serde_json::Value>,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub object_props: ObjectProperties,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub activity_props: ActivityProperties,
|
||||
}
|
||||
|
||||
impl Properties for Announce {}
|
||||
|
||||
impl Announce {
|
||||
pub fn actor<O: Object>(&self) -> Result<O> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actors<O: Object>(&self) -> Result<Vec<O>> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actor_link<L: Link>(&self) -> Result<L> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actor_links<L: Link>(&self) -> Result<Vec<L>> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn object<O: Object>(&self) -> Result<O> {
|
||||
serde_json::from_value(self.object.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn objects<O: Object>(&self) -> Result<Vec<O>> {
|
||||
serde_json::from_value(self.object.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn target<O: Object>(&self) -> Result<O> {
|
||||
self.get_item(|m| &m.target)
|
||||
}
|
||||
|
||||
pub fn targets<O: Object>(&self) -> Result<Vec<O>> {
|
||||
self.get_item(|m| &m.target)
|
||||
}
|
||||
|
||||
pub fn target_link<L: Link>(&self) -> Result<L> {
|
||||
self.get_item(|m| &m.target)
|
||||
}
|
||||
|
||||
pub fn target_links<L: Link>(&self) -> Result<Vec<L>> {
|
||||
self.get_item(|m| &m.target)
|
||||
}
|
||||
}
|
||||
|
||||
impl Object for Announce {}
|
||||
impl Activity for Announce {}
|
||||
|
|
|
@ -2,74 +2,33 @@ use serde_json;
|
|||
|
||||
use super::{kind::ArriveType, properties::ActivityProperties, Activity, IntransitiveActivity};
|
||||
|
||||
use error::{Error, Result};
|
||||
use error::Result;
|
||||
use link::Link;
|
||||
use object::{Object, ObjectProperties};
|
||||
use Properties;
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, Properties)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Arrive {
|
||||
#[serde(rename = "type")]
|
||||
kind: ArriveType,
|
||||
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
actor: serde_json::Value,
|
||||
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
location: serde_json::Value,
|
||||
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
origin: serde_json::Value,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub object_props: ObjectProperties,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub activity_props: ActivityProperties,
|
||||
}
|
||||
|
||||
impl Arrive {
|
||||
pub fn actor<O: Object>(&self) -> Result<O> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actors<O: Object>(&self) -> Result<Vec<O>> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actor_link<L: Link>(&self) -> Result<L> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actor_links<L: Link>(&self) -> Result<Vec<L>> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn location<O: Object>(&self) -> Result<O> {
|
||||
serde_json::from_value(self.location.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn locations<O: Object>(&self) -> Result<Vec<O>> {
|
||||
serde_json::from_value(self.location.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn location_link<L: Link>(&self) -> Result<L> {
|
||||
serde_json::from_value(self.location.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn location_links<L: Link>(&self) -> Result<Vec<L>> {
|
||||
serde_json::from_value(self.location.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn origin<O: Object>(&self) -> Result<O> {
|
||||
serde_json::from_value(self.origin.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn origins<O: Object>(&self) -> Result<Vec<O>> {
|
||||
serde_json::from_value(self.origin.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn origin_link<L: Link>(&self) -> Result<L> {
|
||||
serde_json::from_value(self.origin.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn origin_links<L: Link>(&self) -> Result<Vec<L>> {
|
||||
serde_json::from_value(self.origin.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
}
|
||||
|
||||
impl Object for Arrive {}
|
||||
impl Activity for Arrive {}
|
||||
impl IntransitiveActivity for Arrive {}
|
||||
|
|
|
@ -2,48 +2,29 @@ use serde_json;
|
|||
|
||||
use super::{kind::BlockType, properties::ActivityProperties, Activity};
|
||||
|
||||
use error::{Error, Result};
|
||||
use error::Result;
|
||||
use link::Link;
|
||||
use object::{Object, ObjectProperties};
|
||||
use Properties;
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, Properties)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Block {
|
||||
#[serde(rename = "type")]
|
||||
kind: BlockType,
|
||||
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
actor: serde_json::Value,
|
||||
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
object: serde_json::Value,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub object_props: ObjectProperties,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub activity_props: ActivityProperties,
|
||||
}
|
||||
|
||||
impl Block {
|
||||
pub fn actor<O: Object>(&self) -> Result<O> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actors<O: Object>(&self) -> Result<Vec<O>> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actor_link<L: Link>(&self) -> Result<L> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actor_links<L: Link>(&self) -> Result<Vec<L>> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn object<O: Object>(&self) -> Result<O> {
|
||||
serde_json::from_value(self.object.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn objects<O: Object>(&self) -> Result<Vec<O>> {
|
||||
serde_json::from_value(self.object.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
}
|
||||
|
||||
impl Object for Block {}
|
||||
impl Activity for Block {}
|
||||
|
|
|
@ -2,48 +2,29 @@ use serde_json;
|
|||
|
||||
use super::{kind::CreateType, properties::ActivityProperties, Activity};
|
||||
|
||||
use error::{Error, Result};
|
||||
use error::Result;
|
||||
use link::Link;
|
||||
use object::{Object, ObjectProperties};
|
||||
use Properties;
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, Properties)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Create {
|
||||
#[serde(rename = "type")]
|
||||
kind: CreateType,
|
||||
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
actor: serde_json::Value,
|
||||
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
object: serde_json::Value,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub object_props: ObjectProperties,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub activity_props: ActivityProperties,
|
||||
}
|
||||
|
||||
impl Create {
|
||||
pub fn actor<O: Object>(&self) -> Result<O> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actors<O: Object>(&self) -> Result<Vec<O>> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actor_link<L: Link>(&self) -> Result<L> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actor_links<L: Link>(&self) -> Result<Vec<L>> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn object<O: Object>(&self) -> Result<O> {
|
||||
serde_json::from_value(self.object.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn objects<O: Object>(&self) -> Result<Vec<O>> {
|
||||
serde_json::from_value(self.object.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
}
|
||||
|
||||
impl Object for Create {}
|
||||
impl Activity for Create {}
|
||||
|
|
|
@ -2,69 +2,33 @@ use serde_json;
|
|||
|
||||
use super::{kind::DeleteType, properties::ActivityProperties, Activity};
|
||||
|
||||
use error::{Error, Result};
|
||||
use error::Result;
|
||||
use link::Link;
|
||||
use object::{Object, ObjectProperties};
|
||||
use Properties;
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, Properties)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Delete {
|
||||
#[serde(rename = "type")]
|
||||
kind: DeleteType,
|
||||
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
actor: serde_json::Value,
|
||||
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
object: serde_json::Value,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
origin: Option<serde_json::Value>,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub object_props: ObjectProperties,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub activity_props: ActivityProperties,
|
||||
}
|
||||
|
||||
impl Properties for Delete {}
|
||||
|
||||
impl Delete {
|
||||
pub fn actor<O: Object>(&self) -> Result<O> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actors<O: Object>(&self) -> Result<Vec<O>> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actor_link<L: Link>(&self) -> Result<L> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actor_links<L: Link>(&self) -> Result<Vec<L>> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn object<O: Object>(&self) -> Result<O> {
|
||||
serde_json::from_value(self.object.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn objects<O: Object>(&self) -> Result<Vec<O>> {
|
||||
serde_json::from_value(self.object.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn origin<O: Object>(&self) -> Result<O> {
|
||||
self.get_item(|d| &d.origin)
|
||||
}
|
||||
|
||||
pub fn origins<O: Object>(&self) -> Result<O> {
|
||||
self.get_item(|d| &d.origin)
|
||||
}
|
||||
|
||||
pub fn origin_link<L: Link>(&self) -> Result<L> {
|
||||
self.get_item(|d| &d.origin)
|
||||
}
|
||||
|
||||
pub fn origin_links<L: Link>(&self) -> Result<Vec<L>> {
|
||||
self.get_item(|d| &d.origin)
|
||||
}
|
||||
}
|
||||
|
||||
impl Object for Delete {}
|
||||
impl Activity for Delete {}
|
||||
|
|
|
@ -2,48 +2,29 @@ use serde_json;
|
|||
|
||||
use super::{kind::DislikeType, properties::ActivityProperties, Activity};
|
||||
|
||||
use error::{Error, Result};
|
||||
use error::Result;
|
||||
use link::Link;
|
||||
use object::{Object, ObjectProperties};
|
||||
use Properties;
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, Properties)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Dislike {
|
||||
#[serde(rename = "type")]
|
||||
kind: DislikeType,
|
||||
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
actor: serde_json::Value,
|
||||
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
object: serde_json::Value,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub object_props: ObjectProperties,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub activity_props: ActivityProperties,
|
||||
}
|
||||
|
||||
impl Dislike {
|
||||
pub fn actor<O: Object>(&self) -> Result<O> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actors<O: Object>(&self) -> Result<Vec<O>> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actor_link<L: Link>(&self) -> Result<L> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actor_links<L: Link>(&self) -> Result<Vec<L>> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn object<O: Object>(&self) -> Result<O> {
|
||||
serde_json::from_value(self.object.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn objects<O: Object>(&self) -> Result<Vec<O>> {
|
||||
serde_json::from_value(self.object.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
}
|
||||
|
||||
impl Object for Dislike {}
|
||||
impl Activity for Dislike {}
|
||||
|
|
|
@ -2,48 +2,29 @@ use serde_json;
|
|||
|
||||
use super::{kind::FlagType, properties::ActivityProperties, Activity};
|
||||
|
||||
use error::{Error, Result};
|
||||
use error::Result;
|
||||
use link::Link;
|
||||
use object::{Object, ObjectProperties};
|
||||
use Properties;
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, Properties)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Flag {
|
||||
#[serde(rename = "type")]
|
||||
kind: FlagType,
|
||||
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
actor: serde_json::Value,
|
||||
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
object: serde_json::Value,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub object_props: ObjectProperties,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub activity_props: ActivityProperties,
|
||||
}
|
||||
|
||||
impl Flag {
|
||||
pub fn actor<O: Object>(&self) -> Result<O> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actors<O: Object>(&self) -> Result<Vec<O>> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actor_link<L: Link>(&self) -> Result<L> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actor_links<L: Link>(&self) -> Result<Vec<L>> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn object<O: Object>(&self) -> Result<O> {
|
||||
serde_json::from_value(self.object.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn objects<O: Object>(&self) -> Result<Vec<O>> {
|
||||
serde_json::from_value(self.object.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
}
|
||||
|
||||
impl Object for Flag {}
|
||||
impl Activity for Flag {}
|
||||
|
|
|
@ -2,48 +2,29 @@ use serde_json;
|
|||
|
||||
use super::{kind::FollowType, properties::ActivityProperties, Activity};
|
||||
|
||||
use error::{Error, Result};
|
||||
use error::Result;
|
||||
use link::Link;
|
||||
use object::{Object, ObjectProperties};
|
||||
use Properties;
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, Properties)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Follow {
|
||||
#[serde(rename = "type")]
|
||||
kind: FollowType,
|
||||
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
actor: serde_json::Value,
|
||||
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
object: serde_json::Value,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub object_props: ObjectProperties,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub activity_props: ActivityProperties,
|
||||
}
|
||||
|
||||
impl Follow {
|
||||
pub fn actor<O: Object>(&self) -> Result<O> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actors<O: Object>(&self) -> Result<Vec<O>> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actor_link<L: Link>(&self) -> Result<L> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actor_links<L: Link>(&self) -> Result<Vec<L>> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn object<O: Object>(&self) -> Result<O> {
|
||||
serde_json::from_value(self.object.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn objects<O: Object>(&self) -> Result<Vec<O>> {
|
||||
serde_json::from_value(self.object.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
}
|
||||
|
||||
impl Object for Follow {}
|
||||
impl Activity for Follow {}
|
||||
|
|
|
@ -2,48 +2,29 @@ use serde_json;
|
|||
|
||||
use super::{kind::IgnoreType, properties::ActivityProperties, Activity};
|
||||
|
||||
use error::{Error, Result};
|
||||
use error::Result;
|
||||
use link::Link;
|
||||
use object::{Object, ObjectProperties};
|
||||
use Properties;
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, Properties)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Ignore {
|
||||
#[serde(rename = "type")]
|
||||
kind: IgnoreType,
|
||||
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
actor: serde_json::Value,
|
||||
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
object: serde_json::Value,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub object_props: ObjectProperties,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub activity_props: ActivityProperties,
|
||||
}
|
||||
|
||||
impl Ignore {
|
||||
pub fn actor<O: Object>(&self) -> Result<O> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actors<O: Object>(&self) -> Result<Vec<O>> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actor_link<L: Link>(&self) -> Result<L> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actor_links<L: Link>(&self) -> Result<Vec<L>> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn object<O: Object>(&self) -> Result<O> {
|
||||
serde_json::from_value(self.object.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn objects<O: Object>(&self) -> Result<Vec<O>> {
|
||||
serde_json::from_value(self.object.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
}
|
||||
|
||||
impl Object for Ignore {}
|
||||
impl Activity for Ignore {}
|
||||
|
|
|
@ -2,65 +2,32 @@ use serde_json;
|
|||
|
||||
use super::{kind::InviteType, properties::ActivityProperties, Activity};
|
||||
|
||||
use error::{Error, Result};
|
||||
use error::Result;
|
||||
use link::Link;
|
||||
use object::{Object, ObjectProperties};
|
||||
use Properties;
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, Properties)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Invite {
|
||||
#[serde(rename = "type")]
|
||||
kind: InviteType,
|
||||
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
actor: serde_json::Value,
|
||||
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
object: serde_json::Value,
|
||||
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
target: serde_json::Value,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub object_props: ObjectProperties,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub activity_props: ActivityProperties,
|
||||
}
|
||||
|
||||
impl Invite {
|
||||
pub fn actor<O: Object>(&self) -> Result<O> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actors<O: Object>(&self) -> Result<Vec<O>> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actor_link<L: Link>(&self) -> Result<L> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actor_links<L: Link>(&self) -> Result<Vec<L>> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn object<O: Object>(&self) -> Result<O> {
|
||||
serde_json::from_value(self.object.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn objects<O: Object>(&self) -> Result<Vec<O>> {
|
||||
serde_json::from_value(self.object.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn target<O: Object>(&self) -> Result<O> {
|
||||
serde_json::from_value(self.target.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn targets<O: Object>(&self) -> Result<Vec<O>> {
|
||||
serde_json::from_value(self.target.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn target_link<L: Link>(&self) -> Result<L> {
|
||||
serde_json::from_value(self.target.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn target_links<L: Link>(&self) -> Result<Vec<L>> {
|
||||
serde_json::from_value(self.target.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
}
|
||||
|
||||
impl Object for Invite {}
|
||||
impl Activity for Invite {}
|
||||
|
|
|
@ -2,48 +2,29 @@ use serde_json;
|
|||
|
||||
use super::{kind::JoinType, properties::ActivityProperties, Activity};
|
||||
|
||||
use error::{Error, Result};
|
||||
use error::Result;
|
||||
use link::Link;
|
||||
use object::{Object, ObjectProperties};
|
||||
use Properties;
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, Properties)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Join {
|
||||
#[serde(rename = "type")]
|
||||
kind: JoinType,
|
||||
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
actor: serde_json::Value,
|
||||
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
object: serde_json::Value,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub object_props: ObjectProperties,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub activity_props: ActivityProperties,
|
||||
}
|
||||
|
||||
impl Join {
|
||||
pub fn actor<O: Object>(&self) -> Result<O> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actors<O: Object>(&self) -> Result<Vec<O>> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actor_link<L: Link>(&self) -> Result<L> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actor_links<L: Link>(&self) -> Result<Vec<L>> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn object<O: Object>(&self) -> Result<O> {
|
||||
serde_json::from_value(self.object.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn objects<O: Object>(&self) -> Result<Vec<O>> {
|
||||
serde_json::from_value(self.object.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
}
|
||||
|
||||
impl Object for Join {}
|
||||
impl Activity for Join {}
|
||||
|
|
117
src/activity/kind.rs
Normal file
117
src/activity/kind.rs
Normal file
|
@ -0,0 +1,117 @@
|
|||
use std::fmt;
|
||||
|
||||
use serde::{
|
||||
de::{self, Deserialize, Deserializer, Visitor}, ser::{Serialize, Serializer},
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug, UnitString)]
|
||||
#[activitystreams(Accept)]
|
||||
pub struct AcceptType;
|
||||
|
||||
#[derive(Clone, Debug, UnitString)]
|
||||
#[activitystreams(Add)]
|
||||
pub struct AddType;
|
||||
|
||||
#[derive(Clone, Debug, UnitString)]
|
||||
#[activitystreams(Move)]
|
||||
pub struct MoveType;
|
||||
|
||||
#[derive(Clone, Debug, UnitString)]
|
||||
#[activitystreams(Announce)]
|
||||
pub struct AnnounceType;
|
||||
|
||||
#[derive(Clone, Debug, UnitString)]
|
||||
#[activitystreams(Arrive)]
|
||||
pub struct ArriveType;
|
||||
|
||||
#[derive(Clone, Debug, UnitString)]
|
||||
#[activitystreams(Block)]
|
||||
pub struct BlockType;
|
||||
|
||||
#[derive(Clone, Debug, UnitString)]
|
||||
#[activitystreams(Create)]
|
||||
pub struct CreateType;
|
||||
|
||||
#[derive(Clone, Debug, UnitString)]
|
||||
#[activitystreams(Delete)]
|
||||
pub struct DeleteType;
|
||||
|
||||
#[derive(Clone, Debug, UnitString)]
|
||||
#[activitystreams(Dislike)]
|
||||
pub struct DislikeType;
|
||||
|
||||
#[derive(Clone, Debug, UnitString)]
|
||||
#[activitystreams(Flag)]
|
||||
pub struct FlagType;
|
||||
|
||||
#[derive(Clone, Debug, UnitString)]
|
||||
#[activitystreams(Follow)]
|
||||
pub struct FollowType;
|
||||
|
||||
#[derive(Clone, Debug, UnitString)]
|
||||
#[activitystreams(Ignore)]
|
||||
pub struct IgnoreType;
|
||||
|
||||
#[derive(Clone, Debug, UnitString)]
|
||||
#[activitystreams(Invite)]
|
||||
pub struct InviteType;
|
||||
|
||||
#[derive(Clone, Debug, UnitString)]
|
||||
#[activitystreams(Join)]
|
||||
pub struct JoinType;
|
||||
|
||||
#[derive(Clone, Debug, UnitString)]
|
||||
#[activitystreams(Leave)]
|
||||
pub struct LeaveType;
|
||||
|
||||
#[derive(Clone, Debug, UnitString)]
|
||||
#[activitystreams(Like)]
|
||||
pub struct LikeType;
|
||||
|
||||
#[derive(Clone, Debug, UnitString)]
|
||||
#[activitystreams(Listen)]
|
||||
pub struct ListenType;
|
||||
|
||||
#[derive(Clone, Debug, UnitString)]
|
||||
#[activitystreams(Offer)]
|
||||
pub struct OfferType;
|
||||
|
||||
#[derive(Clone, Debug, UnitString)]
|
||||
#[activitystreams(Question)]
|
||||
pub struct QuestionType;
|
||||
|
||||
#[derive(Clone, Debug, UnitString)]
|
||||
#[activitystreams(Real)]
|
||||
pub struct ReadType;
|
||||
|
||||
#[derive(Clone, Debug, UnitString)]
|
||||
#[activitystreams(Reject)]
|
||||
pub struct RejectType;
|
||||
|
||||
#[derive(Clone, Debug, UnitString)]
|
||||
#[activitystreams(Remove)]
|
||||
pub struct RemoveType;
|
||||
|
||||
#[derive(Clone, Debug, UnitString)]
|
||||
#[activitystreams(TentativeAccept)]
|
||||
pub struct TentativeAcceptType;
|
||||
|
||||
#[derive(Clone, Debug, UnitString)]
|
||||
#[activitystreams(TentativeReject)]
|
||||
pub struct TentativeRejectType;
|
||||
|
||||
#[derive(Clone, Debug, UnitString)]
|
||||
#[activitystreams(Travel)]
|
||||
pub struct TravelType;
|
||||
|
||||
#[derive(Clone, Debug, UnitString)]
|
||||
#[activitystreams(Undo)]
|
||||
pub struct UndoType;
|
||||
|
||||
#[derive(Clone, Debug, UnitString)]
|
||||
#[activitystreams(Update)]
|
||||
pub struct UpdateType;
|
||||
|
||||
#[derive(Clone, Debug, UnitString)]
|
||||
#[activitystreams(View)]
|
||||
pub struct ViewType;
|
|
@ -1,47 +0,0 @@
|
|||
use std::fmt;
|
||||
|
||||
use serde::{
|
||||
de::{self, Deserialize, Deserializer, Visitor}, ser::{Serialize, Serializer},
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct AcceptType;
|
||||
|
||||
impl Serialize for AcceptType {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_str("Accept")
|
||||
}
|
||||
}
|
||||
|
||||
pub struct AcceptTypeVisitor;
|
||||
|
||||
impl<'de> Visitor<'de> for AcceptTypeVisitor {
|
||||
type Value = AcceptType;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(formatter, "The string 'Accept'")
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
if v == "Accept" {
|
||||
Ok(AcceptType)
|
||||
} else {
|
||||
Err(de::Error::custom("Type not Accept"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for AcceptType {
|
||||
fn deserialize<D>(deserializer: D) -> Result<AcceptType, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
deserializer.deserialize_str(AcceptTypeVisitor)
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
use std::fmt;
|
||||
|
||||
use serde::{
|
||||
de::{self, Deserialize, Deserializer, Visitor}, ser::{Serialize, Serializer},
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct AddType;
|
||||
|
||||
impl Serialize for AddType {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_str("Add")
|
||||
}
|
||||
}
|
||||
|
||||
pub struct AddTypeVisitor;
|
||||
|
||||
impl<'de> Visitor<'de> for AddTypeVisitor {
|
||||
type Value = AddType;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(formatter, "The string 'Add'")
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
if v == "Add" {
|
||||
Ok(AddType)
|
||||
} else {
|
||||
Err(de::Error::custom("Type not create"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for AddType {
|
||||
fn deserialize<D>(deserializer: D) -> Result<AddType, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
deserializer.deserialize_str(AddTypeVisitor)
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
use std::fmt;
|
||||
|
||||
use serde::{
|
||||
de::{self, Deserialize, Deserializer, Visitor}, ser::{Serialize, Serializer},
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct MoveType;
|
||||
|
||||
impl Serialize for MoveType {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_str("Move")
|
||||
}
|
||||
}
|
||||
|
||||
pub struct MoveTypeVisitor;
|
||||
|
||||
impl<'de> Visitor<'de> for MoveTypeVisitor {
|
||||
type Value = MoveType;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(formatter, "The string 'Move'")
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
if v == "Move" {
|
||||
Ok(MoveType)
|
||||
} else {
|
||||
Err(de::Error::custom("Type not Move"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for MoveType {
|
||||
fn deserialize<D>(deserializer: D) -> Result<MoveType, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
deserializer.deserialize_str(MoveTypeVisitor)
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
use std::fmt;
|
||||
|
||||
use serde::{
|
||||
de::{self, Deserialize, Deserializer, Visitor}, ser::{Serialize, Serializer},
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct AnnounceType;
|
||||
|
||||
impl Serialize for AnnounceType {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_str("Announce")
|
||||
}
|
||||
}
|
||||
|
||||
pub struct AnnounceTypeVisitor;
|
||||
|
||||
impl<'de> Visitor<'de> for AnnounceTypeVisitor {
|
||||
type Value = AnnounceType;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(formatter, "The string 'Announce'")
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
if v == "Announce" {
|
||||
Ok(AnnounceType)
|
||||
} else {
|
||||
Err(de::Error::custom("Type not Announce"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for AnnounceType {
|
||||
fn deserialize<D>(deserializer: D) -> Result<AnnounceType, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
deserializer.deserialize_str(AnnounceTypeVisitor)
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
use std::fmt;
|
||||
|
||||
use serde::{
|
||||
de::{self, Deserialize, Deserializer, Visitor}, ser::{Serialize, Serializer},
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct ArriveType;
|
||||
|
||||
impl Serialize for ArriveType {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_str("Arrive")
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ArriveTypeVisitor;
|
||||
|
||||
impl<'de> Visitor<'de> for ArriveTypeVisitor {
|
||||
type Value = ArriveType;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(formatter, "The string 'Arrive'")
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
if v == "Arrive" {
|
||||
Ok(ArriveType)
|
||||
} else {
|
||||
Err(de::Error::custom("Type not Arrive"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for ArriveType {
|
||||
fn deserialize<D>(deserializer: D) -> Result<ArriveType, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
deserializer.deserialize_str(ArriveTypeVisitor)
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
use std::fmt;
|
||||
|
||||
use serde::{
|
||||
de::{self, Deserialize, Deserializer, Visitor}, ser::{Serialize, Serializer},
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct BlockType;
|
||||
|
||||
impl Serialize for BlockType {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_str("Block")
|
||||
}
|
||||
}
|
||||
|
||||
pub struct BlockTypeVisitor;
|
||||
|
||||
impl<'de> Visitor<'de> for BlockTypeVisitor {
|
||||
type Value = BlockType;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(formatter, "The string 'Block'")
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
if v == "Block" {
|
||||
Ok(BlockType)
|
||||
} else {
|
||||
Err(de::Error::custom("Type not Block"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for BlockType {
|
||||
fn deserialize<D>(deserializer: D) -> Result<BlockType, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
deserializer.deserialize_str(BlockTypeVisitor)
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
use std::fmt;
|
||||
|
||||
use serde::{
|
||||
de::{self, Deserialize, Deserializer, Visitor}, ser::{Serialize, Serializer},
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct CreateType;
|
||||
|
||||
impl Serialize for CreateType {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_str("Create")
|
||||
}
|
||||
}
|
||||
|
||||
pub struct CreateTypeVisitor;
|
||||
|
||||
impl<'de> Visitor<'de> for CreateTypeVisitor {
|
||||
type Value = CreateType;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(formatter, "The string 'Create'")
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
if v == "Create" {
|
||||
Ok(CreateType)
|
||||
} else {
|
||||
Err(de::Error::custom("Type not create"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for CreateType {
|
||||
fn deserialize<D>(deserializer: D) -> Result<CreateType, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
deserializer.deserialize_str(CreateTypeVisitor)
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
use std::fmt;
|
||||
|
||||
use serde::{
|
||||
de::{self, Deserialize, Deserializer, Visitor}, ser::{Serialize, Serializer},
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct DeleteType;
|
||||
|
||||
impl Serialize for DeleteType {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_str("Delete")
|
||||
}
|
||||
}
|
||||
|
||||
pub struct DeleteTypeVisitor;
|
||||
|
||||
impl<'de> Visitor<'de> for DeleteTypeVisitor {
|
||||
type Value = DeleteType;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(formatter, "The string 'Delete'")
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
if v == "Delete" {
|
||||
Ok(DeleteType)
|
||||
} else {
|
||||
Err(de::Error::custom("Type not Delete"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for DeleteType {
|
||||
fn deserialize<D>(deserializer: D) -> Result<DeleteType, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
deserializer.deserialize_str(DeleteTypeVisitor)
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
use std::fmt;
|
||||
|
||||
use serde::{
|
||||
de::{self, Deserialize, Deserializer, Visitor}, ser::{Serialize, Serializer},
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct DislikeType;
|
||||
|
||||
impl Serialize for DislikeType {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_str("Dislike")
|
||||
}
|
||||
}
|
||||
|
||||
pub struct DislikeTypeVisitor;
|
||||
|
||||
impl<'de> Visitor<'de> for DislikeTypeVisitor {
|
||||
type Value = DislikeType;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(formatter, "The string 'Dislike'")
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
if v == "Dislike" {
|
||||
Ok(DislikeType)
|
||||
} else {
|
||||
Err(de::Error::custom("Type not Dislike"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for DislikeType {
|
||||
fn deserialize<D>(deserializer: D) -> Result<DislikeType, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
deserializer.deserialize_str(DislikeTypeVisitor)
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
use std::fmt;
|
||||
|
||||
use serde::{
|
||||
de::{self, Deserialize, Deserializer, Visitor}, ser::{Serialize, Serializer},
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct FlagType;
|
||||
|
||||
impl Serialize for FlagType {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_str("Flag")
|
||||
}
|
||||
}
|
||||
|
||||
pub struct FlagTypeVisitor;
|
||||
|
||||
impl<'de> Visitor<'de> for FlagTypeVisitor {
|
||||
type Value = FlagType;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(formatter, "The string 'Flag'")
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
if v == "Flag" {
|
||||
Ok(FlagType)
|
||||
} else {
|
||||
Err(de::Error::custom("Type not Flag"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for FlagType {
|
||||
fn deserialize<D>(deserializer: D) -> Result<FlagType, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
deserializer.deserialize_str(FlagTypeVisitor)
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
use std::fmt;
|
||||
|
||||
use serde::{
|
||||
de::{self, Deserialize, Deserializer, Visitor}, ser::{Serialize, Serializer},
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct FollowType;
|
||||
|
||||
impl Serialize for FollowType {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_str("Follow")
|
||||
}
|
||||
}
|
||||
|
||||
pub struct FollowTypeVisitor;
|
||||
|
||||
impl<'de> Visitor<'de> for FollowTypeVisitor {
|
||||
type Value = FollowType;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(formatter, "The string 'Follow'")
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
if v == "Follow" {
|
||||
Ok(FollowType)
|
||||
} else {
|
||||
Err(de::Error::custom("Type not Follow"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for FollowType {
|
||||
fn deserialize<D>(deserializer: D) -> Result<FollowType, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
deserializer.deserialize_str(FollowTypeVisitor)
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
use std::fmt;
|
||||
|
||||
use serde::{
|
||||
de::{self, Deserialize, Deserializer, Visitor}, ser::{Serialize, Serializer},
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct IgnoreType;
|
||||
|
||||
impl Serialize for IgnoreType {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_str("Ignore")
|
||||
}
|
||||
}
|
||||
|
||||
pub struct IgnoreTypeVisitor;
|
||||
|
||||
impl<'de> Visitor<'de> for IgnoreTypeVisitor {
|
||||
type Value = IgnoreType;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(formatter, "The string 'Ignore'")
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
if v == "Ignore" {
|
||||
Ok(IgnoreType)
|
||||
} else {
|
||||
Err(de::Error::custom("Type not Ignore"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for IgnoreType {
|
||||
fn deserialize<D>(deserializer: D) -> Result<IgnoreType, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
deserializer.deserialize_str(IgnoreTypeVisitor)
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
use std::fmt;
|
||||
|
||||
use serde::{
|
||||
de::{self, Deserialize, Deserializer, Visitor}, ser::{Serialize, Serializer},
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct InviteType;
|
||||
|
||||
impl Serialize for InviteType {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_str("Invite")
|
||||
}
|
||||
}
|
||||
|
||||
pub struct InviteTypeVisitor;
|
||||
|
||||
impl<'de> Visitor<'de> for InviteTypeVisitor {
|
||||
type Value = InviteType;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(formatter, "The string 'Invite'")
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
if v == "Invite" {
|
||||
Ok(InviteType)
|
||||
} else {
|
||||
Err(de::Error::custom("Type not Invite"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for InviteType {
|
||||
fn deserialize<D>(deserializer: D) -> Result<InviteType, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
deserializer.deserialize_str(InviteTypeVisitor)
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
use std::fmt;
|
||||
|
||||
use serde::{
|
||||
de::{self, Deserialize, Deserializer, Visitor}, ser::{Serialize, Serializer},
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct JoinType;
|
||||
|
||||
impl Serialize for JoinType {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_str("Join")
|
||||
}
|
||||
}
|
||||
|
||||
pub struct JoinTypeVisitor;
|
||||
|
||||
impl<'de> Visitor<'de> for JoinTypeVisitor {
|
||||
type Value = JoinType;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(formatter, "The string 'Join'")
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
if v == "Join" {
|
||||
Ok(JoinType)
|
||||
} else {
|
||||
Err(de::Error::custom("Type not Join"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for JoinType {
|
||||
fn deserialize<D>(deserializer: D) -> Result<JoinType, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
deserializer.deserialize_str(JoinTypeVisitor)
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
use std::fmt;
|
||||
|
||||
use serde::{
|
||||
de::{self, Deserialize, Deserializer, Visitor}, ser::{Serialize, Serializer},
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct LeaveType;
|
||||
|
||||
impl Serialize for LeaveType {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_str("Leave")
|
||||
}
|
||||
}
|
||||
|
||||
pub struct LeaveTypeVisitor;
|
||||
|
||||
impl<'de> Visitor<'de> for LeaveTypeVisitor {
|
||||
type Value = LeaveType;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(formatter, "The string 'Leave'")
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
if v == "Leave" {
|
||||
Ok(LeaveType)
|
||||
} else {
|
||||
Err(de::Error::custom("Type not Leave"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for LeaveType {
|
||||
fn deserialize<D>(deserializer: D) -> Result<LeaveType, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
deserializer.deserialize_str(LeaveTypeVisitor)
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
use std::fmt;
|
||||
|
||||
use serde::{
|
||||
de::{self, Deserialize, Deserializer, Visitor}, ser::{Serialize, Serializer},
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct LikeType;
|
||||
|
||||
impl Serialize for LikeType {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_str("Like")
|
||||
}
|
||||
}
|
||||
|
||||
pub struct LikeTypeVisitor;
|
||||
|
||||
impl<'de> Visitor<'de> for LikeTypeVisitor {
|
||||
type Value = LikeType;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(formatter, "The string 'Like'")
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
if v == "Like" {
|
||||
Ok(LikeType)
|
||||
} else {
|
||||
Err(de::Error::custom("Type not Like"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for LikeType {
|
||||
fn deserialize<D>(deserializer: D) -> Result<LikeType, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
deserializer.deserialize_str(LikeTypeVisitor)
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
use std::fmt;
|
||||
|
||||
use serde::{
|
||||
de::{self, Deserialize, Deserializer, Visitor}, ser::{Serialize, Serializer},
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct ListenType;
|
||||
|
||||
impl Serialize for ListenType {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_str("Listen")
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ListenTypeVisitor;
|
||||
|
||||
impl<'de> Visitor<'de> for ListenTypeVisitor {
|
||||
type Value = ListenType;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(formatter, "The string 'Listen'")
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
if v == "Listen" {
|
||||
Ok(ListenType)
|
||||
} else {
|
||||
Err(de::Error::custom("Type not Listen"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for ListenType {
|
||||
fn deserialize<D>(deserializer: D) -> Result<ListenType, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
deserializer.deserialize_str(ListenTypeVisitor)
|
||||
}
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
mod accept;
|
||||
mod add;
|
||||
mod amove;
|
||||
mod announce;
|
||||
mod arrive;
|
||||
mod block;
|
||||
mod create;
|
||||
mod delete;
|
||||
mod dislike;
|
||||
mod flag;
|
||||
mod follow;
|
||||
mod ignore;
|
||||
mod invite;
|
||||
mod join;
|
||||
mod leave;
|
||||
mod like;
|
||||
mod listen;
|
||||
mod offer;
|
||||
mod question;
|
||||
mod read;
|
||||
mod reject;
|
||||
mod remove;
|
||||
mod tentative_accept;
|
||||
mod tentative_reject;
|
||||
mod travel;
|
||||
mod undo;
|
||||
mod update;
|
||||
mod view;
|
||||
|
||||
pub use self::accept::*;
|
||||
pub use self::add::*;
|
||||
pub use self::amove::*;
|
||||
pub use self::announce::*;
|
||||
pub use self::arrive::*;
|
||||
pub use self::block::*;
|
||||
pub use self::create::*;
|
||||
pub use self::delete::*;
|
||||
pub use self::dislike::*;
|
||||
pub use self::flag::*;
|
||||
pub use self::follow::*;
|
||||
pub use self::ignore::*;
|
||||
pub use self::invite::*;
|
||||
pub use self::join::*;
|
||||
pub use self::leave::*;
|
||||
pub use self::like::*;
|
||||
pub use self::listen::*;
|
||||
pub use self::offer::*;
|
||||
pub use self::question::*;
|
||||
pub use self::read::*;
|
||||
pub use self::reject::*;
|
||||
pub use self::remove::*;
|
||||
pub use self::tentative_accept::*;
|
||||
pub use self::tentative_reject::*;
|
||||
pub use self::travel::*;
|
||||
pub use self::undo::*;
|
||||
pub use self::update::*;
|
||||
pub use self::view::*;
|
|
@ -1,47 +0,0 @@
|
|||
use std::fmt;
|
||||
|
||||
use serde::{
|
||||
de::{self, Deserialize, Deserializer, Visitor}, ser::{Serialize, Serializer},
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct OfferType;
|
||||
|
||||
impl Serialize for OfferType {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_str("Offer")
|
||||
}
|
||||
}
|
||||
|
||||
pub struct OfferTypeVisitor;
|
||||
|
||||
impl<'de> Visitor<'de> for OfferTypeVisitor {
|
||||
type Value = OfferType;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(formatter, "The string 'Offer'")
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
if v == "Offer" {
|
||||
Ok(OfferType)
|
||||
} else {
|
||||
Err(de::Error::custom("Type not Offer"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for OfferType {
|
||||
fn deserialize<D>(deserializer: D) -> Result<OfferType, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
deserializer.deserialize_str(OfferTypeVisitor)
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
use std::fmt;
|
||||
|
||||
use serde::{
|
||||
de::{self, Deserialize, Deserializer, Visitor}, ser::{Serialize, Serializer},
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct QuestionType;
|
||||
|
||||
impl Serialize for QuestionType {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_str("Question")
|
||||
}
|
||||
}
|
||||
|
||||
pub struct QuestionTypeVisitor;
|
||||
|
||||
impl<'de> Visitor<'de> for QuestionTypeVisitor {
|
||||
type Value = QuestionType;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(formatter, "The string 'Question'")
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
if v == "Question" {
|
||||
Ok(QuestionType)
|
||||
} else {
|
||||
Err(de::Error::custom("Type not Question"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for QuestionType {
|
||||
fn deserialize<D>(deserializer: D) -> Result<QuestionType, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
deserializer.deserialize_str(QuestionTypeVisitor)
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
use std::fmt;
|
||||
|
||||
use serde::{
|
||||
de::{self, Deserialize, Deserializer, Visitor}, ser::{Serialize, Serializer},
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct ReadType;
|
||||
|
||||
impl Serialize for ReadType {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_str("Read")
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ReadTypeVisitor;
|
||||
|
||||
impl<'de> Visitor<'de> for ReadTypeVisitor {
|
||||
type Value = ReadType;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(formatter, "The string 'Read'")
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
if v == "Read" {
|
||||
Ok(ReadType)
|
||||
} else {
|
||||
Err(de::Error::custom("Type not Read"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for ReadType {
|
||||
fn deserialize<D>(deserializer: D) -> Result<ReadType, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
deserializer.deserialize_str(ReadTypeVisitor)
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
use std::fmt;
|
||||
|
||||
use serde::{
|
||||
de::{self, Deserialize, Deserializer, Visitor}, ser::{Serialize, Serializer},
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct RejectType;
|
||||
|
||||
impl Serialize for RejectType {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_str("Reject")
|
||||
}
|
||||
}
|
||||
|
||||
pub struct RejectTypeVisitor;
|
||||
|
||||
impl<'de> Visitor<'de> for RejectTypeVisitor {
|
||||
type Value = RejectType;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(formatter, "The string 'Reject'")
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
if v == "Reject" {
|
||||
Ok(RejectType)
|
||||
} else {
|
||||
Err(de::Error::custom("Type not Reject"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for RejectType {
|
||||
fn deserialize<D>(deserializer: D) -> Result<RejectType, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
deserializer.deserialize_str(RejectTypeVisitor)
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
use std::fmt;
|
||||
|
||||
use serde::{
|
||||
de::{self, Deserialize, Deserializer, Visitor}, ser::{Serialize, Serializer},
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct RemoveType;
|
||||
|
||||
impl Serialize for RemoveType {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_str("Remove")
|
||||
}
|
||||
}
|
||||
|
||||
pub struct RemoveTypeVisitor;
|
||||
|
||||
impl<'de> Visitor<'de> for RemoveTypeVisitor {
|
||||
type Value = RemoveType;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(formatter, "The string 'Remove'")
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
if v == "Remove" {
|
||||
Ok(RemoveType)
|
||||
} else {
|
||||
Err(de::Error::custom("Type not Remove"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for RemoveType {
|
||||
fn deserialize<D>(deserializer: D) -> Result<RemoveType, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
deserializer.deserialize_str(RemoveTypeVisitor)
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
use std::fmt;
|
||||
|
||||
use serde::{
|
||||
de::{self, Deserialize, Deserializer, Visitor}, ser::{Serialize, Serializer},
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct TentativeAcceptType;
|
||||
|
||||
impl Serialize for TentativeAcceptType {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_str("TentativeAccept")
|
||||
}
|
||||
}
|
||||
|
||||
pub struct TentativeAcceptTypeVisitor;
|
||||
|
||||
impl<'de> Visitor<'de> for TentativeAcceptTypeVisitor {
|
||||
type Value = TentativeAcceptType;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(formatter, "The string 'TentativeAccept'")
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
if v == "TentativeAccept" {
|
||||
Ok(TentativeAcceptType)
|
||||
} else {
|
||||
Err(de::Error::custom("Type not TentativeAccept"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for TentativeAcceptType {
|
||||
fn deserialize<D>(deserializer: D) -> Result<TentativeAcceptType, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
deserializer.deserialize_str(TentativeAcceptTypeVisitor)
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
use std::fmt;
|
||||
|
||||
use serde::{
|
||||
de::{self, Deserialize, Deserializer, Visitor}, ser::{Serialize, Serializer},
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct TentativeRejectType;
|
||||
|
||||
impl Serialize for TentativeRejectType {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_str("TentativeReject")
|
||||
}
|
||||
}
|
||||
|
||||
pub struct TentativeRejectTypeVisitor;
|
||||
|
||||
impl<'de> Visitor<'de> for TentativeRejectTypeVisitor {
|
||||
type Value = TentativeRejectType;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(formatter, "The string 'TentativeReject'")
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
if v == "TentativeReject" {
|
||||
Ok(TentativeRejectType)
|
||||
} else {
|
||||
Err(de::Error::custom("Type not TentativeReject"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for TentativeRejectType {
|
||||
fn deserialize<D>(deserializer: D) -> Result<TentativeRejectType, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
deserializer.deserialize_str(TentativeRejectTypeVisitor)
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
use std::fmt;
|
||||
|
||||
use serde::{
|
||||
de::{self, Deserialize, Deserializer, Visitor}, ser::{Serialize, Serializer},
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct TravelType;
|
||||
|
||||
impl Serialize for TravelType {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_str("Travel")
|
||||
}
|
||||
}
|
||||
|
||||
pub struct TravelTypeVisitor;
|
||||
|
||||
impl<'de> Visitor<'de> for TravelTypeVisitor {
|
||||
type Value = TravelType;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(formatter, "The string 'Travel'")
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
if v == "Travel" {
|
||||
Ok(TravelType)
|
||||
} else {
|
||||
Err(de::Error::custom("Type not Travel"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for TravelType {
|
||||
fn deserialize<D>(deserializer: D) -> Result<TravelType, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
deserializer.deserialize_str(TravelTypeVisitor)
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
use std::fmt;
|
||||
|
||||
use serde::{
|
||||
de::{self, Deserialize, Deserializer, Visitor}, ser::{Serialize, Serializer},
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct UndoType;
|
||||
|
||||
impl Serialize for UndoType {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_str("Undo")
|
||||
}
|
||||
}
|
||||
|
||||
pub struct UndoTypeVisitor;
|
||||
|
||||
impl<'de> Visitor<'de> for UndoTypeVisitor {
|
||||
type Value = UndoType;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(formatter, "The string 'Undo'")
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
if v == "Undo" {
|
||||
Ok(UndoType)
|
||||
} else {
|
||||
Err(de::Error::custom("Type not Undo"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for UndoType {
|
||||
fn deserialize<D>(deserializer: D) -> Result<UndoType, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
deserializer.deserialize_str(UndoTypeVisitor)
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
use std::fmt;
|
||||
|
||||
use serde::{
|
||||
de::{self, Deserialize, Deserializer, Visitor}, ser::{Serialize, Serializer},
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct UpdateType;
|
||||
|
||||
impl Serialize for UpdateType {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_str("Update")
|
||||
}
|
||||
}
|
||||
|
||||
pub struct UpdateTypeVisitor;
|
||||
|
||||
impl<'de> Visitor<'de> for UpdateTypeVisitor {
|
||||
type Value = UpdateType;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(formatter, "The string 'Update'")
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
if v == "Update" {
|
||||
Ok(UpdateType)
|
||||
} else {
|
||||
Err(de::Error::custom("Type not update"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for UpdateType {
|
||||
fn deserialize<D>(deserializer: D) -> Result<UpdateType, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
deserializer.deserialize_str(UpdateTypeVisitor)
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
use std::fmt;
|
||||
|
||||
use serde::{
|
||||
de::{self, Deserialize, Deserializer, Visitor}, ser::{Serialize, Serializer},
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct ViewType;
|
||||
|
||||
impl Serialize for ViewType {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_str("View")
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ViewTypeVisitor;
|
||||
|
||||
impl<'de> Visitor<'de> for ViewTypeVisitor {
|
||||
type Value = ViewType;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(formatter, "The string 'View'")
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
if v == "View" {
|
||||
Ok(ViewType)
|
||||
} else {
|
||||
Err(de::Error::custom("Type not View"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for ViewType {
|
||||
fn deserialize<D>(deserializer: D) -> Result<ViewType, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
deserializer.deserialize_str(ViewTypeVisitor)
|
||||
}
|
||||
}
|
|
@ -2,48 +2,29 @@ use serde_json;
|
|||
|
||||
use super::{kind::LeaveType, properties::ActivityProperties, Activity};
|
||||
|
||||
use error::{Error, Result};
|
||||
use error::Result;
|
||||
use link::Link;
|
||||
use object::{Object, ObjectProperties};
|
||||
use Properties;
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, Properties)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Leave {
|
||||
#[serde(rename = "type")]
|
||||
kind: LeaveType,
|
||||
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
actor: serde_json::Value,
|
||||
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
object: serde_json::Value,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub object_props: ObjectProperties,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub activity_props: ActivityProperties,
|
||||
}
|
||||
|
||||
impl Leave {
|
||||
pub fn actor<O: Object>(&self) -> Result<O> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actors<O: Object>(&self) -> Result<Vec<O>> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actor_link<L: Link>(&self) -> Result<L> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actor_links<L: Link>(&self) -> Result<Vec<L>> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn object<O: Object>(&self) -> Result<O> {
|
||||
serde_json::from_value(self.object.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn objects<O: Object>(&self) -> Result<Vec<O>> {
|
||||
serde_json::from_value(self.object.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
}
|
||||
|
||||
impl Object for Leave {}
|
||||
impl Activity for Leave {}
|
||||
|
|
|
@ -2,48 +2,29 @@ use serde_json;
|
|||
|
||||
use super::{kind::LikeType, properties::ActivityProperties, Activity};
|
||||
|
||||
use error::{Error, Result};
|
||||
use error::Result;
|
||||
use link::Link;
|
||||
use object::{Object, ObjectProperties};
|
||||
use Properties;
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, Properties)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Like {
|
||||
#[serde(rename = "type")]
|
||||
kind: LikeType,
|
||||
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
actor: serde_json::Value,
|
||||
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
object: serde_json::Value,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub object_props: ObjectProperties,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub activity_props: ActivityProperties,
|
||||
}
|
||||
|
||||
impl Like {
|
||||
pub fn actor<O: Object>(&self) -> Result<O> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actors<O: Object>(&self) -> Result<Vec<O>> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actor_link<L: Link>(&self) -> Result<L> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actor_links<L: Link>(&self) -> Result<Vec<L>> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn object<O: Object>(&self) -> Result<O> {
|
||||
serde_json::from_value(self.object.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn objects<O: Object>(&self) -> Result<Vec<O>> {
|
||||
serde_json::from_value(self.object.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
}
|
||||
|
||||
impl Object for Like {}
|
||||
impl Activity for Like {}
|
||||
|
|
|
@ -2,48 +2,29 @@ use serde_json;
|
|||
|
||||
use super::{kind::ListenType, properties::ActivityProperties, Activity};
|
||||
|
||||
use error::{Error, Result};
|
||||
use error::Result;
|
||||
use link::Link;
|
||||
use object::{Object, ObjectProperties};
|
||||
use Properties;
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, Properties)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Listen {
|
||||
#[serde(rename = "type")]
|
||||
kind: ListenType,
|
||||
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
actor: serde_json::Value,
|
||||
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
object: serde_json::Value,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub object_props: ObjectProperties,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub activity_props: ActivityProperties,
|
||||
}
|
||||
|
||||
impl Listen {
|
||||
pub fn actor<O: Object>(&self) -> Result<O> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actors<O: Object>(&self) -> Result<Vec<O>> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actor_link<L: Link>(&self) -> Result<L> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actor_links<L: Link>(&self) -> Result<Vec<L>> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn object<O: Object>(&self) -> Result<O> {
|
||||
serde_json::from_value(self.object.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn objects<O: Object>(&self) -> Result<Vec<O>> {
|
||||
serde_json::from_value(self.object.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
}
|
||||
|
||||
impl Object for Listen {}
|
||||
impl Activity for Listen {}
|
||||
|
|
|
@ -2,69 +2,33 @@ use serde_json;
|
|||
|
||||
use super::{kind::OfferType, properties::ActivityProperties, Activity};
|
||||
|
||||
use error::{Error, Result};
|
||||
use error::Result;
|
||||
use link::Link;
|
||||
use object::{Object, ObjectProperties};
|
||||
use Properties;
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, Properties)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Offer {
|
||||
#[serde(rename = "type")]
|
||||
kind: OfferType,
|
||||
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
actor: serde_json::Value,
|
||||
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
object: serde_json::Value,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
target: Option<serde_json::Value>,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub object_props: ObjectProperties,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub activity_props: ActivityProperties,
|
||||
}
|
||||
|
||||
impl Properties for Offer {}
|
||||
|
||||
impl Offer {
|
||||
pub fn actor<O: Object>(&self) -> Result<O> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actors<O: Object>(&self) -> Result<Vec<O>> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actor_link<L: Link>(&self) -> Result<L> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actor_links<L: Link>(&self) -> Result<Vec<L>> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn object<O: Object>(&self) -> Result<O> {
|
||||
serde_json::from_value(self.object.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn objects<O: Object>(&self) -> Result<Vec<O>> {
|
||||
serde_json::from_value(self.object.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn target<O: Object>(&self) -> Result<O> {
|
||||
self.get_item(|d| &d.target)
|
||||
}
|
||||
|
||||
pub fn targets<O: Object>(&self) -> Result<O> {
|
||||
self.get_item(|d| &d.target)
|
||||
}
|
||||
|
||||
pub fn target_link<L: Link>(&self) -> Result<L> {
|
||||
self.get_item(|d| &d.target)
|
||||
}
|
||||
|
||||
pub fn target_links<L: Link>(&self) -> Result<Vec<L>> {
|
||||
self.get_item(|d| &d.target)
|
||||
}
|
||||
}
|
||||
|
||||
impl Object for Offer {}
|
||||
impl Activity for Offer {}
|
||||
|
|
|
@ -5,47 +5,14 @@ use link::Link;
|
|||
use object::Object;
|
||||
use Properties;
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, Properties)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct ActivityProperties {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
result: Option<serde_json::Value>,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
instrument: Option<serde_json::Value>,
|
||||
}
|
||||
|
||||
impl Properties for ActivityProperties {}
|
||||
|
||||
impl ActivityProperties {
|
||||
pub fn result<O: Object>(&self) -> Result<O> {
|
||||
self.get_item(|ap| &ap.result)
|
||||
}
|
||||
|
||||
pub fn results<O: Object>(&self) -> Result<Vec<O>> {
|
||||
self.get_item(|ap| &ap.result)
|
||||
}
|
||||
|
||||
pub fn result_link<L: Link>(&self) -> Result<L> {
|
||||
self.get_item(|ap| &ap.result)
|
||||
}
|
||||
|
||||
pub fn result_links<L: Link>(&self) -> Result<Vec<L>> {
|
||||
self.get_item(|ap| &ap.result)
|
||||
}
|
||||
|
||||
pub fn instrument<O: Object>(&self) -> Result<O> {
|
||||
self.get_item(|ap| &ap.instrument)
|
||||
}
|
||||
|
||||
pub fn instruments<O: Object>(&self) -> Result<Vec<O>> {
|
||||
self.get_item(|ap| &ap.instrument)
|
||||
}
|
||||
|
||||
pub fn instrument_link<L: Link>(&self) -> Result<L> {
|
||||
self.get_item(|ap| &ap.instrument)
|
||||
}
|
||||
|
||||
pub fn instrument_links<L: Link>(&self) -> Result<Vec<L>> {
|
||||
self.get_item(|ap| &ap.instrument)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,66 +1,33 @@
|
|||
use serde::de::DeserializeOwned;
|
||||
use serde_json;
|
||||
|
||||
use super::{kind::QuestionType, properties::ActivityProperties, Activity, IntransitiveActivity};
|
||||
|
||||
use error::{Error, Result};
|
||||
use error::Result;
|
||||
use link::Link;
|
||||
use object::{Object, ObjectProperties};
|
||||
use Properties;
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, Properties)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Question {
|
||||
#[serde(rename = "type")]
|
||||
kind: QuestionType,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
one_of: Option<Vec<serde_json::Value>>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
any_of: Option<Vec<serde_json::Value>>,
|
||||
|
||||
#[serde(skip_serializing_if = "Vec::is_empty", default = "Vec::new")]
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
one_of: Vec<serde_json::Value>,
|
||||
|
||||
#[serde(skip_serializing_if = "Vec::is_empty", default = "Vec::new")]
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
any_of: Vec<serde_json::Value>,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub object_props: ObjectProperties,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub activity_props: ActivityProperties,
|
||||
}
|
||||
|
||||
impl Properties for Question {}
|
||||
|
||||
impl Question {
|
||||
pub fn one_of<O: Object>(&self) -> Result<Vec<O>> {
|
||||
vec_item(&self.one_of)
|
||||
}
|
||||
|
||||
pub fn one_of_link<L: Link>(&self) -> Result<Vec<L>> {
|
||||
vec_item(&self.one_of)
|
||||
}
|
||||
|
||||
pub fn any_of<O: Object>(&self) -> Result<Vec<O>> {
|
||||
vec_item(&self.any_of)
|
||||
}
|
||||
|
||||
pub fn any_of_link<L: Link>(&self) -> Result<Vec<L>> {
|
||||
vec_item(&self.any_of)
|
||||
}
|
||||
}
|
||||
fn vec_item<D: DeserializeOwned>(v: &Option<Vec<serde_json::Value>>) -> Result<Vec<D>> {
|
||||
if let Some(v) = v.clone() {
|
||||
v.into_iter()
|
||||
.map(|value| serde_json::from_value(value))
|
||||
.fold(Ok(Vec::new()), |acc, item| match acc {
|
||||
Ok(mut v) => match item {
|
||||
Ok(item) => {
|
||||
v.push(item);
|
||||
Ok(v)
|
||||
}
|
||||
Err(_) => Err(Error::Deserialize),
|
||||
},
|
||||
Err(e) => Err(e),
|
||||
})
|
||||
} else {
|
||||
Err(Error::NotFound)
|
||||
}
|
||||
}
|
||||
|
||||
impl Object for Question {}
|
||||
impl Activity for Question {}
|
||||
impl IntransitiveActivity for Question {}
|
||||
|
|
|
@ -2,48 +2,29 @@ use serde_json;
|
|||
|
||||
use super::{kind::ReadType, properties::ActivityProperties, Activity};
|
||||
|
||||
use error::{Error, Result};
|
||||
use error::Result;
|
||||
use link::Link;
|
||||
use object::{Object, ObjectProperties};
|
||||
use Properties;
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, Properties)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Read {
|
||||
#[serde(rename = "type")]
|
||||
kind: ReadType,
|
||||
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
actor: serde_json::Value,
|
||||
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
object: serde_json::Value,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub object_props: ObjectProperties,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub activity_props: ActivityProperties,
|
||||
}
|
||||
|
||||
impl Read {
|
||||
pub fn actor<O: Object>(&self) -> Result<O> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actors<O: Object>(&self) -> Result<Vec<O>> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actor_link<L: Link>(&self) -> Result<L> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actor_links<L: Link>(&self) -> Result<Vec<L>> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn object<O: Object>(&self) -> Result<O> {
|
||||
serde_json::from_value(self.object.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn objects<O: Object>(&self) -> Result<Vec<O>> {
|
||||
serde_json::from_value(self.object.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
}
|
||||
|
||||
impl Object for Read {}
|
||||
impl Activity for Read {}
|
||||
|
|
|
@ -2,48 +2,29 @@ use serde_json;
|
|||
|
||||
use super::{kind::RejectType, properties::ActivityProperties, Activity};
|
||||
|
||||
use error::{Error, Result};
|
||||
use error::Result;
|
||||
use link::Link;
|
||||
use object::{Object, ObjectProperties};
|
||||
use Properties;
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, Properties)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Reject {
|
||||
#[serde(rename = "type")]
|
||||
kind: RejectType,
|
||||
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
actor: serde_json::Value,
|
||||
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
object: serde_json::Value,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub object_props: ObjectProperties,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub activity_props: ActivityProperties,
|
||||
}
|
||||
|
||||
impl Reject {
|
||||
pub fn actor<O: Object>(&self) -> Result<O> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actors<O: Object>(&self) -> Result<Vec<O>> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actor_link<L: Link>(&self) -> Result<L> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actor_links<L: Link>(&self) -> Result<Vec<L>> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn object<O: Object>(&self) -> Result<O> {
|
||||
serde_json::from_value(self.object.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn objects<O: Object>(&self) -> Result<Vec<O>> {
|
||||
serde_json::from_value(self.object.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
}
|
||||
|
||||
impl Object for Reject {}
|
||||
impl Activity for Reject {}
|
||||
|
|
|
@ -2,87 +2,37 @@ use serde_json;
|
|||
|
||||
use super::{kind::RemoveType, properties::ActivityProperties, Activity};
|
||||
|
||||
use error::{Error, Result};
|
||||
use error::Result;
|
||||
use link::Link;
|
||||
use object::{Object, ObjectProperties};
|
||||
use Properties;
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, Properties)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Remove {
|
||||
#[serde(rename = "type")]
|
||||
kind: RemoveType,
|
||||
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
actor: serde_json::Value,
|
||||
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
object: serde_json::Value,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
origin: Option<serde_json::Value>,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
target: Option<serde_json::Value>,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub object_props: ObjectProperties,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub activity_props: ActivityProperties,
|
||||
}
|
||||
|
||||
impl Properties for Remove {}
|
||||
|
||||
impl Remove {
|
||||
pub fn actor<O: Object>(&self) -> Result<O> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actors<O: Object>(&self) -> Result<Vec<O>> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actor_link<L: Link>(&self) -> Result<L> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actor_links<L: Link>(&self) -> Result<Vec<L>> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn object<O: Object>(&self) -> Result<O> {
|
||||
serde_json::from_value(self.object.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn objects<O: Object>(&self) -> Result<Vec<O>> {
|
||||
serde_json::from_value(self.object.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn origin<O: Object>(&self) -> Result<O> {
|
||||
self.get_item(|d| &d.origin)
|
||||
}
|
||||
|
||||
pub fn origins<O: Object>(&self) -> Result<O> {
|
||||
self.get_item(|d| &d.origin)
|
||||
}
|
||||
|
||||
pub fn origin_link<L: Link>(&self) -> Result<L> {
|
||||
self.get_item(|d| &d.origin)
|
||||
}
|
||||
|
||||
pub fn origin_links<L: Link>(&self) -> Result<Vec<L>> {
|
||||
self.get_item(|d| &d.origin)
|
||||
}
|
||||
|
||||
pub fn target<O: Object>(&self) -> Result<O> {
|
||||
self.get_item(|d| &d.target)
|
||||
}
|
||||
|
||||
pub fn targets<O: Object>(&self) -> Result<O> {
|
||||
self.get_item(|d| &d.target)
|
||||
}
|
||||
|
||||
pub fn target_link<L: Link>(&self) -> Result<L> {
|
||||
self.get_item(|d| &d.target)
|
||||
}
|
||||
|
||||
pub fn target_links<L: Link>(&self) -> Result<Vec<L>> {
|
||||
self.get_item(|d| &d.target)
|
||||
}
|
||||
}
|
||||
|
||||
impl Object for Remove {}
|
||||
impl Activity for Remove {}
|
||||
|
|
|
@ -2,48 +2,29 @@ use serde_json;
|
|||
|
||||
use super::{kind::TentativeAcceptType, properties::ActivityProperties, Activity};
|
||||
|
||||
use error::{Error, Result};
|
||||
use error::Result;
|
||||
use link::Link;
|
||||
use object::{Object, ObjectProperties};
|
||||
use Properties;
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, Properties)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct TentativeAccept {
|
||||
#[serde(rename = "type")]
|
||||
kind: TentativeAcceptType,
|
||||
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
actor: serde_json::Value,
|
||||
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
object: serde_json::Value,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub object_props: ObjectProperties,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub activity_props: ActivityProperties,
|
||||
}
|
||||
|
||||
impl TentativeAccept {
|
||||
pub fn actor<O: Object>(&self) -> Result<O> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actors<O: Object>(&self) -> Result<Vec<O>> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actor_link<L: Link>(&self) -> Result<L> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actor_links<L: Link>(&self) -> Result<Vec<L>> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn object<O: Object>(&self) -> Result<O> {
|
||||
serde_json::from_value(self.object.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn objects<O: Object>(&self) -> Result<Vec<O>> {
|
||||
serde_json::from_value(self.object.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
}
|
||||
|
||||
impl Object for TentativeAccept {}
|
||||
impl Activity for TentativeAccept {}
|
||||
|
|
|
@ -2,48 +2,29 @@ use serde_json;
|
|||
|
||||
use super::{kind::TentativeRejectType, properties::ActivityProperties, Activity};
|
||||
|
||||
use error::{Error, Result};
|
||||
use error::Result;
|
||||
use link::Link;
|
||||
use object::{Object, ObjectProperties};
|
||||
use Properties;
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, Properties)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct TentativeReject {
|
||||
#[serde(rename = "type")]
|
||||
kind: TentativeRejectType,
|
||||
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
actor: serde_json::Value,
|
||||
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
object: serde_json::Value,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub object_props: ObjectProperties,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub activity_props: ActivityProperties,
|
||||
}
|
||||
|
||||
impl TentativeReject {
|
||||
pub fn actor<O: Object>(&self) -> Result<O> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actors<O: Object>(&self) -> Result<Vec<O>> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actor_link<L: Link>(&self) -> Result<L> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actor_links<L: Link>(&self) -> Result<Vec<L>> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn object<O: Object>(&self) -> Result<O> {
|
||||
serde_json::from_value(self.object.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn objects<O: Object>(&self) -> Result<Vec<O>> {
|
||||
serde_json::from_value(self.object.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
}
|
||||
|
||||
impl Object for TentativeReject {}
|
||||
impl Activity for TentativeReject {}
|
||||
|
|
|
@ -2,79 +2,35 @@ use serde_json;
|
|||
|
||||
use super::{kind::TravelType, properties::ActivityProperties, Activity, IntransitiveActivity};
|
||||
|
||||
use error::{Error, Result};
|
||||
use error::Result;
|
||||
use link::Link;
|
||||
use object::{Object, ObjectProperties};
|
||||
use Properties;
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, Properties)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Travel {
|
||||
#[serde(rename = "type")]
|
||||
kind: TravelType,
|
||||
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
actor: serde_json::Value,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
origin: Option<serde_json::Value>,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
target: Option<serde_json::Value>,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub object_props: ObjectProperties,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub activity_props: ActivityProperties,
|
||||
}
|
||||
|
||||
impl Properties for Travel {}
|
||||
|
||||
impl Travel {
|
||||
pub fn actor<O: Object>(&self) -> Result<O> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actors<O: Object>(&self) -> Result<Vec<O>> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actor_link<L: Link>(&self) -> Result<L> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actor_links<L: Link>(&self) -> Result<Vec<L>> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn origin<O: Object>(&self) -> Result<O> {
|
||||
self.get_item(|d| &d.origin)
|
||||
}
|
||||
|
||||
pub fn origins<O: Object>(&self) -> Result<O> {
|
||||
self.get_item(|d| &d.origin)
|
||||
}
|
||||
|
||||
pub fn origin_link<L: Link>(&self) -> Result<L> {
|
||||
self.get_item(|d| &d.origin)
|
||||
}
|
||||
|
||||
pub fn origin_links<L: Link>(&self) -> Result<Vec<L>> {
|
||||
self.get_item(|d| &d.origin)
|
||||
}
|
||||
|
||||
pub fn target<O: Object>(&self) -> Result<O> {
|
||||
self.get_item(|d| &d.target)
|
||||
}
|
||||
|
||||
pub fn targets<O: Object>(&self) -> Result<O> {
|
||||
self.get_item(|d| &d.target)
|
||||
}
|
||||
|
||||
pub fn target_link<L: Link>(&self) -> Result<L> {
|
||||
self.get_item(|d| &d.target)
|
||||
}
|
||||
|
||||
pub fn target_links<L: Link>(&self) -> Result<Vec<L>> {
|
||||
self.get_item(|d| &d.target)
|
||||
}
|
||||
}
|
||||
|
||||
impl Object for Travel {}
|
||||
impl Activity for Travel {}
|
||||
impl IntransitiveActivity for Travel {}
|
||||
|
|
|
@ -2,48 +2,29 @@ use serde_json;
|
|||
|
||||
use super::{kind::UndoType, properties::ActivityProperties, Activity};
|
||||
|
||||
use error::{Error, Result};
|
||||
use error::Result;
|
||||
use link::Link;
|
||||
use object::{Object, ObjectProperties};
|
||||
use Properties;
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, Properties)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Undo {
|
||||
#[serde(rename = "type")]
|
||||
kind: UndoType,
|
||||
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
actor: serde_json::Value,
|
||||
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
object: serde_json::Value,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub object_props: ObjectProperties,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub activity_props: ActivityProperties,
|
||||
}
|
||||
|
||||
impl Undo {
|
||||
pub fn actor<O: Object>(&self) -> Result<O> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actors<O: Object>(&self) -> Result<Vec<O>> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actor_link<L: Link>(&self) -> Result<L> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actor_links<L: Link>(&self) -> Result<Vec<L>> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn object<O: Object>(&self) -> Result<O> {
|
||||
serde_json::from_value(self.object.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn objects<O: Object>(&self) -> Result<Vec<O>> {
|
||||
serde_json::from_value(self.object.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
}
|
||||
|
||||
impl Object for Undo {}
|
||||
impl Activity for Undo {}
|
||||
|
|
|
@ -2,48 +2,29 @@ use serde_json;
|
|||
|
||||
use super::{kind::UpdateType, properties::ActivityProperties, Activity};
|
||||
|
||||
use error::{Error, Result};
|
||||
use error::Result;
|
||||
use link::Link;
|
||||
use object::{Object, ObjectProperties};
|
||||
use Properties;
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, Properties)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Update {
|
||||
#[serde(rename = "type")]
|
||||
kind: UpdateType,
|
||||
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
actor: serde_json::Value,
|
||||
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
object: serde_json::Value,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub object_props: ObjectProperties,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub activity_props: ActivityProperties,
|
||||
}
|
||||
|
||||
impl Update {
|
||||
pub fn actor<O: Object>(&self) -> Result<O> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actors<O: Object>(&self) -> Result<Vec<O>> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actor_link<L: Link>(&self) -> Result<L> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actor_links<L: Link>(&self) -> Result<Vec<L>> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn object<O: Object>(&self) -> Result<O> {
|
||||
serde_json::from_value(self.object.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn objects<O: Object>(&self) -> Result<Vec<O>> {
|
||||
serde_json::from_value(self.object.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
}
|
||||
|
||||
impl Object for Update {}
|
||||
impl Activity for Update {}
|
||||
|
|
|
@ -2,48 +2,29 @@ use serde_json;
|
|||
|
||||
use super::{kind::ViewType, properties::ActivityProperties, Activity};
|
||||
|
||||
use error::{Error, Result};
|
||||
use error::Result;
|
||||
use link::Link;
|
||||
use object::{Object, ObjectProperties};
|
||||
use Properties;
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, Properties)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct View {
|
||||
#[serde(rename = "type")]
|
||||
kind: ViewType,
|
||||
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
actor: serde_json::Value,
|
||||
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
object: serde_json::Value,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub object_props: ObjectProperties,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub activity_props: ActivityProperties,
|
||||
}
|
||||
|
||||
impl View {
|
||||
pub fn actor<O: Object>(&self) -> Result<O> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actors<O: Object>(&self) -> Result<Vec<O>> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actor_link<L: Link>(&self) -> Result<L> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn actor_links<L: Link>(&self) -> Result<Vec<L>> {
|
||||
serde_json::from_value(self.actor.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn object<O: Object>(&self) -> Result<O> {
|
||||
serde_json::from_value(self.object.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn objects<O: Object>(&self) -> Result<Vec<O>> {
|
||||
serde_json::from_value(self.object.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
}
|
||||
|
||||
impl Object for View {}
|
||||
impl Activity for View {}
|
||||
|
|
25
src/actor/kind.rs
Normal file
25
src/actor/kind.rs
Normal file
|
@ -0,0 +1,25 @@
|
|||
use std::fmt;
|
||||
|
||||
use serde::{
|
||||
de::{self, Deserialize, Deserializer, Visitor}, ser::{Serialize, Serializer},
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug, UnitString)]
|
||||
#[activitystreams(Application)]
|
||||
pub struct ApplicationType;
|
||||
|
||||
#[derive(Clone, Debug, UnitString)]
|
||||
#[activitystreams(Group)]
|
||||
pub struct GroupType;
|
||||
|
||||
#[derive(Clone, Debug, UnitString)]
|
||||
#[activitystreams(Organization)]
|
||||
pub struct OrganizationType;
|
||||
|
||||
#[derive(Clone, Debug, UnitString)]
|
||||
#[activitystreams(Person)]
|
||||
pub struct PersonType;
|
||||
|
||||
#[derive(Clone, Debug, UnitString)]
|
||||
#[activitystreams(Service)]
|
||||
pub struct ServiceType;
|
|
@ -1,47 +0,0 @@
|
|||
use std::fmt;
|
||||
|
||||
use serde::{
|
||||
de::{self, Deserialize, Deserializer, Visitor}, ser::{Serialize, Serializer},
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct ApplicationType;
|
||||
|
||||
impl Serialize for ApplicationType {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_str("Application")
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ApplicationTypeVisitor;
|
||||
|
||||
impl<'de> Visitor<'de> for ApplicationTypeVisitor {
|
||||
type Value = ApplicationType;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(formatter, "The string 'Application'")
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
if v == "Application" {
|
||||
Ok(ApplicationType)
|
||||
} else {
|
||||
Err(de::Error::custom("Type not Application"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for ApplicationType {
|
||||
fn deserialize<D>(deserializer: D) -> Result<ApplicationType, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
deserializer.deserialize_str(ApplicationTypeVisitor)
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
use std::fmt;
|
||||
|
||||
use serde::{
|
||||
de::{self, Deserialize, Deserializer, Visitor}, ser::{Serialize, Serializer},
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct GroupType;
|
||||
|
||||
impl Serialize for GroupType {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_str("Group")
|
||||
}
|
||||
}
|
||||
|
||||
pub struct GroupTypeVisitor;
|
||||
|
||||
impl<'de> Visitor<'de> for GroupTypeVisitor {
|
||||
type Value = GroupType;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(formatter, "The string 'Group'")
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
if v == "Group" {
|
||||
Ok(GroupType)
|
||||
} else {
|
||||
Err(de::Error::custom("Type not Group"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for GroupType {
|
||||
fn deserialize<D>(deserializer: D) -> Result<GroupType, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
deserializer.deserialize_str(GroupTypeVisitor)
|
||||
}
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
mod application;
|
||||
mod group;
|
||||
mod organization;
|
||||
mod person;
|
||||
mod service;
|
||||
|
||||
pub use self::application::*;
|
||||
pub use self::group::*;
|
||||
pub use self::organization::*;
|
||||
pub use self::person::*;
|
||||
pub use self::service::*;
|
|
@ -1,47 +0,0 @@
|
|||
use std::fmt;
|
||||
|
||||
use serde::{
|
||||
de::{self, Deserialize, Deserializer, Visitor}, ser::{Serialize, Serializer},
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct OrganizationType;
|
||||
|
||||
impl Serialize for OrganizationType {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_str("Organization")
|
||||
}
|
||||
}
|
||||
|
||||
pub struct OrganizationTypeVisitor;
|
||||
|
||||
impl<'de> Visitor<'de> for OrganizationTypeVisitor {
|
||||
type Value = OrganizationType;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(formatter, "The string 'Organization'")
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
if v == "Organization" {
|
||||
Ok(OrganizationType)
|
||||
} else {
|
||||
Err(de::Error::custom("Type not Organization"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for OrganizationType {
|
||||
fn deserialize<D>(deserializer: D) -> Result<OrganizationType, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
deserializer.deserialize_str(OrganizationTypeVisitor)
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
use std::fmt;
|
||||
|
||||
use serde::{
|
||||
de::{self, Deserialize, Deserializer, Visitor}, ser::{Serialize, Serializer},
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct PersonType;
|
||||
|
||||
impl Serialize for PersonType {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_str("Person")
|
||||
}
|
||||
}
|
||||
|
||||
pub struct PersonTypeVisitor;
|
||||
|
||||
impl<'de> Visitor<'de> for PersonTypeVisitor {
|
||||
type Value = PersonType;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(formatter, "The string 'Person'")
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
if v == "Person" {
|
||||
Ok(PersonType)
|
||||
} else {
|
||||
Err(de::Error::custom("Type not Person"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for PersonType {
|
||||
fn deserialize<D>(deserializer: D) -> Result<PersonType, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
deserializer.deserialize_str(PersonTypeVisitor)
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
use std::fmt;
|
||||
|
||||
use serde::{
|
||||
de::{self, Deserialize, Deserializer, Visitor}, ser::{Serialize, Serializer},
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct ServiceType;
|
||||
|
||||
impl Serialize for ServiceType {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_str("Service")
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ServiceTypeVisitor;
|
||||
|
||||
impl<'de> Visitor<'de> for ServiceTypeVisitor {
|
||||
type Value = ServiceType;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(formatter, "The string 'Service'")
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
if v == "Service" {
|
||||
Ok(ServiceType)
|
||||
} else {
|
||||
Err(de::Error::custom("Type not Service"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for ServiceType {
|
||||
fn deserialize<D>(deserializer: D) -> Result<ServiceType, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
deserializer.deserialize_str(ServiceTypeVisitor)
|
||||
}
|
||||
}
|
|
@ -10,6 +10,7 @@ pub trait Actor: Object {}
|
|||
pub struct Appliation {
|
||||
#[serde(rename = "type")]
|
||||
kind: ApplicationType,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub object_props: ObjectProperties,
|
||||
}
|
||||
|
@ -21,6 +22,7 @@ impl Object for Appliation {}
|
|||
pub struct Group {
|
||||
#[serde(rename = "type")]
|
||||
kind: GroupType,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub object_props: ObjectProperties,
|
||||
}
|
||||
|
@ -32,6 +34,7 @@ impl Object for Group {}
|
|||
pub struct Organization {
|
||||
#[serde(rename = "type")]
|
||||
kind: OrganizationType,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub object_props: ObjectProperties,
|
||||
}
|
||||
|
@ -43,6 +46,7 @@ impl Object for Organization {}
|
|||
pub struct Person {
|
||||
#[serde(rename = "type")]
|
||||
kind: PersonType,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub object_props: ObjectProperties,
|
||||
}
|
||||
|
@ -54,6 +58,7 @@ impl Object for Person {}
|
|||
pub struct Service {
|
||||
#[serde(rename = "type")]
|
||||
kind: ServiceType,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub object_props: ObjectProperties,
|
||||
}
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
use serde::{de::DeserializeOwned, ser::Serialize};
|
||||
|
||||
pub trait Base: Serialize + DeserializeOwned {}
|
21
src/collection/kind.rs
Normal file
21
src/collection/kind.rs
Normal file
|
@ -0,0 +1,21 @@
|
|||
use std::fmt;
|
||||
|
||||
use serde::{
|
||||
de::{self, Deserialize, Deserializer, Visitor}, ser::{Serialize, Serializer},
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug, UnitString)]
|
||||
#[activitystreams(Collection)]
|
||||
pub struct CollectionType;
|
||||
|
||||
#[derive(Clone, Debug, UnitString)]
|
||||
#[activitystreams(CollectionPage)]
|
||||
pub struct CollectionPageType;
|
||||
|
||||
#[derive(Clone, Debug, UnitString)]
|
||||
#[activitystreams(OrderedCollection)]
|
||||
pub struct OrderedCollectionType;
|
||||
|
||||
#[derive(Clone, Debug, UnitString)]
|
||||
#[activitystreams(OrderedCollectionPage)]
|
||||
pub struct OrderedCollectionPageType;
|
|
@ -1,47 +0,0 @@
|
|||
use std::fmt;
|
||||
|
||||
use serde::{
|
||||
de::{self, Deserialize, Deserializer, Visitor}, ser::{Serialize, Serializer},
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct CollectionType;
|
||||
|
||||
impl Serialize for CollectionType {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_str("Collection")
|
||||
}
|
||||
}
|
||||
|
||||
pub struct CollectionTypeVisitor;
|
||||
|
||||
impl<'de> Visitor<'de> for CollectionTypeVisitor {
|
||||
type Value = CollectionType;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(formatter, "The string 'Collection'")
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
if v == "Collection" {
|
||||
Ok(CollectionType)
|
||||
} else {
|
||||
Err(de::Error::custom("Type not Collection"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for CollectionType {
|
||||
fn deserialize<D>(deserializer: D) -> Result<CollectionType, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
deserializer.deserialize_str(CollectionTypeVisitor)
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
use std::fmt;
|
||||
|
||||
use serde::{
|
||||
de::{self, Deserialize, Deserializer, Visitor}, ser::{Serialize, Serializer},
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct CollectionPageType;
|
||||
|
||||
impl Serialize for CollectionPageType {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_str("CollectionPage")
|
||||
}
|
||||
}
|
||||
|
||||
pub struct CollectionPageTypeVisitor;
|
||||
|
||||
impl<'de> Visitor<'de> for CollectionPageTypeVisitor {
|
||||
type Value = CollectionPageType;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(formatter, "The string 'CollectionPage'")
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
if v == "CollectionPage" {
|
||||
Ok(CollectionPageType)
|
||||
} else {
|
||||
Err(de::Error::custom("Type not CollectionPage"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for CollectionPageType {
|
||||
fn deserialize<D>(deserializer: D) -> Result<CollectionPageType, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
deserializer.deserialize_str(CollectionPageTypeVisitor)
|
||||
}
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
mod collection;
|
||||
mod collection_page;
|
||||
mod ordered_collection;
|
||||
mod ordered_collection_page;
|
||||
|
||||
pub use self::collection::*;
|
||||
pub use self::collection_page::*;
|
||||
pub use self::ordered_collection::*;
|
||||
pub use self::ordered_collection_page::*;
|
|
@ -1,47 +0,0 @@
|
|||
use std::fmt;
|
||||
|
||||
use serde::{
|
||||
de::{self, Deserialize, Deserializer, Visitor}, ser::{Serialize, Serializer},
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct OrderedCollectionType;
|
||||
|
||||
impl Serialize for OrderedCollectionType {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_str("OrderedCollection")
|
||||
}
|
||||
}
|
||||
|
||||
pub struct OrderedCollectionTypeVisitor;
|
||||
|
||||
impl<'de> Visitor<'de> for OrderedCollectionTypeVisitor {
|
||||
type Value = OrderedCollectionType;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(formatter, "The string 'OrderedCollection'")
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
if v == "OrderedCollection" {
|
||||
Ok(OrderedCollectionType)
|
||||
} else {
|
||||
Err(de::Error::custom("Type not OrderedCollection"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for OrderedCollectionType {
|
||||
fn deserialize<D>(deserializer: D) -> Result<OrderedCollectionType, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
deserializer.deserialize_str(OrderedCollectionTypeVisitor)
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
use std::fmt;
|
||||
|
||||
use serde::{
|
||||
de::{self, Deserialize, Deserializer, Visitor}, ser::{Serialize, Serializer},
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct OrderedCollectionPageType;
|
||||
|
||||
impl Serialize for OrderedCollectionPageType {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_str("OrderedCollectionPage")
|
||||
}
|
||||
}
|
||||
|
||||
pub struct OrderedCollectionPageTypeVisitor;
|
||||
|
||||
impl<'de> Visitor<'de> for OrderedCollectionPageTypeVisitor {
|
||||
type Value = OrderedCollectionPageType;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(formatter, "The string 'OrderedCollectionPage'")
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
if v == "OrderedCollectionPage" {
|
||||
Ok(OrderedCollectionPageType)
|
||||
} else {
|
||||
Err(de::Error::custom("Type not OrderedCollectionPage"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for OrderedCollectionPageType {
|
||||
fn deserialize<D>(deserializer: D) -> Result<OrderedCollectionPageType, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
deserializer.deserialize_str(OrderedCollectionPageTypeVisitor)
|
||||
}
|
||||
}
|
|
@ -1,68 +1,78 @@
|
|||
use serde_json;
|
||||
|
||||
use error::Result;
|
||||
use link::Link;
|
||||
use object::Object;
|
||||
|
||||
mod kind;
|
||||
mod properties;
|
||||
pub use self::kind::*;
|
||||
pub use self::properties::*;
|
||||
use Properties;
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, Properties)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Collection {
|
||||
#[serde(rename = "@context")]
|
||||
context: serde_json::Value,
|
||||
#[serde(rename = "type")]
|
||||
kind: CollectionType,
|
||||
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
items: Vec<serde_json::Value>,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub collection_props: CollectionProperties,
|
||||
}
|
||||
|
||||
impl Object for Collection {}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, Properties)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct OrderedCollection {
|
||||
#[serde(rename = "@context")]
|
||||
context: serde_json::Value,
|
||||
#[serde(rename = "type")]
|
||||
kind: OrderedCollectionType,
|
||||
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
items: Vec<serde_json::Value>,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub collection_props: CollectionProperties,
|
||||
}
|
||||
|
||||
impl Object for OrderedCollection {}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, Properties)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct CollectionPage {
|
||||
#[serde(rename = "@context")]
|
||||
context: serde_json::Value,
|
||||
#[serde(rename = "type")]
|
||||
kind: CollectionPageType,
|
||||
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
items: Vec<serde_json::Value>,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub collection_props: CollectionProperties,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub collection_page_props: CollectionPageProperties,
|
||||
}
|
||||
|
||||
impl Object for CollectionPage {}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, Properties)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct OrderedCollectionPage {
|
||||
#[serde(rename = "@context")]
|
||||
context: serde_json::Value,
|
||||
#[serde(rename = "type")]
|
||||
kind: OrderedCollectionPageType,
|
||||
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
items: Vec<serde_json::Value>,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub collection_props: CollectionProperties,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub collection_page_props: CollectionPageProperties,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub ordered_collection_page_props: OrderedCollectionPageProperties,
|
||||
}
|
||||
|
|
|
@ -5,101 +5,46 @@ use error::Result;
|
|||
use link::Link;
|
||||
use Properties;
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, Properties)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct CollectionProperties {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[activitystreams(concrete(u64), functional)]
|
||||
total_items: Option<serde_json::Value>,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[activitystreams(concrete(CollectionPage), ab(Link), functional)]
|
||||
current: Option<serde_json::Value>,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[activitystreams(concrete(CollectionPage), ab(Link), functional)]
|
||||
first: Option<serde_json::Value>,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[activitystreams(concrete(CollectionPage), ab(Link), functional)]
|
||||
last: Option<serde_json::Value>,
|
||||
}
|
||||
|
||||
impl Properties for CollectionProperties {}
|
||||
|
||||
impl CollectionProperties {
|
||||
pub fn total_items(&self) -> Result<u64> {
|
||||
self.get_item(|c| &c.total_items)
|
||||
}
|
||||
|
||||
pub fn current(&self) -> Result<CollectionPage> {
|
||||
self.get_item(|c| &c.current)
|
||||
}
|
||||
|
||||
pub fn current_link<L: Link>(&self) -> Result<L> {
|
||||
self.get_item(|c| &c.current)
|
||||
}
|
||||
|
||||
pub fn first(&self) -> Result<CollectionPage> {
|
||||
self.get_item(|c| &c.first)
|
||||
}
|
||||
|
||||
pub fn first_link<L: Link>(&self) -> Result<L> {
|
||||
self.get_item(|c| &c.first)
|
||||
}
|
||||
|
||||
pub fn last(&self) -> Result<CollectionPage> {
|
||||
self.get_item(|c| &c.last)
|
||||
}
|
||||
|
||||
pub fn last_link<L: Link>(&self) -> Result<L> {
|
||||
self.get_item(|c| &c.last)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, Properties)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct CollectionPageProperties {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[activitystreams(concrete(Collection), ab(Link), functional)]
|
||||
part_of: Option<serde_json::Value>,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[activitystreams(concrete(CollectionPage), ab(Link), functional)]
|
||||
next: Option<serde_json::Value>,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[activitystreams(concrete(CollectionPage), ab(Link), functional)]
|
||||
prev: Option<serde_json::Value>,
|
||||
}
|
||||
|
||||
impl Properties for CollectionPageProperties {}
|
||||
|
||||
impl CollectionPageProperties {
|
||||
pub fn part_of(&self) -> Result<Collection> {
|
||||
self.get_item(|c| &c.part_of)
|
||||
}
|
||||
|
||||
pub fn part_of_link<L: Link>(&self) -> Result<L> {
|
||||
self.get_item(|c| &c.part_of)
|
||||
}
|
||||
|
||||
pub fn next(&self) -> Result<CollectionPage> {
|
||||
self.get_item(|c| &c.next)
|
||||
}
|
||||
|
||||
pub fn next_link<L: Link>(&self) -> Result<L> {
|
||||
self.get_item(|c| &c.next)
|
||||
}
|
||||
|
||||
pub fn prev(&self) -> Result<CollectionPage> {
|
||||
self.get_item(|c| &c.prev)
|
||||
}
|
||||
|
||||
pub fn prev_link<L: Link>(&self) -> Result<L> {
|
||||
self.get_item(|c| &c.prev)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, Properties)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct OrderedCollectionPageProperties {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[activitystreams(concrete(u64), functional)]
|
||||
start_index: Option<serde_json::Value>,
|
||||
}
|
||||
|
||||
impl Properties for OrderedCollectionPageProperties {}
|
||||
|
||||
impl OrderedCollectionPageProperties {
|
||||
pub fn start_index(&self) -> Result<u64> {
|
||||
self.get_item(|c| &c.start_index)
|
||||
}
|
||||
}
|
||||
|
|
30
src/lib.rs
30
src/lib.rs
|
@ -1,4 +1,6 @@
|
|||
#[macro_use]
|
||||
extern crate activitystreams_derive;
|
||||
#[macro_use]
|
||||
extern crate failure;
|
||||
extern crate mime;
|
||||
extern crate serde;
|
||||
|
@ -14,6 +16,14 @@ pub fn context() -> serde_json::Value {
|
|||
}
|
||||
|
||||
pub trait Properties {
|
||||
fn get_value<F, I>(&self, f: F) -> error::Result<I>
|
||||
where
|
||||
F: FnOnce(&Self) -> &serde_json::Value,
|
||||
I: serde::de::DeserializeOwned,
|
||||
{
|
||||
serde_json::from_value(f(self).clone()).map_err(|_| error::Error::Deserialize)
|
||||
}
|
||||
|
||||
fn get_item<F, I>(&self, f: F) -> error::Result<I>
|
||||
where
|
||||
F: FnOnce(&Self) -> &Option<serde_json::Value>,
|
||||
|
@ -25,11 +35,29 @@ pub trait Properties {
|
|||
Err(error::Error::NotFound)
|
||||
}
|
||||
}
|
||||
|
||||
fn get_vec<F, I>(&self, f: F) -> error::Result<Vec<I>>
|
||||
where
|
||||
F: FnOnce(&Self) -> &Vec<serde_json::Value>,
|
||||
I: serde::de::DeserializeOwned,
|
||||
{
|
||||
let item = f(self);
|
||||
|
||||
item.iter().fold(Ok(Vec::new()), |acc, item| match acc {
|
||||
Ok(mut acc) => match serde_json::from_value(item.clone()) {
|
||||
Ok(item) => {
|
||||
acc.push(item);
|
||||
Ok(acc)
|
||||
}
|
||||
Err(_) => Err(error::Error::Deserialize),
|
||||
},
|
||||
Err(e) => Err(e),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub mod activity;
|
||||
pub mod actor;
|
||||
pub mod base;
|
||||
pub mod collection;
|
||||
pub mod error;
|
||||
pub mod link;
|
||||
|
|
|
@ -4,44 +4,6 @@ use serde::{
|
|||
de::{self, Deserialize, Deserializer, Visitor}, ser::{Serialize, Serializer},
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone, Debug, UnitString)]
|
||||
#[activitystreams(Mention)]
|
||||
pub struct MentionType;
|
||||
|
||||
impl Serialize for MentionType {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_str("Mention")
|
||||
}
|
||||
}
|
||||
|
||||
pub struct MentionTypeVisitor;
|
||||
|
||||
impl<'de> Visitor<'de> for MentionTypeVisitor {
|
||||
type Value = MentionType;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(formatter, "The string 'Mention'")
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
if v == "Mention" {
|
||||
Ok(MentionType)
|
||||
} else {
|
||||
Err(de::Error::custom("Type not Mention"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for MentionType {
|
||||
fn deserialize<D>(deserializer: D) -> Result<MentionType, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
deserializer.deserialize_str(MentionTypeVisitor)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ pub trait Link: DeserializeOwned + Serialize {}
|
|||
pub struct Mention {
|
||||
#[serde(rename = "type")]
|
||||
kind: MentionType,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub link_props: LinkProperties,
|
||||
}
|
||||
|
|
|
@ -6,70 +6,50 @@ use link::Link;
|
|||
use object::Object;
|
||||
use Properties;
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, Properties)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct LinkProperties {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[activitystreams(concrete(String), functional)]
|
||||
id: Option<serde_json::Value>,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[activitystreams(concrete(String), functional)]
|
||||
href: Option<serde_json::Value>,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[activitystreams(concrete(String))]
|
||||
rel: Option<serde_json::Value>,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[activitystreams(concrete(String), functional)]
|
||||
media_type: Option<serde_json::Value>,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[activitystreams(concrete(String))]
|
||||
name: Option<serde_json::Value>,
|
||||
|
||||
// TODO: Lang enum
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[activitystreams(concrete(String), functional)]
|
||||
hreflang: Option<serde_json::Value>,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[activitystreams(concrete(u64), functional)]
|
||||
height: Option<serde_json::Value>,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[activitystreams(concrete(u64), functional)]
|
||||
width: Option<serde_json::Value>,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
preview: Option<serde_json::Value>,
|
||||
}
|
||||
|
||||
impl Properties for LinkProperties {}
|
||||
|
||||
impl LinkProperties {
|
||||
pub fn id(&self) -> Result<String> {
|
||||
self.get_item(|l| &l.id)
|
||||
}
|
||||
|
||||
pub fn href(&self) -> Result<String> {
|
||||
self.get_item(|l| &l.href)
|
||||
}
|
||||
|
||||
pub fn rel(&self) -> Result<String> {
|
||||
self.get_item(|l| &l.rel)
|
||||
}
|
||||
|
||||
pub fn rels(&self) -> Result<Vec<String>> {
|
||||
self.get_item(|l| &l.rel)
|
||||
}
|
||||
|
||||
pub fn media_type(&self) -> Result<mime::Mime> {
|
||||
self.get_item::<_, String>(|l| &l.media_type)
|
||||
self.media_type_string()
|
||||
.and_then(|s| s.parse().map_err(|_| Error::Deserialize))
|
||||
}
|
||||
|
||||
pub fn name(&self) -> Result<String> {
|
||||
self.get_item(|l| &l.name)
|
||||
}
|
||||
|
||||
pub fn names(&self) -> Result<Vec<String>> {
|
||||
self.get_item(|l| &l.name)
|
||||
}
|
||||
|
||||
// TODO: Lang enum
|
||||
pub fn hreflang(&self) -> Result<String> {
|
||||
self.get_item(|l| &l.hreflang)
|
||||
}
|
||||
|
||||
pub fn height(&self) -> Result<u64> {
|
||||
self.get_item(|l| &l.height)
|
||||
}
|
||||
|
||||
pub fn width(&self) -> Result<u64> {
|
||||
self.get_item(|l| &l.width)
|
||||
}
|
||||
|
||||
pub fn preview<O: Object>(&self) -> Result<O> {
|
||||
self.get_item(|l| &l.preview)
|
||||
}
|
||||
|
||||
pub fn preview_link<L: Link>(&self) -> Result<L> {
|
||||
self.get_item(|l| &l.preview)
|
||||
}
|
||||
}
|
||||
|
|
53
src/object/kind.rs
Normal file
53
src/object/kind.rs
Normal file
|
@ -0,0 +1,53 @@
|
|||
use std::fmt;
|
||||
|
||||
use serde::{
|
||||
de::{self, Deserialize, Deserializer, Visitor}, ser::{Serialize, Serializer},
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug, UnitString)]
|
||||
#[activitystreams(Article)]
|
||||
pub struct ArticleType;
|
||||
|
||||
#[derive(Clone, Debug, UnitString)]
|
||||
#[activitystreams(Audio)]
|
||||
pub struct AudioType;
|
||||
|
||||
#[derive(Clone, Debug, UnitString)]
|
||||
#[activitystreams(Document)]
|
||||
pub struct DocumentType;
|
||||
|
||||
#[derive(Clone, Debug, UnitString)]
|
||||
#[activitystreams(Event)]
|
||||
pub struct EventType;
|
||||
|
||||
#[derive(Clone, Debug, UnitString)]
|
||||
#[activitystreams(Image)]
|
||||
pub struct ImageType;
|
||||
|
||||
#[derive(Clone, Debug, UnitString)]
|
||||
#[activitystreams(Note)]
|
||||
pub struct NoteType;
|
||||
|
||||
#[derive(Clone, Debug, UnitString)]
|
||||
#[activitystreams(Page)]
|
||||
pub struct PageType;
|
||||
|
||||
#[derive(Clone, Debug, UnitString)]
|
||||
#[activitystreams(Place)]
|
||||
pub struct PlaceType;
|
||||
|
||||
#[derive(Clone, Debug, UnitString)]
|
||||
#[activitystreams(Profile)]
|
||||
pub struct ProfileType;
|
||||
|
||||
#[derive(Clone, Debug, UnitString)]
|
||||
#[activitystreams(Relationship)]
|
||||
pub struct RelationshipType;
|
||||
|
||||
#[derive(Clone, Debug, UnitString)]
|
||||
#[activitystreams(Tombstone)]
|
||||
pub struct TombstoneType;
|
||||
|
||||
#[derive(Clone, Debug, UnitString)]
|
||||
#[activitystreams(Video)]
|
||||
pub struct VideoType;
|
|
@ -1,47 +0,0 @@
|
|||
use std::fmt;
|
||||
|
||||
use serde::{
|
||||
de::{self, Deserialize, Deserializer, Visitor}, ser::{Serialize, Serializer},
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct ArticleType;
|
||||
|
||||
impl Serialize for ArticleType {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_str("Article")
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ArticleTypeVisitor;
|
||||
|
||||
impl<'de> Visitor<'de> for ArticleTypeVisitor {
|
||||
type Value = ArticleType;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(formatter, "The string 'Article'")
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
if v == "Article" {
|
||||
Ok(ArticleType)
|
||||
} else {
|
||||
Err(de::Error::custom("Type not Article"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for ArticleType {
|
||||
fn deserialize<D>(deserializer: D) -> Result<ArticleType, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
deserializer.deserialize_str(ArticleTypeVisitor)
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
use std::fmt;
|
||||
|
||||
use serde::{
|
||||
de::{self, Deserialize, Deserializer, Visitor}, ser::{Serialize, Serializer},
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct AudioType;
|
||||
|
||||
impl Serialize for AudioType {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_str("Audio")
|
||||
}
|
||||
}
|
||||
|
||||
pub struct AudioTypeVisitor;
|
||||
|
||||
impl<'de> Visitor<'de> for AudioTypeVisitor {
|
||||
type Value = AudioType;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(formatter, "The string 'Audio'")
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
if v == "Audio" {
|
||||
Ok(AudioType)
|
||||
} else {
|
||||
Err(de::Error::custom("Type not Audio"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for AudioType {
|
||||
fn deserialize<D>(deserializer: D) -> Result<AudioType, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
deserializer.deserialize_str(AudioTypeVisitor)
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
use std::fmt;
|
||||
|
||||
use serde::{
|
||||
de::{self, Deserialize, Deserializer, Visitor}, ser::{Serialize, Serializer},
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct DocumentType;
|
||||
|
||||
impl Serialize for DocumentType {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_str("Document")
|
||||
}
|
||||
}
|
||||
|
||||
pub struct DocumentTypeVisitor;
|
||||
|
||||
impl<'de> Visitor<'de> for DocumentTypeVisitor {
|
||||
type Value = DocumentType;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(formatter, "The string 'Document'")
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
if v == "Document" {
|
||||
Ok(DocumentType)
|
||||
} else {
|
||||
Err(de::Error::custom("Type not Document"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for DocumentType {
|
||||
fn deserialize<D>(deserializer: D) -> Result<DocumentType, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
deserializer.deserialize_str(DocumentTypeVisitor)
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
use std::fmt;
|
||||
|
||||
use serde::{
|
||||
de::{self, Deserialize, Deserializer, Visitor}, ser::{Serialize, Serializer},
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct EventType;
|
||||
|
||||
impl Serialize for EventType {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_str("Event")
|
||||
}
|
||||
}
|
||||
|
||||
pub struct EventTypeVisitor;
|
||||
|
||||
impl<'de> Visitor<'de> for EventTypeVisitor {
|
||||
type Value = EventType;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(formatter, "The string 'Event'")
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
if v == "Event" {
|
||||
Ok(EventType)
|
||||
} else {
|
||||
Err(de::Error::custom("Type not Event"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for EventType {
|
||||
fn deserialize<D>(deserializer: D) -> Result<EventType, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
deserializer.deserialize_str(EventTypeVisitor)
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
use std::fmt;
|
||||
|
||||
use serde::{
|
||||
de::{self, Deserialize, Deserializer, Visitor}, ser::{Serialize, Serializer},
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct ImageType;
|
||||
|
||||
impl Serialize for ImageType {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_str("Image")
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ImageTypeVisitor;
|
||||
|
||||
impl<'de> Visitor<'de> for ImageTypeVisitor {
|
||||
type Value = ImageType;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(formatter, "The string 'Image'")
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
if v == "Image" {
|
||||
Ok(ImageType)
|
||||
} else {
|
||||
Err(de::Error::custom("Type not Image"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for ImageType {
|
||||
fn deserialize<D>(deserializer: D) -> Result<ImageType, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
deserializer.deserialize_str(ImageTypeVisitor)
|
||||
}
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
mod article;
|
||||
mod audio;
|
||||
mod document;
|
||||
mod event;
|
||||
mod image;
|
||||
mod note;
|
||||
mod page;
|
||||
mod place;
|
||||
mod profile;
|
||||
mod relationship;
|
||||
mod tombstone;
|
||||
mod video;
|
||||
|
||||
pub use self::article::*;
|
||||
pub use self::audio::*;
|
||||
pub use self::document::*;
|
||||
pub use self::event::*;
|
||||
pub use self::image::*;
|
||||
pub use self::note::*;
|
||||
pub use self::page::*;
|
||||
pub use self::place::*;
|
||||
pub use self::profile::*;
|
||||
pub use self::relationship::*;
|
||||
pub use self::tombstone::*;
|
||||
pub use self::video::*;
|
|
@ -1,47 +0,0 @@
|
|||
use std::fmt;
|
||||
|
||||
use serde::{
|
||||
de::{self, Deserialize, Deserializer, Visitor}, ser::{Serialize, Serializer},
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct NoteType;
|
||||
|
||||
impl Serialize for NoteType {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_str("Note")
|
||||
}
|
||||
}
|
||||
|
||||
pub struct NoteTypeVisitor;
|
||||
|
||||
impl<'de> Visitor<'de> for NoteTypeVisitor {
|
||||
type Value = NoteType;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(formatter, "The string 'Note'")
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
if v == "Note" {
|
||||
Ok(NoteType)
|
||||
} else {
|
||||
Err(de::Error::custom("Type not Note"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for NoteType {
|
||||
fn deserialize<D>(deserializer: D) -> Result<NoteType, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
deserializer.deserialize_str(NoteTypeVisitor)
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
use std::fmt;
|
||||
|
||||
use serde::{
|
||||
de::{self, Deserialize, Deserializer, Visitor}, ser::{Serialize, Serializer},
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct PageType;
|
||||
|
||||
impl Serialize for PageType {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_str("Page")
|
||||
}
|
||||
}
|
||||
|
||||
pub struct PageTypeVisitor;
|
||||
|
||||
impl<'de> Visitor<'de> for PageTypeVisitor {
|
||||
type Value = PageType;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(formatter, "The string 'Page'")
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
if v == "Page" {
|
||||
Ok(PageType)
|
||||
} else {
|
||||
Err(de::Error::custom("Type not Page"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for PageType {
|
||||
fn deserialize<D>(deserializer: D) -> Result<PageType, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
deserializer.deserialize_str(PageTypeVisitor)
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
use std::fmt;
|
||||
|
||||
use serde::{
|
||||
de::{self, Deserialize, Deserializer, Visitor}, ser::{Serialize, Serializer},
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct PlaceType;
|
||||
|
||||
impl Serialize for PlaceType {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_str("Place")
|
||||
}
|
||||
}
|
||||
|
||||
pub struct PlaceTypeVisitor;
|
||||
|
||||
impl<'de> Visitor<'de> for PlaceTypeVisitor {
|
||||
type Value = PlaceType;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(formatter, "The string 'Place'")
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
if v == "Place" {
|
||||
Ok(PlaceType)
|
||||
} else {
|
||||
Err(de::Error::custom("Type not Place"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for PlaceType {
|
||||
fn deserialize<D>(deserializer: D) -> Result<PlaceType, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
deserializer.deserialize_str(PlaceTypeVisitor)
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
use std::fmt;
|
||||
|
||||
use serde::{
|
||||
de::{self, Deserialize, Deserializer, Visitor}, ser::{Serialize, Serializer},
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct ProfileType;
|
||||
|
||||
impl Serialize for ProfileType {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_str("Profile")
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ProfileTypeVisitor;
|
||||
|
||||
impl<'de> Visitor<'de> for ProfileTypeVisitor {
|
||||
type Value = ProfileType;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(formatter, "The string 'Profile'")
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
if v == "Profile" {
|
||||
Ok(ProfileType)
|
||||
} else {
|
||||
Err(de::Error::custom("Type not Profile"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for ProfileType {
|
||||
fn deserialize<D>(deserializer: D) -> Result<ProfileType, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
deserializer.deserialize_str(ProfileTypeVisitor)
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
use std::fmt;
|
||||
|
||||
use serde::{
|
||||
de::{self, Deserialize, Deserializer, Visitor}, ser::{Serialize, Serializer},
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct RelationshipType;
|
||||
|
||||
impl Serialize for RelationshipType {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_str("Relationship")
|
||||
}
|
||||
}
|
||||
|
||||
pub struct RelationshipTypeVisitor;
|
||||
|
||||
impl<'de> Visitor<'de> for RelationshipTypeVisitor {
|
||||
type Value = RelationshipType;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(formatter, "The string 'Relationship'")
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
if v == "Relationship" {
|
||||
Ok(RelationshipType)
|
||||
} else {
|
||||
Err(de::Error::custom("Type not Relationship"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for RelationshipType {
|
||||
fn deserialize<D>(deserializer: D) -> Result<RelationshipType, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
deserializer.deserialize_str(RelationshipTypeVisitor)
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
use std::fmt;
|
||||
|
||||
use serde::{
|
||||
de::{self, Deserialize, Deserializer, Visitor}, ser::{Serialize, Serializer},
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct TombstoneType;
|
||||
|
||||
impl Serialize for TombstoneType {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_str("Tombstone")
|
||||
}
|
||||
}
|
||||
|
||||
pub struct TombstoneTypeVisitor;
|
||||
|
||||
impl<'de> Visitor<'de> for TombstoneTypeVisitor {
|
||||
type Value = TombstoneType;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(formatter, "The string 'Tombstone'")
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
if v == "Tombstone" {
|
||||
Ok(TombstoneType)
|
||||
} else {
|
||||
Err(de::Error::custom("Type not Tombstone"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for TombstoneType {
|
||||
fn deserialize<D>(deserializer: D) -> Result<TombstoneType, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
deserializer.deserialize_str(TombstoneTypeVisitor)
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
use std::fmt;
|
||||
|
||||
use serde::{
|
||||
de::{self, Deserialize, Deserializer, Visitor}, ser::{Serialize, Serializer},
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct VideoType;
|
||||
|
||||
impl Serialize for VideoType {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_str("Video")
|
||||
}
|
||||
}
|
||||
|
||||
pub struct VideoTypeVisitor;
|
||||
|
||||
impl<'de> Visitor<'de> for VideoTypeVisitor {
|
||||
type Value = VideoType;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(formatter, "The string 'Video'")
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
if v == "Video" {
|
||||
Ok(VideoType)
|
||||
} else {
|
||||
Err(de::Error::custom("Type not Video"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for VideoType {
|
||||
fn deserialize<D>(deserializer: D) -> Result<VideoType, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
deserializer.deserialize_str(VideoTypeVisitor)
|
||||
}
|
||||
}
|
|
@ -1,8 +1,9 @@
|
|||
use serde::{de::DeserializeOwned, ser::Serialize};
|
||||
use serde_json;
|
||||
|
||||
use error::{Error, Result};
|
||||
use error::Result;
|
||||
use link::Link;
|
||||
use Properties;
|
||||
|
||||
mod kind;
|
||||
mod properties;
|
||||
|
@ -16,6 +17,7 @@ pub trait Object: DeserializeOwned + Serialize {}
|
|||
pub struct Article {
|
||||
#[serde(rename = "type")]
|
||||
kind: ArticleType,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub object_props: ObjectProperties,
|
||||
}
|
||||
|
@ -27,6 +29,7 @@ impl Object for Article {}
|
|||
pub struct Audio {
|
||||
#[serde(rename = "type")]
|
||||
kind: AudioType,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub object_props: ObjectProperties,
|
||||
}
|
||||
|
@ -38,6 +41,7 @@ impl Object for Audio {}
|
|||
pub struct Document {
|
||||
#[serde(rename = "type")]
|
||||
kind: DocumentType,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub object_props: ObjectProperties,
|
||||
}
|
||||
|
@ -49,6 +53,7 @@ impl Object for Document {}
|
|||
pub struct Event {
|
||||
#[serde(rename = "type")]
|
||||
kind: EventType,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub object_props: ObjectProperties,
|
||||
}
|
||||
|
@ -60,6 +65,7 @@ impl Object for Event {}
|
|||
pub struct Image {
|
||||
#[serde(rename = "type")]
|
||||
kind: ImageType,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub object_props: ObjectProperties,
|
||||
}
|
||||
|
@ -71,6 +77,7 @@ impl Object for Image {}
|
|||
pub struct Note {
|
||||
#[serde(rename = "type")]
|
||||
kind: NoteType,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub object_props: ObjectProperties,
|
||||
}
|
||||
|
@ -82,6 +89,7 @@ impl Object for Note {}
|
|||
pub struct Page {
|
||||
#[serde(rename = "type")]
|
||||
kind: PageType,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub object_props: ObjectProperties,
|
||||
}
|
||||
|
@ -93,70 +101,50 @@ impl Object for Page {}
|
|||
pub struct Place {
|
||||
#[serde(rename = "type")]
|
||||
kind: PlaceType,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub object_props: ObjectProperties,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub place: PlaceProperties,
|
||||
}
|
||||
|
||||
impl Object for Place {}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, Properties)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Profile {
|
||||
#[serde(rename = "type")]
|
||||
kind: ProfileType,
|
||||
|
||||
#[activitystreams(ab(Object), functional)]
|
||||
describes: serde_json::Value,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub object_props: ObjectProperties,
|
||||
}
|
||||
|
||||
impl Profile {
|
||||
pub fn describes<O: Object>(&self) -> Result<O> {
|
||||
serde_json::from_value(self.describes.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
}
|
||||
|
||||
impl Object for Profile {}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, Properties)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Relationship {
|
||||
#[serde(rename = "type")]
|
||||
kind: RelationshipType,
|
||||
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
subject: serde_json::Value,
|
||||
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
object: serde_json::Value,
|
||||
|
||||
#[activitystreams(ab(Object))]
|
||||
relationship: serde_json::Value,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub object_props: ObjectProperties,
|
||||
}
|
||||
|
||||
impl Relationship {
|
||||
pub fn subject<O: Object>(&self) -> Result<O> {
|
||||
serde_json::from_value(self.subject.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn object<O: Object>(&self) -> Result<O> {
|
||||
serde_json::from_value(self.object.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn relationship<O: Object>(&self) -> Result<O> {
|
||||
serde_json::from_value(self.relationship.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn subject_link<L: Link>(&self) -> Result<L> {
|
||||
serde_json::from_value(self.subject.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn object_link<L: Link>(&self) -> Result<L> {
|
||||
serde_json::from_value(self.object.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
|
||||
pub fn relationship_link<L: Link>(&self) -> Result<L> {
|
||||
serde_json::from_value(self.relationship.clone()).map_err(|_| Error::Deserialize)
|
||||
}
|
||||
}
|
||||
|
||||
impl Object for Relationship {}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
|
@ -164,8 +152,10 @@ impl Object for Relationship {}
|
|||
pub struct Tombstone {
|
||||
#[serde(rename = "type")]
|
||||
kind: TombstoneType,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub object_props: ObjectProperties,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub tombstone_props: TombstoneProperties,
|
||||
}
|
||||
|
@ -177,6 +167,7 @@ impl Object for Tombstone {}
|
|||
pub struct Video {
|
||||
#[serde(rename = "type")]
|
||||
kind: VideoType,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub object_props: ObjectProperties,
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
use mime;
|
||||
use serde::de::DeserializeOwned;
|
||||
use serde_json;
|
||||
use serde_json::{self, Value};
|
||||
|
||||
use collection::Collection;
|
||||
use error::{Error, Result};
|
||||
|
@ -8,435 +7,164 @@ use link::Link;
|
|||
use object::{Image, Object};
|
||||
use Properties;
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, Properties)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct ObjectProperties {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[activitystreams(concrete(String), functional)]
|
||||
id: Option<serde_json::Value>,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
attachment: Option<serde_json::Value>,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
attributed_to: Option<serde_json::Value>,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
audience: Option<serde_json::Value>,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[activitystreams(concrete(String))]
|
||||
content: Option<serde_json::Value>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[serde(rename = "@context")]
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none", rename = "@context")]
|
||||
#[activitystreams(concrete(Value), functional)]
|
||||
context: Option<serde_json::Value>,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[activitystreams(concrete(String))]
|
||||
name: Option<serde_json::Value>,
|
||||
|
||||
// TODO: DateTime<Utc>
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[activitystreams(concrete(String), functional)]
|
||||
end_time: Option<serde_json::Value>,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
generator: Option<serde_json::Value>,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[activitystreams(ab(Link), concrete(Image))]
|
||||
icon: Option<serde_json::Value>,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[activitystreams(ab(Link), concrete(Image))]
|
||||
image: Option<serde_json::Value>,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
in_reply_to: Option<serde_json::Value>,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
location: Option<serde_json::Value>,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
preview: Option<serde_json::Value>,
|
||||
|
||||
// TODO: DateTime<Utc>
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[activitystreams(concrete(String), functional)]
|
||||
published: Option<serde_json::Value>,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[activitystreams(concrete(Collection), functional)]
|
||||
replies: Option<serde_json::Value>,
|
||||
|
||||
// TODO: DateTime<Utc>
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[activitystreams(concrete(String), functional)]
|
||||
start_time: Option<serde_json::Value>,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[activitystreams(concrete(String))]
|
||||
summary: Option<serde_json::Value>,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
tag: Option<serde_json::Value>,
|
||||
|
||||
// TODO: DateTime<Utc>
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[activitystreams(concrete(String), functional)]
|
||||
updated: Option<serde_json::Value>,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[activitystreams(concrete(String), ab(Link))]
|
||||
url: Option<serde_json::Value>,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
to: Option<serde_json::Value>,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
bto: Option<serde_json::Value>,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
cc: Option<serde_json::Value>,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
bcc: Option<serde_json::Value>,
|
||||
|
||||
// TODO: mime
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[activitystreams(concrete(String), functional)]
|
||||
media_type: Option<serde_json::Value>,
|
||||
|
||||
// TODO: xsd:duration
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[activitystreams(concrete(String), functional)]
|
||||
duration: Option<serde_json::Value>,
|
||||
}
|
||||
|
||||
impl Properties for ObjectProperties {}
|
||||
|
||||
impl ObjectProperties {
|
||||
pub fn id<D: DeserializeOwned>(&self) -> Result<D> {
|
||||
self.get_item(|props| &props.id)
|
||||
}
|
||||
|
||||
pub fn attachment<O: Object>(&self) -> Result<O> {
|
||||
self.get_item(|props| &props.attachment)
|
||||
}
|
||||
|
||||
pub fn attachments<O: Object>(&self) -> Result<Vec<O>> {
|
||||
self.get_item(|props| &props.attachment)
|
||||
}
|
||||
|
||||
pub fn attachment_link<L: Link>(&self) -> Result<L> {
|
||||
self.get_item(|props| &props.attachment)
|
||||
}
|
||||
|
||||
pub fn attachment_links<L: Link>(&self) -> Result<Vec<L>> {
|
||||
self.get_item(|props| &props.attachment)
|
||||
}
|
||||
|
||||
pub fn attributed_to<O: Object>(&self) -> Result<O> {
|
||||
self.get_item(|props| &props.attributed_to)
|
||||
}
|
||||
|
||||
pub fn attributed_tos<O: Object>(&self) -> Result<Vec<O>> {
|
||||
self.get_item(|props| &props.attributed_to)
|
||||
}
|
||||
|
||||
pub fn attributed_to_link<L: Link>(&self) -> Result<L> {
|
||||
self.get_item(|props| &props.attributed_to)
|
||||
}
|
||||
|
||||
pub fn attributed_to_links<L: Link>(&self) -> Result<Vec<L>> {
|
||||
self.get_item(|props| &props.attributed_to)
|
||||
}
|
||||
|
||||
pub fn audience<O: Object>(&self) -> Result<O> {
|
||||
self.get_item(|props| &props.audience)
|
||||
}
|
||||
|
||||
pub fn audiences<O: Object>(&self) -> Result<Vec<O>> {
|
||||
self.get_item(|props| &props.audience)
|
||||
}
|
||||
|
||||
pub fn audience_link<L: Link>(&self) -> Result<L> {
|
||||
self.get_item(|props| &props.audience)
|
||||
}
|
||||
|
||||
pub fn audience_links<L: Link>(&self) -> Result<Vec<L>> {
|
||||
self.get_item(|props| &props.audience)
|
||||
}
|
||||
|
||||
pub fn content(&self) -> Result<String> {
|
||||
self.get_item(|props| &props.content)
|
||||
}
|
||||
|
||||
pub fn contents(&self) -> Result<Vec<String>> {
|
||||
self.get_item(|props| &props.content)
|
||||
}
|
||||
|
||||
pub fn context(&self) -> Result<serde_json::Value> {
|
||||
self.context.clone().ok_or(Error::NotFound)
|
||||
}
|
||||
|
||||
pub fn name(&self) -> Result<String> {
|
||||
self.get_item(|props| &props.name)
|
||||
}
|
||||
|
||||
pub fn names(&self) -> Result<Vec<String>> {
|
||||
self.get_item(|props| &props.name)
|
||||
}
|
||||
|
||||
// TODO: DateTime<Utc>
|
||||
pub fn end_time(&self) -> Result<String> {
|
||||
self.get_item(|props| &props.end_time)
|
||||
}
|
||||
|
||||
pub fn generator<O: Object>(&self) -> Result<O> {
|
||||
self.get_item(|props| &props.generator)
|
||||
}
|
||||
|
||||
pub fn generators<O: Object>(&self) -> Result<Vec<O>> {
|
||||
self.get_item(|props| &props.generator)
|
||||
}
|
||||
|
||||
pub fn generator_link<L: Link>(&self) -> Result<L> {
|
||||
self.get_item(|props| &props.generator)
|
||||
}
|
||||
|
||||
pub fn generator_links<L: Link>(&self) -> Result<Vec<L>> {
|
||||
self.get_item(|props| &props.generator)
|
||||
}
|
||||
|
||||
pub fn icon(&self) -> Result<Image> {
|
||||
self.get_item(|props| &props.icon)
|
||||
}
|
||||
|
||||
pub fn icons(&self) -> Result<Vec<Image>> {
|
||||
self.get_item(|props| &props.icon)
|
||||
}
|
||||
|
||||
pub fn icon_link<L: Link>(&self) -> Result<L> {
|
||||
self.get_item(|props| &props.icon)
|
||||
}
|
||||
|
||||
pub fn icon_links<L: Link>(&self) -> Result<Vec<L>> {
|
||||
self.get_item(|props| &props.icon)
|
||||
}
|
||||
|
||||
pub fn image(&self) -> Result<Image> {
|
||||
self.get_item(|props| &props.image)
|
||||
}
|
||||
|
||||
pub fn images(&self) -> Result<Vec<Image>> {
|
||||
self.get_item(|props| &props.image)
|
||||
}
|
||||
|
||||
pub fn image_link<L: Link>(&self) -> Result<L> {
|
||||
self.get_item(|props| &props.image)
|
||||
}
|
||||
|
||||
pub fn image_links<L: Link>(&self) -> Result<Vec<L>> {
|
||||
self.get_item(|props| &props.image)
|
||||
}
|
||||
|
||||
pub fn in_reply_to<O: Object>(&self) -> Result<O> {
|
||||
self.get_item(|props| &props.in_reply_to)
|
||||
}
|
||||
|
||||
pub fn in_reply_tos<O: Object>(&self) -> Result<Vec<O>> {
|
||||
self.get_item(|props| &props.in_reply_to)
|
||||
}
|
||||
|
||||
pub fn in_reply_to_link<L: Link>(&self) -> Result<L> {
|
||||
self.get_item(|props| &props.in_reply_to)
|
||||
}
|
||||
|
||||
pub fn in_reply_to_links<L: Link>(&self) -> Result<Vec<L>> {
|
||||
self.get_item(|props| &props.in_reply_to)
|
||||
}
|
||||
|
||||
pub fn location<O: Object>(&self) -> Result<O> {
|
||||
self.get_item(|props| &props.location)
|
||||
}
|
||||
|
||||
pub fn locations<O: Object>(&self) -> Result<Vec<O>> {
|
||||
self.get_item(|props| &props.location)
|
||||
}
|
||||
|
||||
pub fn location_link<L: Link>(&self) -> Result<L> {
|
||||
self.get_item(|props| &props.location)
|
||||
}
|
||||
|
||||
pub fn location_links<L: Link>(&self) -> Result<Vec<L>> {
|
||||
self.get_item(|props| &props.location)
|
||||
}
|
||||
|
||||
pub fn preview<O: Object>(&self) -> Result<O> {
|
||||
self.get_item(|props| &props.preview)
|
||||
}
|
||||
|
||||
pub fn previews<O: Object>(&self) -> Result<Vec<O>> {
|
||||
self.get_item(|props| &props.preview)
|
||||
}
|
||||
|
||||
pub fn preview_link<L: Link>(&self) -> Result<L> {
|
||||
self.get_item(|props| &props.preview)
|
||||
}
|
||||
|
||||
pub fn preview_links<L: Link>(&self) -> Result<Vec<L>> {
|
||||
self.get_item(|props| &props.preview)
|
||||
}
|
||||
|
||||
// TODO: DateTime<Utc>
|
||||
pub fn published(&self) -> Result<String> {
|
||||
self.get_item(|props| &props.published)
|
||||
}
|
||||
|
||||
pub fn replies(&self) -> Result<Collection> {
|
||||
self.get_item(|props| &props.replies)
|
||||
}
|
||||
|
||||
// TODO: DateTime<Utc>
|
||||
pub fn start_time(&self) -> Result<String> {
|
||||
self.get_item(|props| &props.start_time)
|
||||
}
|
||||
|
||||
pub fn summary(&self) -> Result<String> {
|
||||
self.get_item(|props| &props.summary)
|
||||
}
|
||||
|
||||
pub fn summaries(&self) -> Result<Vec<String>> {
|
||||
self.get_item(|props| &props.summary)
|
||||
}
|
||||
|
||||
pub fn tag<O: Object>(&self) -> Result<O> {
|
||||
self.get_item(|props| &props.tag)
|
||||
}
|
||||
|
||||
pub fn tags<O: Object>(&self) -> Result<Vec<O>> {
|
||||
self.get_item(|props| &props.tag)
|
||||
}
|
||||
|
||||
pub fn tag_link<L: Link>(&self) -> Result<L> {
|
||||
self.get_item(|props| &props.tag)
|
||||
}
|
||||
|
||||
pub fn tag_links<L: Link>(&self) -> Result<Vec<L>> {
|
||||
self.get_item(|props| &props.tag)
|
||||
}
|
||||
|
||||
// TODO: DateTime<Utc>
|
||||
pub fn updated(&self) -> Result<String> {
|
||||
self.get_item(|props| &props.updated)
|
||||
}
|
||||
|
||||
pub fn url(&self) -> Result<String> {
|
||||
self.get_item(|props| &props.url)
|
||||
}
|
||||
|
||||
pub fn urls(&self) -> Result<Vec<String>> {
|
||||
self.get_item(|props| &props.url)
|
||||
}
|
||||
|
||||
pub fn url_link<L: Link>(&self) -> Result<L> {
|
||||
self.get_item(|props| &props.url)
|
||||
}
|
||||
|
||||
pub fn url_links<L: Link>(&self) -> Result<Vec<L>> {
|
||||
self.get_item(|props| &props.url)
|
||||
}
|
||||
|
||||
pub fn to<O: Object>(&self) -> Result<O> {
|
||||
self.get_item(|props| &props.to)
|
||||
}
|
||||
|
||||
pub fn tos<O: Object>(&self) -> Result<Vec<O>> {
|
||||
self.get_item(|props| &props.to)
|
||||
}
|
||||
|
||||
pub fn to_link<L: Link>(&self) -> Result<L> {
|
||||
self.get_item(|props| &props.to)
|
||||
}
|
||||
|
||||
pub fn to_links<L: Link>(&self) -> Result<Vec<L>> {
|
||||
self.get_item(|props| &props.to)
|
||||
}
|
||||
|
||||
pub fn bto<O: Object>(&self) -> Result<O> {
|
||||
self.get_item(|props| &props.bto)
|
||||
}
|
||||
|
||||
pub fn btos<O: Object>(&self) -> Result<Vec<O>> {
|
||||
self.get_item(|props| &props.bto)
|
||||
}
|
||||
|
||||
pub fn bto_link<L: Link>(&self) -> Result<L> {
|
||||
self.get_item(|props| &props.bto)
|
||||
}
|
||||
|
||||
pub fn bto_links<L: Link>(&self) -> Result<Vec<L>> {
|
||||
self.get_item(|props| &props.bto)
|
||||
}
|
||||
|
||||
pub fn cc<O: Object>(&self) -> Result<O> {
|
||||
self.get_item(|props| &props.cc)
|
||||
}
|
||||
|
||||
pub fn ccs<O: Object>(&self) -> Result<Vec<O>> {
|
||||
self.get_item(|props| &props.cc)
|
||||
}
|
||||
|
||||
pub fn cc_link<L: Link>(&self) -> Result<L> {
|
||||
self.get_item(|props| &props.cc)
|
||||
}
|
||||
|
||||
pub fn cc_links<L: Link>(&self) -> Result<Vec<L>> {
|
||||
self.get_item(|props| &props.cc)
|
||||
}
|
||||
|
||||
pub fn bcc<O: Object>(&self) -> Result<O> {
|
||||
self.get_item(|props| &props.bcc)
|
||||
}
|
||||
|
||||
pub fn bccs<O: Object>(&self) -> Result<Vec<O>> {
|
||||
self.get_item(|props| &props.bcc)
|
||||
}
|
||||
|
||||
pub fn bcc_link<L: Link>(&self) -> Result<L> {
|
||||
self.get_item(|props| &props.bcc)
|
||||
}
|
||||
|
||||
pub fn bcc_links<L: Link>(&self) -> Result<Vec<L>> {
|
||||
self.get_item(|props| &props.bcc)
|
||||
}
|
||||
|
||||
pub fn media_type(&self) -> Result<mime::Mime> {
|
||||
self.get_item::<_, String>(|props| &props.media_type)
|
||||
self.media_type_string()
|
||||
.and_then(|s| s.parse().map_err(|_| Error::Deserialize))
|
||||
}
|
||||
|
||||
// TODO: xsd:duration
|
||||
pub fn duration(&self) -> Result<String> {
|
||||
self.get_item(|props| &props.duration)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, Properties)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct PlaceProperties {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
accuracy: Option<f64>,
|
||||
#[activitystreams(concrete(f64), functional)]
|
||||
accuracy: Option<serde_json::Value>,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
altitude: Option<f64>,
|
||||
#[activitystreams(concrete(f64), functional)]
|
||||
altitude: Option<serde_json::Value>,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
latitude: Option<f64>,
|
||||
#[activitystreams(concrete(f64), functional)]
|
||||
latitude: Option<serde_json::Value>,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
longitude: Option<f64>,
|
||||
#[activitystreams(concrete(f64), functional)]
|
||||
longitude: Option<serde_json::Value>,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
radius: Option<f64>,
|
||||
#[activitystreams(concrete(f64), functional)]
|
||||
radius: Option<serde_json::Value>,
|
||||
}
|
||||
|
||||
impl PlaceProperties {
|
||||
pub fn accuracy(&self) -> Result<f64> {
|
||||
self.accuracy.ok_or(Error::NotFound)
|
||||
}
|
||||
|
||||
pub fn altitude(&self) -> Result<f64> {
|
||||
self.altitude.ok_or(Error::NotFound)
|
||||
}
|
||||
|
||||
pub fn latitude(&self) -> Result<f64> {
|
||||
self.latitude.ok_or(Error::NotFound)
|
||||
}
|
||||
|
||||
pub fn longitude(&self) -> Result<f64> {
|
||||
self.longitude.ok_or(Error::NotFound)
|
||||
}
|
||||
|
||||
pub fn radius(&self) -> Result<f64> {
|
||||
self.radius.ok_or(Error::NotFound)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, Properties)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct TombstoneProperties {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[activitystreams(concrete(String))]
|
||||
former_type: Option<serde_json::Value>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
deleted: Option<serde_json::Value>,
|
||||
}
|
||||
|
||||
impl Properties for TombstoneProperties {}
|
||||
|
||||
impl TombstoneProperties {
|
||||
pub fn former_type(&self) -> Result<String> {
|
||||
self.get_item(|t| &t.former_type)
|
||||
}
|
||||
|
||||
pub fn former_types(&self) -> Result<Vec<String>> {
|
||||
self.get_item(|t| &t.former_type)
|
||||
}
|
||||
|
||||
// TODO: DateTime<Utc>
|
||||
pub fn deleted(&self) -> Result<String> {
|
||||
self.get_item(|t| &t.deleted)
|
||||
}
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[activitystreams(concrete(String), functional)]
|
||||
deleted: Option<serde_json::Value>,
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue