write-out interface for points
This commit is contained in:
parent
770d3594e8
commit
cb18245de6
18
src/core.rs
18
src/core.rs
@ -89,13 +89,21 @@ pub trait Mentionable<'a, Ctx: 'a + Context>: 'a + Serializable {
|
||||
/// Used for walking over object trees to ensure two objects with different references don't collide.
|
||||
fn topology(&self) -> Hash {
|
||||
let mut vec = Vec::new();
|
||||
for point in self.points() {
|
||||
let mut points = Vec::new();
|
||||
self.points(&mut points);
|
||||
for point in points {
|
||||
vec.extend(point.point);
|
||||
}
|
||||
Ctx::hash(&vec)
|
||||
}
|
||||
/// References ([Point]s) to other objects.
|
||||
fn points(&self) -> Vec<Point<'a, Ctx, TypelessMentionable<'a, Ctx>>>;
|
||||
fn points(&self, points: &mut Vec<Point<'a, Ctx, TypelessMentionable<'a, Ctx>>>);
|
||||
|
||||
fn points_vec(&self) -> Vec<Point<'a, Ctx, TypelessMentionable<'a, Ctx>>> {
|
||||
let mut points = Vec::new();
|
||||
self.points(&mut points);
|
||||
points
|
||||
}
|
||||
}
|
||||
|
||||
/// Short-hand for the type of values returned by [`Resolver::resolve`].
|
||||
@ -273,8 +281,8 @@ impl<'a, Ctx: 'a + Context> Mentionable<'a, Ctx> for TypelessMentionable<'a, Ctx
|
||||
self.t_topology
|
||||
}
|
||||
|
||||
fn points(&self) -> Vec<Point<'a, Ctx, TypelessMentionable<'a, Ctx>>> {
|
||||
self.t_points.clone()
|
||||
fn points(&self, points: &mut Vec<Point<'a, Ctx, TypelessMentionable<'a, Ctx>>>) {
|
||||
points.extend(self.t_points.iter().map(Clone::clone));
|
||||
}
|
||||
}
|
||||
|
||||
@ -324,7 +332,7 @@ impl<'a, Ctx: 'a + Context> TypelessMentionable<'a, Ctx> {
|
||||
pub fn from_typed<A: Mentionable<'a, Ctx>>(mentionable: Rc<A>) -> Self {
|
||||
let factory = TypelessFactory::from_typed(mentionable.factory());
|
||||
let topology = mentionable.topology();
|
||||
let points = mentionable.points();
|
||||
let points = mentionable.points_vec();
|
||||
TypelessMentionable {
|
||||
t_serialize: Box::new(move |serializer| mentionable.serialize(serializer)),
|
||||
t_factory: factory,
|
||||
|
@ -127,8 +127,8 @@ impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Mentionable<'a, Ctx> for Po
|
||||
Ctx::hash(&self.point)
|
||||
}
|
||||
|
||||
fn points(&self) -> Vec<Point<'a, Ctx, TypelessMentionable<'a, Ctx>>> {
|
||||
vec![self.typeless()]
|
||||
fn points(&self, points: &mut Vec<Point<'a, Ctx, TypelessMentionable<'a, Ctx>>>) {
|
||||
points.push(self.typeless());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -43,9 +43,7 @@ impl<'a, Ctx: 'a + Context, A: Atomic> Mentionable<'a, Ctx> for AtomicObject<A>
|
||||
Ctx::hash(b"")
|
||||
}
|
||||
|
||||
fn points(&self) -> Vec<Point<'a, Ctx, TypelessMentionable<'a, Ctx>>> {
|
||||
vec![]
|
||||
}
|
||||
fn points(&self, _points: &mut Vec<Point<'a, Ctx, TypelessMentionable<'a, Ctx>>>) {}
|
||||
}
|
||||
|
||||
/// Generic implementation of a factory for [Atomic]s.
|
||||
@ -97,4 +95,3 @@ impl<A: Atomic> ExtAtomicObject for A {
|
||||
self.into()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -84,7 +84,7 @@ where
|
||||
|resolved| match resolved {
|
||||
Ok(mentionable) => {
|
||||
let resolver: Rc<dyn Resolver<'a, Ctx>> = Rc::new(CastResolver {
|
||||
points: mentionable.points(),
|
||||
points: mentionable.points_vec(),
|
||||
});
|
||||
Ok((mentionable.bytes(), resolver))
|
||||
}
|
||||
@ -111,7 +111,7 @@ where
|
||||
factory.parse_slice(
|
||||
&self.bytes(),
|
||||
Rc::new(CastResolver {
|
||||
points: self.points(),
|
||||
points: self.points_vec(),
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
@ -44,10 +44,9 @@ impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Mentionable<'a, Ctx>
|
||||
StackNodeFactory::new(self.element.factory())
|
||||
}
|
||||
|
||||
fn points(&self) -> Vec<Point<'a, Ctx, TypelessMentionable<'a, Ctx>>> {
|
||||
let mut points = self.rest.points();
|
||||
points.extend(self.element.points());
|
||||
points
|
||||
fn points(&self, points: &mut Vec<Point<'a, Ctx, TypelessMentionable<'a, Ctx>>>) {
|
||||
self.rest.points(points);
|
||||
self.element.points(points);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
pub mod static_pair;
|
||||
|
||||
use super::atomic::*;
|
||||
use super::atomic::atomic_object::*;
|
||||
use super::atomic::*;
|
||||
use crate::core::*;
|
||||
use crate::std::*;
|
||||
|
||||
|
@ -79,11 +79,10 @@ impl<'a, Ctx: 'a + Context, SP: StaticPair<'a, Ctx>> Mentionable<'a, Ctx> for St
|
||||
}
|
||||
}
|
||||
|
||||
fn points(&self) -> Vec<Point<'a, Ctx, TypelessMentionable<'a, Ctx>>> {
|
||||
fn points(&self, points: &mut Vec<Point<'a, Ctx, TypelessMentionable<'a, Ctx>>>) {
|
||||
let (a, b) = self.pair.elements();
|
||||
let mut vec = a.points();
|
||||
vec.extend(b.points());
|
||||
vec
|
||||
a.points(points);
|
||||
b.points(points);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -40,11 +40,11 @@ impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Mentionable<'a, Ctx> for Nu
|
||||
}
|
||||
}
|
||||
|
||||
fn points(&self) -> Vec<Point<'a, Ctx, TypelessMentionable<'a, Ctx>>> {
|
||||
fn points(&self, points: &mut Vec<Point<'a, Ctx, TypelessMentionable<'a, Ctx>>>) {
|
||||
match self {
|
||||
Nullable::Null(_) => vec![],
|
||||
Nullable::NotNull(point) => vec![point.typeless()],
|
||||
}
|
||||
Nullable::Null(_) => {}
|
||||
Nullable::NotNull(point) => points.push(point.typeless()),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user