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)
-
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:
asclass Parent() class Child: 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 ofstruct Parent { parent_field_1: Option<String> } struct Child { child_field_1: Option<String>, // etc _extends: Parent }
Object
from ActivityStreams really accepts anything that inherits or extends fromObject
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 offlatten
anduntagged_enum
. Then I just write aFrom
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 -
I realize now I'm basically inverting the computer science use of the term "tree" (which is usually written as a series of roots spawning) to be an actual fucking tree compared to how they'd usually implement it. Except I did actually implement a "root" instead of a tree.
fucking... names. -
@aud i tried OO a long time. But it was not the way to go in Java. I learned a lot. At the Ende i use RDF. My java classes are now wrappers around a graph. So internaly every property is an triple. And a java getter/setter knows the predicate Name. To access the graph.