ap: refactor super enums to use a macro
This commit is contained in:
parent
3d71b04338
commit
140aa9bd88
5 changed files with 108 additions and 536 deletions
|
@ -6,6 +6,39 @@ use crate::ap::trans::{
|
||||||
};
|
};
|
||||||
use crate::ap::vocab::apub;
|
use crate::ap::vocab::apub;
|
||||||
|
|
||||||
|
ap_super_enum! {
|
||||||
|
Activity,
|
||||||
|
|
||||||
|
Accept(Accept),
|
||||||
|
Add(Add),
|
||||||
|
Announce(Announce),
|
||||||
|
Arrive(Arrive),
|
||||||
|
Block(Block),
|
||||||
|
Create(Create),
|
||||||
|
Delete(Delete),
|
||||||
|
Dislike(Dislike),
|
||||||
|
Flag(Flag),
|
||||||
|
Follow(Follow),
|
||||||
|
Ignore(Ignore),
|
||||||
|
Invite(Invite),
|
||||||
|
Join(Join),
|
||||||
|
Leave(Leave),
|
||||||
|
Like(Like),
|
||||||
|
Listen(Listen),
|
||||||
|
Move(Move),
|
||||||
|
Offer(Offer),
|
||||||
|
Question(Question),
|
||||||
|
Reject(Reject),
|
||||||
|
Read(Read),
|
||||||
|
Remove(Remove),
|
||||||
|
TentativeReject(TentativeReject),
|
||||||
|
TentativeAccept(TentativeAccept),
|
||||||
|
Travel(Travel),
|
||||||
|
Undo(Undo),
|
||||||
|
Update(Update),
|
||||||
|
View(View),
|
||||||
|
}
|
||||||
|
|
||||||
pub struct AbstractActivity {
|
pub struct AbstractActivity {
|
||||||
_super: AbstractObject,
|
_super: AbstractObject,
|
||||||
pub actor: Vec<ApDocument>,
|
pub actor: Vec<ApDocument>,
|
||||||
|
@ -51,178 +84,6 @@ impl DebugApub for AbstractActivity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum Activity {
|
|
||||||
Accept(Accept),
|
|
||||||
Add(Add),
|
|
||||||
Announce(Announce),
|
|
||||||
Arrive(Arrive),
|
|
||||||
Block(Block),
|
|
||||||
Create(Create),
|
|
||||||
Delete(Delete),
|
|
||||||
Dislike(Dislike),
|
|
||||||
Flag(Flag),
|
|
||||||
Follow(Follow),
|
|
||||||
Ignore(Ignore),
|
|
||||||
Invite(Invite),
|
|
||||||
Join(Join),
|
|
||||||
Leave(Leave),
|
|
||||||
Like(Like),
|
|
||||||
Listen(Listen),
|
|
||||||
Move(Move),
|
|
||||||
Offer(Offer),
|
|
||||||
Question(Question),
|
|
||||||
Reject(Reject),
|
|
||||||
Read(Read),
|
|
||||||
Remove(Remove),
|
|
||||||
TentativeReject(TentativeReject),
|
|
||||||
TentativeAccept(TentativeAccept),
|
|
||||||
Travel(Travel),
|
|
||||||
Undo(Undo),
|
|
||||||
Update(Update),
|
|
||||||
View(View),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ParseApub for Activity {
|
|
||||||
fn parse_apub(obj: &RawObject) -> Option<Self> {
|
|
||||||
Accept::parse_apub(obj)
|
|
||||||
.map(Self::Accept)
|
|
||||||
.or_else(|| Add::parse_apub(obj).map(Self::Add))
|
|
||||||
.or_else(|| Announce::parse_apub(obj).map(Self::Announce))
|
|
||||||
.or_else(|| Arrive::parse_apub(obj).map(Self::Arrive))
|
|
||||||
.or_else(|| Block::parse_apub(obj).map(Self::Block))
|
|
||||||
.or_else(|| Create::parse_apub(obj).map(Self::Create))
|
|
||||||
.or_else(|| Delete::parse_apub(obj).map(Self::Delete))
|
|
||||||
.or_else(|| Dislike::parse_apub(obj).map(Self::Dislike))
|
|
||||||
.or_else(|| Flag::parse_apub(obj).map(Self::Flag))
|
|
||||||
.or_else(|| Follow::parse_apub(obj).map(Self::Follow))
|
|
||||||
.or_else(|| Ignore::parse_apub(obj).map(Self::Ignore))
|
|
||||||
.or_else(|| Invite::parse_apub(obj).map(Self::Invite))
|
|
||||||
.or_else(|| Join::parse_apub(obj).map(Self::Join))
|
|
||||||
.or_else(|| Leave::parse_apub(obj).map(Self::Leave))
|
|
||||||
.or_else(|| Like::parse_apub(obj).map(Self::Like))
|
|
||||||
.or_else(|| Listen::parse_apub(obj).map(Self::Listen))
|
|
||||||
.or_else(|| Move::parse_apub(obj).map(Self::Move))
|
|
||||||
.or_else(|| Offer::parse_apub(obj).map(Self::Offer))
|
|
||||||
.or_else(|| Question::parse_apub(obj).map(Self::Question))
|
|
||||||
.or_else(|| Reject::parse_apub(obj).map(Self::Reject))
|
|
||||||
.or_else(|| Read::parse_apub(obj).map(Self::Read))
|
|
||||||
.or_else(|| Remove::parse_apub(obj).map(Self::Remove))
|
|
||||||
.or_else(|| TentativeReject::parse_apub(obj).map(Self::TentativeReject))
|
|
||||||
.or_else(|| TentativeAccept::parse_apub(obj).map(Self::TentativeAccept))
|
|
||||||
.or_else(|| Travel::parse_apub(obj).map(Self::Travel))
|
|
||||||
.or_else(|| Undo::parse_apub(obj).map(Self::Undo))
|
|
||||||
.or_else(|| Update::parse_apub(obj).map(Self::Update))
|
|
||||||
.or_else(|| View::parse_apub(obj).map(Self::View))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl DebugApub for Activity {
|
|
||||||
fn apub_class_name(&self) -> &str {
|
|
||||||
use Activity::*;
|
|
||||||
|
|
||||||
match self {
|
|
||||||
Accept(a) => a.apub_class_name(),
|
|
||||||
Add(a) => a.apub_class_name(),
|
|
||||||
Announce(a) => a.apub_class_name(),
|
|
||||||
Arrive(a) => a.apub_class_name(),
|
|
||||||
Block(b) => b.apub_class_name(),
|
|
||||||
Create(c) => c.apub_class_name(),
|
|
||||||
Delete(d) => d.apub_class_name(),
|
|
||||||
Dislike(d) => d.apub_class_name(),
|
|
||||||
Flag(f) => f.apub_class_name(),
|
|
||||||
Follow(f) => f.apub_class_name(),
|
|
||||||
Ignore(i) => i.apub_class_name(),
|
|
||||||
Invite(i) => i.apub_class_name(),
|
|
||||||
Join(j) => j.apub_class_name(),
|
|
||||||
Leave(l) => l.apub_class_name(),
|
|
||||||
Like(l) => l.apub_class_name(),
|
|
||||||
Listen(l) => l.apub_class_name(),
|
|
||||||
Move(m) => m.apub_class_name(),
|
|
||||||
Offer(o) => o.apub_class_name(),
|
|
||||||
Question(q) => q.apub_class_name(),
|
|
||||||
Reject(r) => r.apub_class_name(),
|
|
||||||
Read(r) => r.apub_class_name(),
|
|
||||||
Remove(r) => r.apub_class_name(),
|
|
||||||
TentativeReject(t) => t.apub_class_name(),
|
|
||||||
TentativeAccept(t) => t.apub_class_name(),
|
|
||||||
Travel(t) => t.apub_class_name(),
|
|
||||||
Undo(u) => u.apub_class_name(),
|
|
||||||
Update(u) => u.apub_class_name(),
|
|
||||||
View(v) => v.apub_class_name(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn debug_apub(&self, f: &mut fmt::Formatter, depth: usize) -> fmt::Result {
|
|
||||||
use Activity::*;
|
|
||||||
|
|
||||||
match self {
|
|
||||||
Accept(a) => a.debug_apub(f, depth),
|
|
||||||
Add(a) => a.debug_apub(f, depth),
|
|
||||||
Announce(a) => a.debug_apub(f, depth),
|
|
||||||
Arrive(a) => a.debug_apub(f, depth),
|
|
||||||
Block(b) => b.debug_apub(f, depth),
|
|
||||||
Create(c) => c.debug_apub(f, depth),
|
|
||||||
Delete(d) => d.debug_apub(f, depth),
|
|
||||||
Dislike(d) => d.debug_apub(f, depth),
|
|
||||||
Flag(flag) => flag.debug_apub(f, depth),
|
|
||||||
Follow(follow) => follow.debug_apub(f, depth),
|
|
||||||
Ignore(i) => i.debug_apub(f, depth),
|
|
||||||
Invite(i) => i.debug_apub(f, depth),
|
|
||||||
Join(j) => j.debug_apub(f, depth),
|
|
||||||
Leave(l) => l.debug_apub(f, depth),
|
|
||||||
Like(l) => l.debug_apub(f, depth),
|
|
||||||
Listen(l) => l.debug_apub(f, depth),
|
|
||||||
Move(m) => m.debug_apub(f, depth),
|
|
||||||
Offer(o) => o.debug_apub(f, depth),
|
|
||||||
Question(q) => q.debug_apub(f, depth),
|
|
||||||
Reject(r) => r.debug_apub(f, depth),
|
|
||||||
Read(r) => r.debug_apub(f, depth),
|
|
||||||
Remove(r) => r.debug_apub(f, depth),
|
|
||||||
TentativeReject(t) => t.debug_apub(f, depth),
|
|
||||||
TentativeAccept(t) => t.debug_apub(f, depth),
|
|
||||||
Travel(t) => t.debug_apub(f, depth),
|
|
||||||
Undo(u) => u.debug_apub(f, depth),
|
|
||||||
Update(u) => u.debug_apub(f, depth),
|
|
||||||
View(v) => v.debug_apub(f, depth),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn debug_apub_members(&self, f: &mut fmt::Formatter, depth: usize) -> fmt::Result {
|
|
||||||
use Activity::*;
|
|
||||||
|
|
||||||
match self {
|
|
||||||
Accept(a) => a.debug_apub_members(f, depth),
|
|
||||||
Add(a) => a.debug_apub_members(f, depth),
|
|
||||||
Announce(a) => a.debug_apub_members(f, depth),
|
|
||||||
Arrive(a) => a.debug_apub_members(f, depth),
|
|
||||||
Block(b) => b.debug_apub_members(f, depth),
|
|
||||||
Create(c) => c.debug_apub_members(f, depth),
|
|
||||||
Delete(d) => d.debug_apub_members(f, depth),
|
|
||||||
Dislike(d) => d.debug_apub_members(f, depth),
|
|
||||||
Flag(flag) => flag.debug_apub_members(f, depth),
|
|
||||||
Follow(follow) => follow.debug_apub_members(f, depth),
|
|
||||||
Ignore(i) => i.debug_apub_members(f, depth),
|
|
||||||
Invite(i) => i.debug_apub_members(f, depth),
|
|
||||||
Join(j) => j.debug_apub_members(f, depth),
|
|
||||||
Leave(l) => l.debug_apub_members(f, depth),
|
|
||||||
Like(l) => l.debug_apub_members(f, depth),
|
|
||||||
Listen(l) => l.debug_apub_members(f, depth),
|
|
||||||
Move(m) => m.debug_apub_members(f, depth),
|
|
||||||
Offer(o) => o.debug_apub_members(f, depth),
|
|
||||||
Question(q) => q.debug_apub_members(f, depth),
|
|
||||||
Reject(r) => r.debug_apub_members(f, depth),
|
|
||||||
Read(r) => r.debug_apub_members(f, depth),
|
|
||||||
Remove(r) => r.debug_apub_members(f, depth),
|
|
||||||
TentativeReject(t) => t.debug_apub_members(f, depth),
|
|
||||||
TentativeAccept(t) => t.debug_apub_members(f, depth),
|
|
||||||
Travel(t) => t.debug_apub_members(f, depth),
|
|
||||||
Undo(u) => u.debug_apub_members(f, depth),
|
|
||||||
Update(u) => u.debug_apub_members(f, depth),
|
|
||||||
View(v) => v.debug_apub_members(f, depth),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct Question {
|
pub struct Question {
|
||||||
_super: AbstractActivity,
|
_super: AbstractActivity,
|
||||||
pub one_of: Vec<ApDocument>,
|
pub one_of: Vec<ApDocument>,
|
||||||
|
|
|
@ -1,9 +1,18 @@
|
||||||
use iref::IriBuf;
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
use crate::ap::trans::{AbstractObject, ApDocument, DebugApub, ParseApub, PropHelper, RawObject};
|
use crate::ap::trans::{AbstractObject, ApDocument, DebugApub, ParseApub, PropHelper, RawObject};
|
||||||
use crate::ap::vocab::{apub, toot, NyaIri};
|
use crate::ap::vocab::{apub, toot, NyaIri};
|
||||||
|
|
||||||
|
ap_super_enum! {
|
||||||
|
Actor,
|
||||||
|
|
||||||
|
Application(Application),
|
||||||
|
Group(Group),
|
||||||
|
Organization(Organization),
|
||||||
|
Person(Person),
|
||||||
|
Service(Service),
|
||||||
|
}
|
||||||
|
|
||||||
pub struct AbstractActor {
|
pub struct AbstractActor {
|
||||||
_super: AbstractObject,
|
_super: AbstractObject,
|
||||||
inbox: Option<NyaIri>,
|
inbox: Option<NyaIri>,
|
||||||
|
@ -61,60 +70,6 @@ impl DebugApub for AbstractActor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum Actor {
|
|
||||||
Application(Application),
|
|
||||||
Group(Group),
|
|
||||||
Organization(Organization),
|
|
||||||
Person(Person),
|
|
||||||
Service(Service),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ParseApub for Actor {
|
|
||||||
fn parse_apub(obj: &RawObject) -> Option<Self> {
|
|
||||||
Application::parse_apub(obj)
|
|
||||||
.map(Self::Application)
|
|
||||||
.or_else(|| Group::parse_apub(obj).map(Self::Group))
|
|
||||||
.or_else(|| Organization::parse_apub(obj).map(Self::Organization))
|
|
||||||
.or_else(|| Person::parse_apub(obj).map(Self::Person))
|
|
||||||
.or_else(|| Service::parse_apub(obj).map(Self::Service))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl DebugApub for Actor {
|
|
||||||
fn apub_class_name(&self) -> &str {
|
|
||||||
use Actor::*;
|
|
||||||
match self {
|
|
||||||
Application(a) => a.apub_class_name(),
|
|
||||||
Group(g) => g.apub_class_name(),
|
|
||||||
Organization(o) => o.apub_class_name(),
|
|
||||||
Person(p) => p.apub_class_name(),
|
|
||||||
Service(s) => s.apub_class_name(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn debug_apub(&self, f: &mut fmt::Formatter, depth: usize) -> fmt::Result {
|
|
||||||
use Actor::*;
|
|
||||||
match self {
|
|
||||||
Application(a) => a.debug_apub(f, depth),
|
|
||||||
Group(g) => g.debug_apub(f, depth),
|
|
||||||
Organization(o) => o.debug_apub(f, depth),
|
|
||||||
Person(p) => p.debug_apub(f, depth),
|
|
||||||
Service(s) => s.debug_apub(f, depth),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn debug_apub_members(&self, f: &mut fmt::Formatter, depth: usize) -> fmt::Result {
|
|
||||||
use Actor::*;
|
|
||||||
match self {
|
|
||||||
Application(a) => a.debug_apub_members(f, depth),
|
|
||||||
Group(g) => g.debug_apub_members(f, depth),
|
|
||||||
Organization(o) => o.debug_apub_members(f, depth),
|
|
||||||
Person(p) => p.debug_apub_members(f, depth),
|
|
||||||
Service(s) => s.debug_apub_members(f, depth),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ap_empty_child_impl!(Application, AbstractActor, apub::Application);
|
ap_empty_child_impl!(Application, AbstractActor, apub::Application);
|
||||||
ap_empty_child_impl!(Group, AbstractActor, apub::Group);
|
ap_empty_child_impl!(Group, AbstractActor, apub::Group);
|
||||||
ap_empty_child_impl!(Organization, AbstractActor, apub::Organization);
|
ap_empty_child_impl!(Organization, AbstractActor, apub::Organization);
|
||||||
|
|
|
@ -4,42 +4,13 @@ use std::fmt;
|
||||||
use crate::ap::trans::{matches_type, ApDocument, DebugApub, ParseApub, PropHelper, RawObject};
|
use crate::ap::trans::{matches_type, ApDocument, DebugApub, ParseApub, PropHelper, RawObject};
|
||||||
use crate::ap::vocab::{apub, NyaIri};
|
use crate::ap::vocab::{apub, NyaIri};
|
||||||
|
|
||||||
pub enum Link {
|
ap_super_enum! {
|
||||||
|
Link,
|
||||||
|
|
||||||
Link(BaseLink),
|
Link(BaseLink),
|
||||||
Mention(Mention),
|
Mention(Mention),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ParseApub for Link {
|
|
||||||
fn parse_apub(obj: &RawObject) -> Option<Self> {
|
|
||||||
BaseLink::parse_apub(obj)
|
|
||||||
.map(Self::Link)
|
|
||||||
.or_else(|| Mention::parse_apub(obj).map(Self::Mention))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl DebugApub for Link {
|
|
||||||
fn apub_class_name(&self) -> &str {
|
|
||||||
match self {
|
|
||||||
Link::Link(link) => link.apub_class_name(),
|
|
||||||
Link::Mention(mention) => mention.apub_class_name(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn debug_apub(&self, f: &mut fmt::Formatter, depth: usize) -> fmt::Result {
|
|
||||||
match self {
|
|
||||||
Link::Link(link) => link.debug_apub(f, depth),
|
|
||||||
Link::Mention(mention) => mention.debug_apub(f, depth),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn debug_apub_members(&self, f: &mut fmt::Formatter, depth: usize) -> fmt::Result {
|
|
||||||
match self {
|
|
||||||
Link::Link(link) => link.debug_apub_members(f, depth),
|
|
||||||
Link::Mention(mention) => mention.debug_apub_members(f, depth),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct BaseLink {
|
pub struct BaseLink {
|
||||||
pub id: Option<NyaIri>,
|
pub id: Option<NyaIri>,
|
||||||
pub href: Option<String>,
|
pub href: Option<String>,
|
||||||
|
|
|
@ -104,6 +104,53 @@ macro_rules! ap_empty_child_impl {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
macro_rules! ap_super_enum {
|
||||||
|
($name:ident, $memb1:ident($child1:ty), $($memb:ident($child:ty)),* $(,)?) => {
|
||||||
|
pub enum $name {
|
||||||
|
$memb1($child1),
|
||||||
|
$($memb($child),)*
|
||||||
|
}
|
||||||
|
|
||||||
|
impl $crate::ap::trans::ParseApub for $name {
|
||||||
|
fn parse_apub(obj: &$crate::ap::trans::RawObject) -> ::std::option::Option<Self> {
|
||||||
|
<$child1 as $crate::ap::trans::ParseApub>::parse_apub(obj).map(Self::$memb1)
|
||||||
|
$(.or_else(|| {
|
||||||
|
<$child as $crate::ap::trans::ParseApub>::parse_apub(obj).map(Self::$memb)
|
||||||
|
}))*
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl $crate::ap::trans::DebugApub for $name {
|
||||||
|
fn apub_class_name(&self) -> &str {
|
||||||
|
match self {
|
||||||
|
Self::$memb1(x) => $crate::ap::trans::DebugApub::apub_class_name(x),
|
||||||
|
$(Self::$memb(x) => $crate::ap::trans::DebugApub::apub_class_name(x),)*
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn debug_apub(&self, f: &mut ::std::fmt::Formatter, depth: usize) -> ::std::fmt::Result {
|
||||||
|
match self {
|
||||||
|
Self::$memb1(x) => $crate::ap::trans::DebugApub::debug_apub(x, f, depth),
|
||||||
|
$(Self::$memb(x) => $crate::ap::trans::DebugApub::debug_apub(x, f, depth),)*
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn debug_apub_members(&self, f: &mut ::std::fmt::Formatter, depth: usize) -> ::std::fmt::Result {
|
||||||
|
match self {
|
||||||
|
Self::$memb1(x) => $crate::ap::trans::DebugApub::debug_apub_members(x, f, depth),
|
||||||
|
$(Self::$memb(x) => $crate::ap::trans::DebugApub::debug_apub_members(x, f, depth),)*
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ::std::fmt::Debug for $name {
|
||||||
|
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
|
||||||
|
$crate::ap::trans::DebugApub::debug_apub(self, f, 0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
macro_rules! ap_display_prop {
|
macro_rules! ap_display_prop {
|
||||||
($this:expr, $f:ident, $name:ident, $depth:expr) => {
|
($this:expr, $f:ident, $name:ident, $depth:expr) => {
|
||||||
$crate::ap::trans::display_prop($f, stringify!($name), $this.$name.as_ref(), $depth)
|
$crate::ap::trans::display_prop($f, stringify!($name), $this.$name.as_ref(), $depth)
|
||||||
|
@ -134,138 +181,31 @@ pub use link::*;
|
||||||
mod object;
|
mod object;
|
||||||
pub use object::*;
|
pub use object::*;
|
||||||
|
|
||||||
/// The top-level type for any kind of object or link
|
// This is the top-level type for any kind of object or link
|
||||||
pub enum ApDocument {
|
ap_super_enum! {
|
||||||
|
ApDocument,
|
||||||
|
|
||||||
Object(Object),
|
Object(Object),
|
||||||
Link(Link),
|
Link(Link),
|
||||||
Remote(String),
|
Remote(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ParseApub for ApDocument {
|
ap_super_enum! {
|
||||||
fn parse_apub(obj: &RawObject) -> Option<Self> {
|
ImageOrLink,
|
||||||
if let Some(s) = obj.as_value().and_then(|v| v.as_str()) {
|
|
||||||
Some(Self::Remote(String::from(s)))
|
|
||||||
} else {
|
|
||||||
Object::parse_apub(obj)
|
|
||||||
.map(Self::Object)
|
|
||||||
.or_else(|| Link::parse_apub(obj).map(Self::Link))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl DebugApub for ApDocument {
|
|
||||||
fn apub_class_name(&self) -> &str {
|
|
||||||
use ApDocument::*;
|
|
||||||
match self {
|
|
||||||
Object(o) => o.apub_class_name(),
|
|
||||||
Link(l) => l.apub_class_name(),
|
|
||||||
Remote(_) => "<remote>",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn debug_apub(&self, f: &mut fmt::Formatter, depth: usize) -> fmt::Result {
|
|
||||||
use ApDocument::*;
|
|
||||||
match self {
|
|
||||||
Object(o) => o.debug_apub(f, depth),
|
|
||||||
Link(l) => l.debug_apub(f, depth),
|
|
||||||
Remote(url) => writeln!(f, "{}<remote> => {url}", indent(depth)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn debug_apub_members(&self, f: &mut fmt::Formatter, depth: usize) -> fmt::Result {
|
|
||||||
use ApDocument::*;
|
|
||||||
match self {
|
|
||||||
Object(o) => o.debug_apub_members(f, depth),
|
|
||||||
Link(l) => l.debug_apub_members(f, depth),
|
|
||||||
Remote(url) => writeln!(f, "{}<remote> => {url}", indent(depth)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Debug for ApDocument {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
||||||
self.debug_apub(f, 0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub enum ImageOrLink {
|
|
||||||
Link(Link),
|
Link(Link),
|
||||||
Image(Image),
|
Image(Image),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ParseApub for ImageOrLink {
|
ap_super_enum! {
|
||||||
fn parse_apub(obj: &RawObject) -> Option<Self> {
|
Collection,
|
||||||
Image::parse_apub(obj)
|
|
||||||
.map(Self::Image)
|
|
||||||
.or_else(|| Link::parse_apub(obj).map(Self::Link))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl DebugApub for ImageOrLink {
|
|
||||||
fn apub_class_name(&self) -> &str {
|
|
||||||
match self {
|
|
||||||
ImageOrLink::Link(link) => link.apub_class_name(),
|
|
||||||
ImageOrLink::Image(image) => image.apub_class_name(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn debug_apub_members(&self, f: &mut fmt::Formatter, depth: usize) -> fmt::Result {
|
|
||||||
match self {
|
|
||||||
ImageOrLink::Link(link) => link.debug_apub_members(f, depth),
|
|
||||||
ImageOrLink::Image(image) => image.debug_apub_members(f, depth),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub enum Collection {
|
|
||||||
Base(BaseCollection),
|
Base(BaseCollection),
|
||||||
Ordered(OrderedCollection),
|
Ordered(OrderedCollection),
|
||||||
Page(CollectionPage),
|
Page(CollectionPage),
|
||||||
OrderedPage(OrderedCollectionPage),
|
OrderedPage(OrderedCollectionPage),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ParseApub for Collection {
|
|
||||||
fn parse_apub(obj: &RawObject) -> Option<Self> {
|
|
||||||
BaseCollection::parse_apub(obj)
|
|
||||||
.map(Self::Base)
|
|
||||||
.or_else(|| OrderedCollection::parse_apub(obj).map(Self::Ordered))
|
|
||||||
.or_else(|| CollectionPage::parse_apub(obj).map(Self::Page))
|
|
||||||
.or_else(|| OrderedCollectionPage::parse_apub(obj).map(Self::OrderedPage))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl DebugApub for Collection {
|
|
||||||
fn apub_class_name(&self) -> &str {
|
|
||||||
use Collection::*;
|
|
||||||
match self {
|
|
||||||
Base(b) => b.apub_class_name(),
|
|
||||||
Ordered(o) => o.apub_class_name(),
|
|
||||||
Page(p) => p.apub_class_name(),
|
|
||||||
OrderedPage(o) => o.apub_class_name(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn debug_apub(&self, f: &mut fmt::Formatter, depth: usize) -> fmt::Result {
|
|
||||||
use Collection::*;
|
|
||||||
match self {
|
|
||||||
Base(b) => b.debug_apub(f, depth),
|
|
||||||
Ordered(o) => o.debug_apub(f, depth),
|
|
||||||
Page(p) => p.debug_apub(f, depth),
|
|
||||||
OrderedPage(o) => o.debug_apub(f, depth),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn debug_apub_members(&self, f: &mut fmt::Formatter, depth: usize) -> fmt::Result {
|
|
||||||
use Collection::*;
|
|
||||||
match self {
|
|
||||||
Base(b) => b.debug_apub_members(f, depth),
|
|
||||||
Ordered(o) => o.debug_apub_members(f, depth),
|
|
||||||
Page(p) => p.debug_apub_members(f, depth),
|
|
||||||
OrderedPage(o) => o.debug_apub_members(f, depth),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct BaseCollection {
|
pub struct BaseCollection {
|
||||||
_super: AbstractObject,
|
_super: AbstractObject,
|
||||||
pub total_items: Option<u32>,
|
pub total_items: Option<u32>,
|
||||||
|
@ -377,84 +317,20 @@ impl DebugApub for OrderedCollectionPage {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum CollectionOrLink {
|
ap_super_enum! {
|
||||||
|
CollectionOrLink,
|
||||||
|
|
||||||
Collection(Collection),
|
Collection(Collection),
|
||||||
Link(BaseLink),
|
Link(BaseLink),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ParseApub for CollectionOrLink {
|
ap_super_enum! {
|
||||||
fn parse_apub(obj: &RawObject) -> Option<Self> {
|
CollectionPageOrLink,
|
||||||
Collection::parse_apub(obj)
|
|
||||||
.map(Self::Collection)
|
|
||||||
.or_else(|| BaseLink::parse_apub(obj).map(Self::Link))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl DebugApub for CollectionOrLink {
|
|
||||||
fn apub_class_name(&self) -> &str {
|
|
||||||
use CollectionOrLink::*;
|
|
||||||
match self {
|
|
||||||
Collection(c) => c.apub_class_name(),
|
|
||||||
Link(l) => l.apub_class_name(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn debug_apub(&self, f: &mut fmt::Formatter, depth: usize) -> fmt::Result {
|
|
||||||
use CollectionOrLink::*;
|
|
||||||
match self {
|
|
||||||
Collection(c) => c.debug_apub(f, depth),
|
|
||||||
Link(l) => l.debug_apub(f, depth),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn debug_apub_members(&self, f: &mut fmt::Formatter, depth: usize) -> fmt::Result {
|
|
||||||
use CollectionOrLink::*;
|
|
||||||
match self {
|
|
||||||
Collection(c) => c.debug_apub_members(f, depth),
|
|
||||||
Link(l) => l.debug_apub_members(f, depth),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub enum CollectionPageOrLink {
|
|
||||||
CollectionPage(CollectionPage),
|
CollectionPage(CollectionPage),
|
||||||
Link(BaseLink),
|
Link(BaseLink),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ParseApub for CollectionPageOrLink {
|
|
||||||
fn parse_apub(obj: &RawObject) -> Option<Self> {
|
|
||||||
CollectionPage::parse_apub(obj)
|
|
||||||
.map(Self::CollectionPage)
|
|
||||||
.or_else(|| BaseLink::parse_apub(obj).map(Self::Link))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl DebugApub for CollectionPageOrLink {
|
|
||||||
fn apub_class_name(&self) -> &str {
|
|
||||||
use CollectionPageOrLink::*;
|
|
||||||
match self {
|
|
||||||
CollectionPage(c) => c.apub_class_name(),
|
|
||||||
Link(l) => l.apub_class_name(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn debug_apub(&self, f: &mut fmt::Formatter, depth: usize) -> fmt::Result {
|
|
||||||
use CollectionPageOrLink::*;
|
|
||||||
match self {
|
|
||||||
CollectionPage(c) => c.debug_apub(f, depth),
|
|
||||||
Link(l) => l.debug_apub(f, depth),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn debug_apub_members(&self, f: &mut fmt::Formatter, depth: usize) -> fmt::Result {
|
|
||||||
use CollectionPageOrLink::*;
|
|
||||||
match self {
|
|
||||||
CollectionPage(c) => c.debug_apub_members(f, depth),
|
|
||||||
Link(l) => l.debug_apub_members(f, depth),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ParseApub for IriBuf {
|
impl ParseApub for IriBuf {
|
||||||
fn parse_apub(obj: &RawObject) -> Option<Self> {
|
fn parse_apub(obj: &RawObject) -> Option<Self> {
|
||||||
obj.as_iri().map(|iri| iri.to_owned())
|
obj.as_iri().map(|iri| iri.to_owned())
|
||||||
|
|
|
@ -14,7 +14,8 @@ use crate::util::xsd;
|
||||||
// does not introduce any new properties, we simplify the class hierarchy by
|
// does not introduce any new properties, we simplify the class hierarchy by
|
||||||
// making all of the ones mentioned above direct subclasses of Object.
|
// making all of the ones mentioned above direct subclasses of Object.
|
||||||
|
|
||||||
pub enum Object {
|
ap_super_enum! {
|
||||||
|
Object,
|
||||||
Activity(activity::Activity),
|
Activity(activity::Activity),
|
||||||
Actor(actor::Actor),
|
Actor(actor::Actor),
|
||||||
Article(Article),
|
Article(Article),
|
||||||
|
@ -30,101 +31,9 @@ pub enum Object {
|
||||||
Tombstone(Tombstone),
|
Tombstone(Tombstone),
|
||||||
Video(Video),
|
Video(Video),
|
||||||
Collection(Collection),
|
Collection(Collection),
|
||||||
|
|
||||||
// ActivityPub draft, used by Mastodon
|
|
||||||
Emoji(Emoji),
|
Emoji(Emoji),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ParseApub for Object {
|
|
||||||
fn parse_apub(obj: &RawObject) -> Option<Self> {
|
|
||||||
activity::Activity::parse_apub(obj)
|
|
||||||
.map(Self::Activity)
|
|
||||||
.or_else(|| actor::Actor::parse_apub(obj).map(Self::Actor))
|
|
||||||
.or_else(|| Article::parse_apub(obj).map(Self::Article))
|
|
||||||
.or_else(|| Audio::parse_apub(obj).map(Self::Audio))
|
|
||||||
.or_else(|| Document::parse_apub(obj).map(Self::Document))
|
|
||||||
.or_else(|| Event::parse_apub(obj).map(Self::Event))
|
|
||||||
.or_else(|| Image::parse_apub(obj).map(Self::Image))
|
|
||||||
.or_else(|| Note::parse_apub(obj).map(Self::Note))
|
|
||||||
.or_else(|| Page::parse_apub(obj).map(Self::Page))
|
|
||||||
.or_else(|| Place::parse_apub(obj).map(Self::Place))
|
|
||||||
.or_else(|| Profile::parse_apub(obj).map(Self::Profile))
|
|
||||||
.or_else(|| Relationship::parse_apub(obj).map(Self::Relationship))
|
|
||||||
.or_else(|| Tombstone::parse_apub(obj).map(Self::Tombstone))
|
|
||||||
.or_else(|| Video::parse_apub(obj).map(Self::Video))
|
|
||||||
.or_else(|| Collection::parse_apub(obj).map(Self::Collection))
|
|
||||||
.or_else(|| Emoji::parse_apub(obj).map(Self::Emoji))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl DebugApub for Object {
|
|
||||||
fn apub_class_name(&self) -> &str {
|
|
||||||
use Object::*;
|
|
||||||
match self {
|
|
||||||
Activity(a) => a.apub_class_name(),
|
|
||||||
Actor(a) => a.apub_class_name(),
|
|
||||||
Article(a) => a.apub_class_name(),
|
|
||||||
Audio(a) => a.apub_class_name(),
|
|
||||||
Document(d) => d.apub_class_name(),
|
|
||||||
Event(e) => e.apub_class_name(),
|
|
||||||
Image(i) => i.apub_class_name(),
|
|
||||||
Note(n) => n.apub_class_name(),
|
|
||||||
Page(p) => p.apub_class_name(),
|
|
||||||
Place(p) => p.apub_class_name(),
|
|
||||||
Profile(p) => p.apub_class_name(),
|
|
||||||
Relationship(r) => r.apub_class_name(),
|
|
||||||
Tombstone(t) => t.apub_class_name(),
|
|
||||||
Video(v) => v.apub_class_name(),
|
|
||||||
Collection(c) => c.apub_class_name(),
|
|
||||||
Emoji(e) => e.apub_class_name(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn debug_apub(&self, f: &mut fmt::Formatter, depth: usize) -> fmt::Result {
|
|
||||||
use Object::*;
|
|
||||||
match self {
|
|
||||||
Activity(a) => a.debug_apub(f, depth),
|
|
||||||
Actor(a) => a.debug_apub(f, depth),
|
|
||||||
Article(a) => a.debug_apub(f, depth),
|
|
||||||
Audio(a) => a.debug_apub(f, depth),
|
|
||||||
Document(d) => d.debug_apub(f, depth),
|
|
||||||
Event(e) => e.debug_apub(f, depth),
|
|
||||||
Image(i) => i.debug_apub(f, depth),
|
|
||||||
Note(n) => n.debug_apub(f, depth),
|
|
||||||
Page(p) => p.debug_apub(f, depth),
|
|
||||||
Place(p) => p.debug_apub(f, depth),
|
|
||||||
Profile(p) => p.debug_apub(f, depth),
|
|
||||||
Relationship(r) => r.debug_apub(f, depth),
|
|
||||||
Tombstone(t) => t.debug_apub(f, depth),
|
|
||||||
Video(v) => v.debug_apub(f, depth),
|
|
||||||
Collection(c) => c.debug_apub(f, depth),
|
|
||||||
Emoji(e) => e.debug_apub(f, depth),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn debug_apub_members(&self, f: &mut fmt::Formatter, depth: usize) -> fmt::Result {
|
|
||||||
use Object::*;
|
|
||||||
match self {
|
|
||||||
Activity(a) => a.debug_apub_members(f, depth),
|
|
||||||
Actor(a) => a.debug_apub_members(f, depth),
|
|
||||||
Article(a) => a.debug_apub_members(f, depth),
|
|
||||||
Audio(a) => a.debug_apub_members(f, depth),
|
|
||||||
Document(d) => d.debug_apub_members(f, depth),
|
|
||||||
Event(e) => e.debug_apub_members(f, depth),
|
|
||||||
Image(i) => i.debug_apub_members(f, depth),
|
|
||||||
Note(n) => n.debug_apub_members(f, depth),
|
|
||||||
Page(p) => p.debug_apub_members(f, depth),
|
|
||||||
Place(p) => p.debug_apub_members(f, depth),
|
|
||||||
Profile(p) => p.debug_apub_members(f, depth),
|
|
||||||
Relationship(r) => r.debug_apub_members(f, depth),
|
|
||||||
Tombstone(t) => t.debug_apub_members(f, depth),
|
|
||||||
Video(v) => v.debug_apub_members(f, depth),
|
|
||||||
Collection(c) => c.debug_apub_members(f, depth),
|
|
||||||
Emoji(e) => e.debug_apub_members(f, depth),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct AbstractObject {
|
pub struct AbstractObject {
|
||||||
pub id: Option<NyaIri>,
|
pub id: Option<NyaIri>,
|
||||||
pub attachment: Vec<ApDocument>,
|
pub attachment: Vec<ApDocument>,
|
||||||
|
|
Loading…
Reference in a new issue