so after a week off writing some stuff, I went back and realized I was going to have difficulty with my _extends
idea of squashing normal inheritance from an object oriented schema into Rust (ActivityStreams and ActivityPub)
I realized, though, that since I actually know all the possible children and their variants, it's actually trivial to basically reverse inheritance and just do it that way. So, rather than children storing their parent object, i.e:
so this, in a generic OO schema, was done as:
class Parent()
class Child: Parent()
as
struct Parent {
parent_field_1: Option<String>
}
struct Child {
child_field_1: Option<String>, // etc
_extends: Parent
}
followed by use of recursive getter/setter functions... I realized that this was going to be a problem because technically anything that accepted a type of
Object
from ActivityStreams really accepts anything that
inherits or extends from
Object
in some fashion. So I switched it around:
class Object {
id: Option<String>,
...
_child: ObjectInheritance
}
enum ObjectInheritance {
Actor {
actor_specific_field: Option<String>
},
Activity {
activity_specific_field: Option<String>
}
}
This simplifies a hell of a lot of things: deserialization, and by extension serialization, become very trivial by simply making use of flatten
and
untagged_enum
. Then I just write a
From
implementation that can handle all the different ActivityStreams types that inherit from Object.
Since all the children are set in an an enum, I can now just do basic matching against the enum variants to handle incoming payloads.
There's a lot to clean up still but I just basically just... I won't say the work I did before was worthless, because it wasn't to understand ActivityStreams, ActivityPub, and Rust a little better but.
#techPosting #activityStreams #activityPub #rustLang