2020-05-14 03:54:50 +00:00
|
|
|
use crate::{
|
|
|
|
either::Either,
|
|
|
|
primitives::{
|
|
|
|
AnyString, MimeMediaType, OneOrMany, Unit, Unparsed, XsdAnyUri, XsdDateTime, XsdDuration,
|
2020-05-14 16:23:38 +00:00
|
|
|
XsdFloat, XsdString,
|
2020-05-14 03:54:50 +00:00
|
|
|
},
|
|
|
|
traits::{self, Extends, WithUnparsed, WithUnparsedExt},
|
|
|
|
};
|
|
|
|
use std::convert::TryFrom;
|
2020-05-14 16:23:38 +00:00
|
|
|
use typed_builder::TypedBuilder;
|
2020-05-14 03:54:50 +00:00
|
|
|
|
|
|
|
pub mod kind {
|
|
|
|
pub use activitystreams::object::kind::*;
|
|
|
|
}
|
|
|
|
|
|
|
|
use self::kind::*;
|
|
|
|
|
|
|
|
pub type Article = Object<ArticleType>;
|
|
|
|
pub type Audio = Object<AudioType>;
|
|
|
|
pub type Document = Object<DocumentType>;
|
|
|
|
pub type Event = Object<EventType>;
|
|
|
|
pub type Image = Object<ImageType>;
|
|
|
|
pub type Note = Object<NoteType>;
|
|
|
|
pub type Page = Object<PageType>;
|
|
|
|
pub type Video = Object<VideoType>;
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
|
|
|
|
#[serde(transparent)]
|
|
|
|
struct IdOrObject(Either<XsdAnyUri, Box<Object<serde_json::Value>>>);
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
|
|
|
|
#[serde(transparent)]
|
|
|
|
pub struct AnyObject(Either<IdOrObject, XsdString>);
|
|
|
|
|
2020-05-14 16:23:38 +00:00
|
|
|
#[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize, TypedBuilder)]
|
2020-05-14 03:54:50 +00:00
|
|
|
#[serde(rename_all = "camelCase")]
|
2020-05-14 16:23:38 +00:00
|
|
|
#[builder(doc)]
|
2020-05-14 03:54:50 +00:00
|
|
|
pub struct Object<Kind> {
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2020-05-14 16:23:38 +00:00
|
|
|
#[builder(default, setter(strip_option, into))]
|
2020-05-14 03:54:50 +00:00
|
|
|
pub context: Option<OneOrMany<AnyObject>>,
|
|
|
|
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2020-05-14 16:23:38 +00:00
|
|
|
#[builder(default, setter(strip_option, into))]
|
2020-05-14 03:54:50 +00:00
|
|
|
pub id: Option<AnyObject>,
|
|
|
|
|
|
|
|
#[serde(rename = "type")]
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2020-05-14 16:23:38 +00:00
|
|
|
#[builder(default, setter(strip_option))]
|
2020-05-14 03:54:50 +00:00
|
|
|
pub kind: Option<Kind>,
|
|
|
|
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2020-05-14 16:23:38 +00:00
|
|
|
#[builder(default, setter(strip_option, into))]
|
2020-05-14 03:54:50 +00:00
|
|
|
pub attachment: Option<OneOrMany<AnyObject>>,
|
|
|
|
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2020-05-14 16:23:38 +00:00
|
|
|
#[builder(default, setter(strip_option, into))]
|
2020-05-14 03:54:50 +00:00
|
|
|
pub attributed_to: Option<OneOrMany<AnyObject>>,
|
|
|
|
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2020-05-14 16:23:38 +00:00
|
|
|
#[builder(default, setter(strip_option, into))]
|
2020-05-14 03:54:50 +00:00
|
|
|
pub audience: Option<OneOrMany<AnyObject>>,
|
|
|
|
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2020-05-14 16:23:38 +00:00
|
|
|
#[builder(default, setter(strip_option, into))]
|
2020-05-14 03:54:50 +00:00
|
|
|
pub content: Option<OneOrMany<AnyString>>,
|
|
|
|
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2020-05-14 16:23:38 +00:00
|
|
|
#[builder(default, setter(strip_option, into))]
|
2020-05-14 03:54:50 +00:00
|
|
|
pub name: Option<OneOrMany<AnyString>>,
|
|
|
|
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2020-05-14 16:23:38 +00:00
|
|
|
#[builder(default, setter(strip_option, into))]
|
2020-05-14 03:54:50 +00:00
|
|
|
pub summary: Option<OneOrMany<AnyString>>,
|
|
|
|
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2020-05-14 16:23:38 +00:00
|
|
|
#[builder(default, setter(strip_option, into))]
|
2020-05-14 03:54:50 +00:00
|
|
|
pub url: Option<OneOrMany<AnyObject>>,
|
|
|
|
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2020-05-14 16:23:38 +00:00
|
|
|
#[builder(default, setter(strip_option))]
|
2020-05-14 03:54:50 +00:00
|
|
|
pub media_type: Option<MimeMediaType>,
|
|
|
|
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2020-05-14 16:23:38 +00:00
|
|
|
#[builder(default, setter(strip_option, into))]
|
2020-05-14 03:54:50 +00:00
|
|
|
pub generator: Option<OneOrMany<AnyObject>>,
|
|
|
|
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2020-05-14 16:23:38 +00:00
|
|
|
#[builder(default, setter(strip_option, into))]
|
2020-05-14 03:54:50 +00:00
|
|
|
pub image: Option<OneOrMany<AnyObject>>,
|
|
|
|
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2020-05-14 16:23:38 +00:00
|
|
|
#[builder(default, setter(strip_option, into))]
|
2020-05-14 03:54:50 +00:00
|
|
|
pub location: Option<OneOrMany<AnyObject>>,
|
|
|
|
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2020-05-14 16:23:38 +00:00
|
|
|
#[builder(default, setter(strip_option, into))]
|
2020-05-14 03:54:50 +00:00
|
|
|
pub preview: Option<OneOrMany<AnyObject>>,
|
|
|
|
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2020-05-14 16:23:38 +00:00
|
|
|
#[builder(default, setter(strip_option, into))]
|
2020-05-14 03:54:50 +00:00
|
|
|
pub start_time: Option<XsdDateTime>,
|
|
|
|
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2020-05-14 16:23:38 +00:00
|
|
|
#[builder(default, setter(strip_option, into))]
|
2020-05-14 03:54:50 +00:00
|
|
|
pub end_time: Option<XsdDateTime>,
|
|
|
|
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2020-05-14 16:23:38 +00:00
|
|
|
#[builder(default, setter(strip_option))]
|
2020-05-14 03:54:50 +00:00
|
|
|
pub duration: Option<XsdDuration>,
|
|
|
|
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2020-05-14 16:23:38 +00:00
|
|
|
#[builder(default, setter(strip_option, into))]
|
2020-05-14 03:54:50 +00:00
|
|
|
pub published: Option<XsdDateTime>,
|
|
|
|
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2020-05-14 16:23:38 +00:00
|
|
|
#[builder(default, setter(strip_option, into))]
|
2020-05-14 03:54:50 +00:00
|
|
|
pub updated: Option<XsdDateTime>,
|
|
|
|
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2020-05-14 16:23:38 +00:00
|
|
|
#[builder(default, setter(strip_option, into))]
|
2020-05-14 03:54:50 +00:00
|
|
|
pub in_reply_to: Option<OneOrMany<AnyObject>>,
|
|
|
|
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2020-05-14 16:23:38 +00:00
|
|
|
#[builder(default, setter(strip_option, into))]
|
2020-05-14 03:54:50 +00:00
|
|
|
pub replies: Option<OneOrMany<AnyObject>>,
|
|
|
|
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2020-05-14 16:23:38 +00:00
|
|
|
#[builder(default, setter(strip_option, into))]
|
2020-05-14 03:54:50 +00:00
|
|
|
pub to: Option<OneOrMany<AnyObject>>,
|
|
|
|
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2020-05-14 16:23:38 +00:00
|
|
|
#[builder(default, setter(strip_option, into))]
|
2020-05-14 03:54:50 +00:00
|
|
|
pub bto: Option<OneOrMany<AnyObject>>,
|
|
|
|
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2020-05-14 16:23:38 +00:00
|
|
|
#[builder(default, setter(strip_option, into))]
|
2020-05-14 03:54:50 +00:00
|
|
|
pub cc: Option<OneOrMany<AnyObject>>,
|
|
|
|
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2020-05-14 16:23:38 +00:00
|
|
|
#[builder(default, setter(strip_option, into))]
|
2020-05-14 03:54:50 +00:00
|
|
|
pub bcc: Option<OneOrMany<AnyObject>>,
|
|
|
|
|
|
|
|
#[serde(flatten)]
|
2020-05-14 16:23:38 +00:00
|
|
|
#[builder(default)]
|
2020-05-14 03:54:50 +00:00
|
|
|
pub unparsed: Unparsed,
|
|
|
|
}
|
|
|
|
|
2020-05-14 16:23:38 +00:00
|
|
|
#[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize, TypedBuilder)]
|
2020-05-14 03:54:50 +00:00
|
|
|
#[serde(rename_all = "camelCase")]
|
2020-05-14 16:23:38 +00:00
|
|
|
#[builder(doc)]
|
2020-05-14 03:54:50 +00:00
|
|
|
pub struct ApObject<Inner> {
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2020-05-14 16:23:38 +00:00
|
|
|
#[builder(default, setter(strip_option))]
|
2020-05-14 03:54:50 +00:00
|
|
|
pub shares: Option<XsdAnyUri>,
|
|
|
|
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2020-05-14 16:23:38 +00:00
|
|
|
#[builder(default, setter(strip_option))]
|
2020-05-14 03:54:50 +00:00
|
|
|
pub likes: Option<XsdAnyUri>,
|
|
|
|
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2020-05-14 16:23:38 +00:00
|
|
|
#[builder(default, setter(strip_option, into))]
|
2020-05-14 03:54:50 +00:00
|
|
|
pub source: Option<AnyObject>,
|
|
|
|
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2020-05-14 16:23:38 +00:00
|
|
|
#[builder(default, setter(strip_option, into))]
|
2020-05-14 03:54:50 +00:00
|
|
|
pub upload_media: Option<OneOrMany<XsdAnyUri>>,
|
|
|
|
|
|
|
|
#[serde(flatten)]
|
|
|
|
pub inner: Inner,
|
|
|
|
}
|
|
|
|
|
2020-05-14 16:23:38 +00:00
|
|
|
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize, TypedBuilder)]
|
|
|
|
#[builder(doc)]
|
2020-05-14 03:54:50 +00:00
|
|
|
pub struct Place {
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2020-05-14 16:23:38 +00:00
|
|
|
#[builder(default, setter(strip_option, into))]
|
|
|
|
pub accuracy: Option<XsdFloat>,
|
2020-05-14 03:54:50 +00:00
|
|
|
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2020-05-14 16:23:38 +00:00
|
|
|
#[builder(default, setter(strip_option, into))]
|
|
|
|
pub altitude: Option<XsdFloat>,
|
2020-05-14 03:54:50 +00:00
|
|
|
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2020-05-14 16:23:38 +00:00
|
|
|
#[builder(default, setter(strip_option, into))]
|
|
|
|
pub latitude: Option<XsdFloat>,
|
2020-05-14 03:54:50 +00:00
|
|
|
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2020-05-14 16:23:38 +00:00
|
|
|
#[builder(default, setter(strip_option, into))]
|
|
|
|
pub longitude: Option<XsdFloat>,
|
2020-05-14 03:54:50 +00:00
|
|
|
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2020-05-14 16:23:38 +00:00
|
|
|
#[builder(default, setter(strip_option, into))]
|
|
|
|
pub radius: Option<XsdFloat>,
|
2020-05-14 03:54:50 +00:00
|
|
|
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2020-05-14 16:23:38 +00:00
|
|
|
#[builder(default, setter(strip_option))]
|
2020-05-14 03:54:50 +00:00
|
|
|
pub units: Option<Unit>,
|
|
|
|
|
|
|
|
#[serde(flatten)]
|
|
|
|
pub inner: Object<PlaceType>,
|
|
|
|
}
|
|
|
|
|
2020-05-14 16:23:38 +00:00
|
|
|
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize, TypedBuilder)]
|
|
|
|
#[builder(doc)]
|
2020-05-14 03:54:50 +00:00
|
|
|
pub struct Profile {
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2020-05-14 16:23:38 +00:00
|
|
|
#[builder(default, setter(strip_option, into))]
|
2020-05-14 03:54:50 +00:00
|
|
|
pub describes: Option<AnyObject>,
|
|
|
|
|
|
|
|
#[serde(flatten)]
|
|
|
|
pub inner: Object<ProfileType>,
|
|
|
|
}
|
|
|
|
|
2020-05-14 16:23:38 +00:00
|
|
|
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize, TypedBuilder)]
|
|
|
|
#[builder(doc)]
|
2020-05-14 03:54:50 +00:00
|
|
|
pub struct Relationship {
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2020-05-14 16:23:38 +00:00
|
|
|
#[builder(default, setter(strip_option, into))]
|
2020-05-14 03:54:50 +00:00
|
|
|
pub subject: Option<AnyObject>,
|
|
|
|
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2020-05-14 16:23:38 +00:00
|
|
|
#[builder(default, setter(strip_option, into))]
|
2020-05-14 03:54:50 +00:00
|
|
|
pub object: Option<OneOrMany<AnyObject>>,
|
|
|
|
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2020-05-14 16:23:38 +00:00
|
|
|
#[builder(default, setter(strip_option, into))]
|
2020-05-14 03:54:50 +00:00
|
|
|
pub relationship: Option<OneOrMany<AnyObject>>,
|
|
|
|
|
|
|
|
#[serde(flatten)]
|
|
|
|
pub inner: Object<RelationshipType>,
|
|
|
|
}
|
|
|
|
|
2020-05-14 16:23:38 +00:00
|
|
|
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize, TypedBuilder)]
|
|
|
|
#[builder(doc)]
|
2020-05-14 03:54:50 +00:00
|
|
|
pub struct Tombstone {
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2020-05-14 16:23:38 +00:00
|
|
|
#[builder(default, setter(strip_option, into))]
|
2020-05-14 03:54:50 +00:00
|
|
|
pub former_type: Option<OneOrMany<AnyObject>>,
|
|
|
|
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2020-05-14 16:23:38 +00:00
|
|
|
#[builder(default, setter(strip_option, into))]
|
2020-05-14 03:54:50 +00:00
|
|
|
pub deleted: Option<XsdDateTime>,
|
|
|
|
|
|
|
|
#[serde(flatten)]
|
|
|
|
pub inner: Object<TombstoneType>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl AnyObject {
|
|
|
|
pub fn as_xsd_any_uri(&self) -> Option<&XsdAnyUri> {
|
|
|
|
self.0.as_ref().left().and_then(|l| l.as_xsd_any_uri())
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn as_xsd_string(&self) -> Option<&XsdString> {
|
|
|
|
self.0.as_ref().right()
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn as_object(&self) -> Option<&Object<serde_json::Value>> {
|
|
|
|
self.0.as_ref().left().and_then(|l| l.as_object())
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn id(self) -> Option<XsdAnyUri> {
|
|
|
|
self.0.left().and_then(|l| l.id())
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn xsd_string(self) -> Option<XsdString> {
|
|
|
|
self.0.right()
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn object(self) -> Option<Object<serde_json::Value>> {
|
|
|
|
self.0.left().and_then(|l| l.object())
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn set_xsd_any_uri(&mut self, id: XsdAnyUri) {
|
|
|
|
self.0 = Either::Left(IdOrObject::from_xsd_any_uri(id));
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn set_object(&mut self, object: Object<serde_json::Value>) {
|
|
|
|
self.0 = Either::Left(IdOrObject::from_object(object));
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn set_xsd_string(&mut self, xsd_string: XsdString) {
|
|
|
|
self.0 = Either::Right(xsd_string);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn from_xsd_any_uri(id: XsdAnyUri) -> Self {
|
|
|
|
AnyObject(Either::Left(IdOrObject::from_xsd_any_uri(id)))
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn from_object(object: Object<serde_json::Value>) -> Self {
|
|
|
|
AnyObject(Either::Left(IdOrObject::from_object(object)))
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn from_xsd_string(xsd_string: XsdString) -> Self {
|
|
|
|
AnyObject(Either::Right(xsd_string))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl IdOrObject {
|
|
|
|
fn as_xsd_any_uri(&self) -> Option<&XsdAnyUri> {
|
|
|
|
self.0.as_ref().left()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn as_object(&self) -> Option<&Object<serde_json::Value>> {
|
|
|
|
self.0.as_ref().right().map(|b| b.as_ref())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn id(self) -> Option<XsdAnyUri> {
|
|
|
|
self.0.left()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn object(self) -> Option<Object<serde_json::Value>> {
|
|
|
|
self.0.right().map(|b| *b)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn from_xsd_any_uri(id: XsdAnyUri) -> Self {
|
|
|
|
IdOrObject(Either::Left(id))
|
|
|
|
}
|
|
|
|
|
|
|
|
fn from_object(object: Object<serde_json::Value>) -> Self {
|
|
|
|
IdOrObject(Either::Right(Box::new(object)))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl OneOrMany<AnyObject> {
|
|
|
|
pub fn as_single_xsd_any_uri(&self) -> Option<&XsdAnyUri> {
|
|
|
|
self.as_one().and_then(|inner| inner.as_xsd_any_uri())
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn as_single_xsd_string(&self) -> Option<&XsdString> {
|
|
|
|
self.as_one().and_then(|inner| inner.as_xsd_string())
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn as_single_object(&self) -> Option<&Object<serde_json::Value>> {
|
|
|
|
self.as_one().and_then(|inner| inner.as_object())
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn single_xsd_any_uri(self) -> Option<XsdAnyUri> {
|
|
|
|
self.one().and_then(|inner| inner.id())
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn single_xsd_string(self) -> Option<XsdString> {
|
|
|
|
self.one().and_then(|inner| inner.xsd_string())
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn single_object(self) -> Option<Object<serde_json::Value>> {
|
|
|
|
self.one().and_then(|inner| inner.object())
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn from_xsd_any_uri(id: XsdAnyUri) -> Self {
|
|
|
|
OneOrMany(Either::Left(AnyObject::from_xsd_any_uri(id)))
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn from_xsd_string(xsd_string: XsdString) -> Self {
|
|
|
|
OneOrMany(Either::Left(AnyObject::from_xsd_string(xsd_string)))
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn from_object(object: Object<serde_json::Value>) -> Self {
|
|
|
|
OneOrMany(Either::Left(AnyObject::from_object(object)))
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn set_single_xsd_any_uri(&mut self, id: XsdAnyUri) -> &mut Self {
|
|
|
|
self.0 = Either::Left(AnyObject::from_xsd_any_uri(id));
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn set_single_xsd_string(&mut self, xsd_string: XsdString) -> &mut Self {
|
|
|
|
self.0 = Either::Left(AnyObject::from_xsd_string(xsd_string));
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn set_single_object(&mut self, object: Object<serde_json::Value>) -> &mut Self {
|
|
|
|
self.0 = Either::Left(AnyObject::from_object(object));
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn add_xsd_any_uri(&mut self, id: XsdAnyUri) -> &mut Self {
|
|
|
|
self.add(AnyObject::from_xsd_any_uri(id))
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn add_xsd_string(&mut self, xsd_string: XsdString) -> &mut Self {
|
|
|
|
self.add(AnyObject::from_xsd_string(xsd_string))
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn add_object(&mut self, object: Object<serde_json::Value>) -> &mut Self {
|
|
|
|
self.add(AnyObject::from_object(object))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Object<serde_json::Value> {
|
|
|
|
pub fn solidify<Kind>(self) -> Result<Object<Kind>, serde_json::Error>
|
|
|
|
where
|
|
|
|
Kind: serde::de::DeserializeOwned,
|
|
|
|
{
|
|
|
|
self.try_map_kind(serde_json::from_value)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<Kind> Object<Kind> {
|
2020-05-14 16:23:38 +00:00
|
|
|
fn extending(mut unparsed: Unparsed) -> Result<Self, serde_json::Error>
|
|
|
|
where
|
|
|
|
Kind: serde::de::DeserializeOwned,
|
|
|
|
{
|
|
|
|
Ok(Object {
|
|
|
|
kind: WithUnparsedExt::remove(&mut unparsed, "type")?,
|
|
|
|
context: WithUnparsedExt::remove(&mut unparsed, "context")?,
|
|
|
|
id: WithUnparsedExt::remove(&mut unparsed, "id")?,
|
|
|
|
attachment: WithUnparsedExt::remove(&mut unparsed, "attachment")?,
|
|
|
|
attributed_to: WithUnparsedExt::remove(&mut unparsed, "attributedTo")?,
|
|
|
|
audience: WithUnparsedExt::remove(&mut unparsed, "audience")?,
|
|
|
|
content: WithUnparsedExt::remove(&mut unparsed, "content")?,
|
|
|
|
name: WithUnparsedExt::remove(&mut unparsed, "name")?,
|
|
|
|
summary: WithUnparsedExt::remove(&mut unparsed, "summary")?,
|
|
|
|
url: WithUnparsedExt::remove(&mut unparsed, "url")?,
|
|
|
|
media_type: WithUnparsedExt::remove(&mut unparsed, "mediaType")?,
|
|
|
|
generator: WithUnparsedExt::remove(&mut unparsed, "generator")?,
|
|
|
|
image: WithUnparsedExt::remove(&mut unparsed, "image")?,
|
|
|
|
location: WithUnparsedExt::remove(&mut unparsed, "location")?,
|
|
|
|
preview: WithUnparsedExt::remove(&mut unparsed, "preview")?,
|
|
|
|
start_time: WithUnparsedExt::remove(&mut unparsed, "startTime")?,
|
|
|
|
end_time: WithUnparsedExt::remove(&mut unparsed, "endTime")?,
|
|
|
|
duration: WithUnparsedExt::remove(&mut unparsed, "duration")?,
|
|
|
|
published: WithUnparsedExt::remove(&mut unparsed, "published")?,
|
|
|
|
updated: WithUnparsedExt::remove(&mut unparsed, "updated")?,
|
|
|
|
in_reply_to: WithUnparsedExt::remove(&mut unparsed, "inReplyTo")?,
|
|
|
|
replies: WithUnparsedExt::remove(&mut unparsed, "replies")?,
|
|
|
|
to: WithUnparsedExt::remove(&mut unparsed, "to")?,
|
|
|
|
bto: WithUnparsedExt::remove(&mut unparsed, "bto")?,
|
|
|
|
cc: WithUnparsedExt::remove(&mut unparsed, "cc")?,
|
|
|
|
bcc: WithUnparsedExt::remove(&mut unparsed, "bcc")?,
|
|
|
|
unparsed,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
fn retracting(self) -> Result<Unparsed, serde_json::Error>
|
|
|
|
where
|
|
|
|
Kind: serde::ser::Serialize,
|
|
|
|
{
|
|
|
|
let Object {
|
|
|
|
kind,
|
|
|
|
context,
|
|
|
|
id,
|
|
|
|
attachment,
|
|
|
|
attributed_to,
|
|
|
|
audience,
|
|
|
|
content,
|
|
|
|
name,
|
|
|
|
summary,
|
|
|
|
url,
|
|
|
|
media_type,
|
|
|
|
generator,
|
|
|
|
image,
|
|
|
|
location,
|
|
|
|
preview,
|
|
|
|
start_time,
|
|
|
|
end_time,
|
|
|
|
duration,
|
|
|
|
published,
|
|
|
|
updated,
|
|
|
|
in_reply_to,
|
|
|
|
replies,
|
|
|
|
to,
|
|
|
|
bto,
|
|
|
|
cc,
|
|
|
|
bcc,
|
|
|
|
mut unparsed,
|
|
|
|
} = self;
|
|
|
|
|
|
|
|
WithUnparsedExt::insert(&mut unparsed, "type", kind)?;
|
|
|
|
WithUnparsedExt::insert(&mut unparsed, "context", context)?;
|
|
|
|
WithUnparsedExt::insert(&mut unparsed, "id", id)?;
|
|
|
|
WithUnparsedExt::insert(&mut unparsed, "attachment", attachment)?;
|
|
|
|
WithUnparsedExt::insert(&mut unparsed, "attributedTo", attributed_to)?;
|
|
|
|
WithUnparsedExt::insert(&mut unparsed, "audience", audience)?;
|
|
|
|
WithUnparsedExt::insert(&mut unparsed, "content", content)?;
|
|
|
|
WithUnparsedExt::insert(&mut unparsed, "name", name)?;
|
|
|
|
WithUnparsedExt::insert(&mut unparsed, "summary", summary)?;
|
|
|
|
WithUnparsedExt::insert(&mut unparsed, "url", url)?;
|
|
|
|
WithUnparsedExt::insert(&mut unparsed, "mediaType", media_type)?;
|
|
|
|
WithUnparsedExt::insert(&mut unparsed, "generator", generator)?;
|
|
|
|
WithUnparsedExt::insert(&mut unparsed, "image", image)?;
|
|
|
|
WithUnparsedExt::insert(&mut unparsed, "location", location)?;
|
|
|
|
WithUnparsedExt::insert(&mut unparsed, "preview", preview)?;
|
|
|
|
WithUnparsedExt::insert(&mut unparsed, "startTime", start_time)?;
|
|
|
|
WithUnparsedExt::insert(&mut unparsed, "endTime", end_time)?;
|
|
|
|
WithUnparsedExt::insert(&mut unparsed, "duration", duration)?;
|
|
|
|
WithUnparsedExt::insert(&mut unparsed, "published", published)?;
|
|
|
|
WithUnparsedExt::insert(&mut unparsed, "updated", updated)?;
|
|
|
|
WithUnparsedExt::insert(&mut unparsed, "inReplyTo", in_reply_to)?;
|
|
|
|
WithUnparsedExt::insert(&mut unparsed, "replies", replies)?;
|
|
|
|
WithUnparsedExt::insert(&mut unparsed, "to", to)?;
|
|
|
|
WithUnparsedExt::insert(&mut unparsed, "bto", bto)?;
|
|
|
|
WithUnparsedExt::insert(&mut unparsed, "cc", cc)?;
|
|
|
|
WithUnparsedExt::insert(&mut unparsed, "bcc", bcc)?;
|
|
|
|
|
|
|
|
Ok(unparsed)
|
|
|
|
}
|
|
|
|
|
2020-05-14 03:54:50 +00:00
|
|
|
pub fn into_generic(self) -> Result<Object<serde_json::Value>, serde_json::Error>
|
|
|
|
where
|
|
|
|
Kind: serde::ser::Serialize,
|
|
|
|
{
|
|
|
|
self.try_map_kind(serde_json::to_value)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn map_kind<NewKind>(self, f: impl Fn(Kind) -> NewKind) -> Object<NewKind> {
|
|
|
|
Object {
|
|
|
|
kind: self.kind.map(f),
|
|
|
|
context: self.context,
|
|
|
|
id: self.id,
|
|
|
|
attachment: self.attachment,
|
|
|
|
attributed_to: self.attributed_to,
|
|
|
|
audience: self.audience,
|
|
|
|
content: self.content,
|
|
|
|
name: self.name,
|
|
|
|
summary: self.summary,
|
|
|
|
url: self.url,
|
|
|
|
media_type: self.media_type,
|
|
|
|
generator: self.generator,
|
|
|
|
image: self.image,
|
|
|
|
location: self.location,
|
|
|
|
preview: self.preview,
|
|
|
|
start_time: self.start_time,
|
|
|
|
end_time: self.end_time,
|
|
|
|
duration: self.duration,
|
|
|
|
published: self.published,
|
|
|
|
updated: self.updated,
|
|
|
|
in_reply_to: self.in_reply_to,
|
|
|
|
replies: self.replies,
|
|
|
|
to: self.to,
|
|
|
|
bto: self.bto,
|
|
|
|
cc: self.cc,
|
|
|
|
bcc: self.bcc,
|
|
|
|
unparsed: self.unparsed,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn try_map_kind<NewKind, E>(
|
|
|
|
self,
|
|
|
|
f: impl Fn(Kind) -> Result<NewKind, E>,
|
|
|
|
) -> Result<Object<NewKind>, E> {
|
|
|
|
Ok(Object {
|
|
|
|
kind: if let Some(kind) = self.kind {
|
|
|
|
Some((f)(kind)?)
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
},
|
|
|
|
context: self.context,
|
|
|
|
id: self.id,
|
|
|
|
attachment: self.attachment,
|
|
|
|
attributed_to: self.attributed_to,
|
|
|
|
audience: self.audience,
|
|
|
|
content: self.content,
|
|
|
|
name: self.name,
|
|
|
|
summary: self.summary,
|
|
|
|
url: self.url,
|
|
|
|
media_type: self.media_type,
|
|
|
|
generator: self.generator,
|
|
|
|
image: self.image,
|
|
|
|
location: self.location,
|
|
|
|
preview: self.preview,
|
|
|
|
start_time: self.start_time,
|
|
|
|
end_time: self.end_time,
|
|
|
|
duration: self.duration,
|
|
|
|
published: self.published,
|
|
|
|
updated: self.updated,
|
|
|
|
in_reply_to: self.in_reply_to,
|
|
|
|
replies: self.replies,
|
|
|
|
to: self.to,
|
|
|
|
bto: self.bto,
|
|
|
|
cc: self.cc,
|
|
|
|
bcc: self.bcc,
|
|
|
|
unparsed: self.unparsed,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn extend<Extended>(self) -> Result<Extended, Extended::Error>
|
|
|
|
where
|
|
|
|
Extended: Extends<Self>,
|
|
|
|
{
|
|
|
|
Extended::extends(self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<Inner> ApObject<Inner> {
|
|
|
|
fn extending(mut inner: Inner) -> Result<Self, serde_json::Error>
|
|
|
|
where
|
|
|
|
Inner: WithUnparsed + traits::Object,
|
|
|
|
{
|
|
|
|
let shares = inner.remove("shares")?;
|
|
|
|
let likes = inner.remove("likes")?;
|
|
|
|
let source = inner.remove("source")?;
|
|
|
|
let upload_media = inner.remove("uploadMedia")?;
|
|
|
|
|
|
|
|
Ok(ApObject {
|
|
|
|
shares,
|
|
|
|
likes,
|
|
|
|
source,
|
|
|
|
upload_media,
|
|
|
|
inner,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
fn retracting(self) -> Result<Inner, serde_json::Error>
|
|
|
|
where
|
|
|
|
Inner: WithUnparsed + traits::Object,
|
|
|
|
{
|
|
|
|
let ApObject {
|
|
|
|
shares,
|
|
|
|
likes,
|
|
|
|
source,
|
|
|
|
upload_media,
|
|
|
|
mut inner,
|
|
|
|
} = self;
|
|
|
|
|
|
|
|
inner
|
|
|
|
.insert("uploadMedia", upload_media)?
|
|
|
|
.insert("source", source)?
|
|
|
|
.insert("likes", likes)?
|
|
|
|
.insert("shares", shares)?;
|
|
|
|
|
|
|
|
Ok(inner)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Place {
|
|
|
|
fn extending(mut inner: Object<PlaceType>) -> Result<Self, serde_json::Error> {
|
|
|
|
let accuracy = inner.remove("accuracy")?;
|
|
|
|
let altitude = inner.remove("altitude")?;
|
|
|
|
let latitude = inner.remove("latitude")?;
|
|
|
|
let longitude = inner.remove("longitude")?;
|
|
|
|
let radius = inner.remove("radius")?;
|
|
|
|
let units = inner.remove("units")?;
|
|
|
|
|
|
|
|
Ok(Place {
|
|
|
|
accuracy,
|
|
|
|
altitude,
|
|
|
|
latitude,
|
|
|
|
longitude,
|
|
|
|
radius,
|
|
|
|
units,
|
|
|
|
inner,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
fn retracting(self) -> Result<Object<PlaceType>, serde_json::Error> {
|
|
|
|
let Place {
|
|
|
|
accuracy,
|
|
|
|
altitude,
|
|
|
|
latitude,
|
|
|
|
longitude,
|
|
|
|
radius,
|
|
|
|
units,
|
|
|
|
mut inner,
|
|
|
|
} = self;
|
|
|
|
|
|
|
|
inner
|
|
|
|
.insert("units", units)?
|
|
|
|
.insert("radius", radius)?
|
|
|
|
.insert("longitude", longitude)?
|
|
|
|
.insert("latitude", latitude)?
|
|
|
|
.insert("altitude", altitude)?
|
|
|
|
.insert("accuracy", accuracy)?;
|
|
|
|
|
|
|
|
Ok(inner)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Profile {
|
|
|
|
fn extending(mut inner: Object<ProfileType>) -> Result<Self, serde_json::Error> {
|
|
|
|
let describes = inner.remove("describes")?;
|
|
|
|
|
|
|
|
Ok(Profile { describes, inner })
|
|
|
|
}
|
|
|
|
|
|
|
|
fn retracting(self) -> Result<Object<ProfileType>, serde_json::Error> {
|
|
|
|
let Profile {
|
|
|
|
describes,
|
|
|
|
mut inner,
|
|
|
|
} = self;
|
|
|
|
|
|
|
|
inner.insert("describes", describes)?;
|
|
|
|
Ok(inner)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Relationship {
|
|
|
|
fn extending(mut inner: Object<RelationshipType>) -> Result<Self, serde_json::Error> {
|
|
|
|
let subject = inner.remove("subject")?;
|
|
|
|
let object = inner.remove("object")?;
|
|
|
|
let relationship = inner.remove("relationship")?;
|
|
|
|
|
|
|
|
Ok(Relationship {
|
|
|
|
subject,
|
|
|
|
object,
|
|
|
|
relationship,
|
|
|
|
inner,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
fn retracting(self) -> Result<Object<RelationshipType>, serde_json::Error> {
|
|
|
|
let Relationship {
|
|
|
|
subject,
|
|
|
|
object,
|
|
|
|
relationship,
|
|
|
|
mut inner,
|
|
|
|
} = self;
|
|
|
|
|
|
|
|
inner
|
|
|
|
.insert("subject", subject)?
|
|
|
|
.insert("object", object)?
|
|
|
|
.insert("relationship", relationship)?;
|
|
|
|
|
|
|
|
Ok(inner)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Tombstone {
|
|
|
|
fn extending(mut inner: Object<TombstoneType>) -> Result<Self, serde_json::Error> {
|
|
|
|
let former_type = inner.remove("formerType")?;
|
|
|
|
let deleted = inner.remove("deleted")?;
|
|
|
|
|
|
|
|
Ok(Tombstone {
|
|
|
|
former_type,
|
|
|
|
deleted,
|
|
|
|
inner,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
fn retracting(self) -> Result<Object<TombstoneType>, serde_json::Error> {
|
|
|
|
let Tombstone {
|
|
|
|
former_type,
|
|
|
|
deleted,
|
|
|
|
mut inner,
|
|
|
|
} = self;
|
|
|
|
|
|
|
|
inner
|
|
|
|
.insert("formerType", former_type)?
|
|
|
|
.insert("deleted", deleted)?;
|
|
|
|
|
|
|
|
Ok(inner)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<Kind> traits::Base for Object<Kind> where Kind: std::fmt::Debug {}
|
|
|
|
impl<Kind> traits::Object for Object<Kind> where Kind: std::fmt::Debug {}
|
|
|
|
|
|
|
|
impl<Inner> traits::Base for ApObject<Inner> where Inner: traits::Base {}
|
|
|
|
impl<Inner> traits::Object for ApObject<Inner> where Inner: traits::Object {}
|
|
|
|
|
|
|
|
impl traits::Base for Place {}
|
|
|
|
impl traits::Object for Place {}
|
|
|
|
|
|
|
|
impl traits::Base for Profile {}
|
|
|
|
impl traits::Object for Profile {}
|
|
|
|
|
|
|
|
impl traits::Base for Relationship {}
|
|
|
|
impl traits::Object for Relationship {}
|
|
|
|
|
|
|
|
impl traits::Base for Tombstone {}
|
|
|
|
impl traits::Object for Tombstone {}
|
|
|
|
|
2020-05-14 16:23:38 +00:00
|
|
|
impl<Kind> Extends<Unparsed> for Object<Kind>
|
|
|
|
where
|
|
|
|
Kind: serde::de::DeserializeOwned + serde::ser::Serialize,
|
|
|
|
{
|
|
|
|
type Error = serde_json::Error;
|
|
|
|
|
|
|
|
fn extends(unparsed: Unparsed) -> Result<Self, Self::Error> {
|
|
|
|
Self::extending(unparsed)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn retracts(self) -> Result<Unparsed, Self::Error> {
|
|
|
|
self.retracting()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<Kind> TryFrom<Unparsed> for Object<Kind>
|
|
|
|
where
|
|
|
|
Kind: serde::de::DeserializeOwned,
|
|
|
|
{
|
|
|
|
type Error = serde_json::Error;
|
|
|
|
|
|
|
|
fn try_from(unparsed: Unparsed) -> Result<Self, Self::Error> {
|
|
|
|
Self::extending(unparsed)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<Kind> TryFrom<Object<Kind>> for Unparsed
|
|
|
|
where
|
|
|
|
Kind: serde::ser::Serialize,
|
|
|
|
{
|
|
|
|
type Error = serde_json::Error;
|
|
|
|
|
|
|
|
fn try_from(object: Object<Kind>) -> Result<Self, Self::Error> {
|
|
|
|
object.retracting()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-14 03:54:50 +00:00
|
|
|
impl<Inner> Extends<Inner> for ApObject<Inner>
|
|
|
|
where
|
|
|
|
Inner: WithUnparsed + traits::Object,
|
|
|
|
{
|
|
|
|
type Error = serde_json::Error;
|
|
|
|
|
|
|
|
fn extends(inner: Inner) -> Result<Self, Self::Error> {
|
|
|
|
Self::extending(inner)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn retracts(self) -> Result<Inner, Self::Error> {
|
|
|
|
self.retracting()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Extends<Object<PlaceType>> for Place {
|
|
|
|
type Error = serde_json::Error;
|
|
|
|
|
|
|
|
fn extends(object: Object<PlaceType>) -> Result<Self, Self::Error> {
|
|
|
|
Self::extending(object)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn retracts(self) -> Result<Object<PlaceType>, Self::Error> {
|
|
|
|
self.retracting()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl TryFrom<Object<PlaceType>> for Place {
|
|
|
|
type Error = serde_json::Error;
|
|
|
|
|
|
|
|
fn try_from(object: Object<PlaceType>) -> Result<Self, Self::Error> {
|
|
|
|
Self::extending(object)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-14 16:23:38 +00:00
|
|
|
impl TryFrom<Place> for Object<PlaceType> {
|
|
|
|
type Error = serde_json::Error;
|
|
|
|
|
|
|
|
fn try_from(place: Place) -> Result<Self, Self::Error> {
|
|
|
|
place.retracting()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-14 03:54:50 +00:00
|
|
|
impl Extends<Object<ProfileType>> for Profile {
|
|
|
|
type Error = serde_json::Error;
|
|
|
|
|
|
|
|
fn extends(object: Object<ProfileType>) -> Result<Self, Self::Error> {
|
|
|
|
Self::extending(object)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn retracts(self) -> Result<Object<ProfileType>, Self::Error> {
|
|
|
|
self.retracting()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl TryFrom<Object<ProfileType>> for Profile {
|
|
|
|
type Error = serde_json::Error;
|
|
|
|
|
|
|
|
fn try_from(object: Object<ProfileType>) -> Result<Self, Self::Error> {
|
|
|
|
Self::extending(object)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-14 16:23:38 +00:00
|
|
|
impl TryFrom<Profile> for Object<ProfileType> {
|
|
|
|
type Error = serde_json::Error;
|
|
|
|
|
|
|
|
fn try_from(profile: Profile) -> Result<Self, Self::Error> {
|
|
|
|
profile.retracting()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-14 03:54:50 +00:00
|
|
|
impl Extends<Object<RelationshipType>> for Relationship {
|
|
|
|
type Error = serde_json::Error;
|
|
|
|
|
|
|
|
fn extends(object: Object<RelationshipType>) -> Result<Self, Self::Error> {
|
|
|
|
Self::extending(object)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn retracts(self) -> Result<Object<RelationshipType>, Self::Error> {
|
|
|
|
self.retracting()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl TryFrom<Object<RelationshipType>> for Relationship {
|
|
|
|
type Error = serde_json::Error;
|
|
|
|
|
|
|
|
fn try_from(object: Object<RelationshipType>) -> Result<Self, Self::Error> {
|
|
|
|
Self::extending(object)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-14 16:23:38 +00:00
|
|
|
impl TryFrom<Relationship> for Object<RelationshipType> {
|
|
|
|
type Error = serde_json::Error;
|
|
|
|
|
|
|
|
fn try_from(relationship: Relationship) -> Result<Self, Self::Error> {
|
|
|
|
relationship.retracting()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-14 03:54:50 +00:00
|
|
|
impl Extends<Object<TombstoneType>> for Tombstone {
|
|
|
|
type Error = serde_json::Error;
|
|
|
|
|
|
|
|
fn extends(object: Object<TombstoneType>) -> Result<Self, Self::Error> {
|
|
|
|
Self::extending(object)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn retracts(self) -> Result<Object<TombstoneType>, Self::Error> {
|
|
|
|
self.retracting()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl TryFrom<Object<TombstoneType>> for Tombstone {
|
|
|
|
type Error = serde_json::Error;
|
|
|
|
|
|
|
|
fn try_from(object: Object<TombstoneType>) -> Result<Self, Self::Error> {
|
|
|
|
Self::extending(object)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-14 16:23:38 +00:00
|
|
|
impl TryFrom<Tombstone> for Object<TombstoneType> {
|
|
|
|
type Error = serde_json::Error;
|
|
|
|
|
|
|
|
fn try_from(tombstone: Tombstone) -> Result<Self, Self::Error> {
|
|
|
|
tombstone.retracting()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-14 03:54:50 +00:00
|
|
|
impl<Kind> WithUnparsed for Object<Kind> {
|
|
|
|
fn unparsed(&self) -> &Unparsed {
|
|
|
|
&self.unparsed
|
|
|
|
}
|
|
|
|
|
|
|
|
fn unparsed_mut(&mut self) -> &mut Unparsed {
|
|
|
|
&mut self.unparsed
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<Inner> WithUnparsed for ApObject<Inner>
|
|
|
|
where
|
|
|
|
Inner: WithUnparsed,
|
|
|
|
{
|
|
|
|
fn unparsed(&self) -> &Unparsed {
|
|
|
|
self.inner.unparsed()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn unparsed_mut(&mut self) -> &mut Unparsed {
|
|
|
|
self.inner.unparsed_mut()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl WithUnparsed for Place {
|
|
|
|
fn unparsed(&self) -> &Unparsed {
|
|
|
|
self.inner.unparsed()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn unparsed_mut(&mut self) -> &mut Unparsed {
|
|
|
|
self.inner.unparsed_mut()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl WithUnparsed for Profile {
|
|
|
|
fn unparsed(&self) -> &Unparsed {
|
|
|
|
self.inner.unparsed()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn unparsed_mut(&mut self) -> &mut Unparsed {
|
|
|
|
self.inner.unparsed_mut()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl WithUnparsed for Relationship {
|
|
|
|
fn unparsed(&self) -> &Unparsed {
|
|
|
|
self.inner.unparsed()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn unparsed_mut(&mut self) -> &mut Unparsed {
|
|
|
|
self.inner.unparsed_mut()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl WithUnparsed for Tombstone {
|
|
|
|
fn unparsed(&self) -> &Unparsed {
|
|
|
|
self.inner.unparsed()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn unparsed_mut(&mut self) -> &mut Unparsed {
|
|
|
|
self.inner.unparsed_mut()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<Object<serde_json::Value>> for AnyObject {
|
|
|
|
fn from(o: Object<serde_json::Value>) -> Self {
|
|
|
|
Self::from_object(o)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<XsdAnyUri> for AnyObject {
|
|
|
|
fn from(id: XsdAnyUri) -> Self {
|
|
|
|
Self::from_xsd_any_uri(id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<XsdString> for AnyObject {
|
|
|
|
fn from(xsd_string: XsdString) -> Self {
|
|
|
|
Self::from_xsd_string(xsd_string)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<Object<serde_json::Value>> for OneOrMany<AnyObject> {
|
|
|
|
fn from(object: Object<serde_json::Value>) -> Self {
|
|
|
|
Self::from_object(object)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<XsdAnyUri> for OneOrMany<AnyObject> {
|
|
|
|
fn from(xsd_any_uri: XsdAnyUri) -> Self {
|
|
|
|
Self::from_xsd_any_uri(xsd_any_uri)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<XsdString> for OneOrMany<AnyObject> {
|
|
|
|
fn from(xsd_string: XsdString) -> Self {
|
|
|
|
Self::from_xsd_string(xsd_string)
|
|
|
|
}
|
|
|
|
}
|