TakesPoints
-> PointsVisitor
This commit is contained in:
parent
ffd0cf6ec2
commit
4425b4c545
@ -33,7 +33,7 @@ pub use self::inctx::InCtx;
|
||||
pub use self::inlining::{Inlining, InliningExt, InliningResultExt};
|
||||
pub use self::origin::{OFctr, Origin};
|
||||
pub use self::point::Point;
|
||||
pub use self::points::TakesPoints;
|
||||
pub use self::points::PointsVisitor;
|
||||
pub use self::resolution::{
|
||||
Address, HashResolution, HashResolutionResult, LookupError, Resolution, ResolutionError,
|
||||
ResolutionFailure, ResolutionResult, Resolver, ResolverMap,
|
||||
@ -60,7 +60,7 @@ pub trait Mentionable<'a, Ctx: Context<'a>>: 'a + Serializable {
|
||||
Ctx::hash(&vec)
|
||||
}
|
||||
/// References ([Point]s) to other objects. Typed.
|
||||
fn points_typed(&self, points: &mut impl TakesPoints<'a, Ctx>);
|
||||
fn points_typed(&self, points: &mut impl PointsVisitor<'a, Ctx>);
|
||||
}
|
||||
|
||||
/// [`Factory`] associated with the [`Mentionable`]. Mostly useful for `type` definitions.
|
||||
|
@ -1,14 +1,14 @@
|
||||
use super::*;
|
||||
|
||||
/// Visitor used in [`Mentionable::points_typed`].
|
||||
pub trait TakesPoints<'a, Ctx: Context<'a>> {
|
||||
pub trait PointsVisitor<'a, Ctx: Context<'a>> {
|
||||
/// Visit a [Point].
|
||||
fn take<A: Mentionable<'a, Ctx>>(&mut self, point: &Point<'a, Ctx, A>);
|
||||
fn visit<A: Mentionable<'a, Ctx>>(&mut self, point: &Point<'a, Ctx, A>);
|
||||
}
|
||||
|
||||
impl<'a, Ctx: Context<'a>> TakesPoints<'a, Ctx> for Vec<u8> {
|
||||
impl<'a, Ctx: Context<'a>> PointsVisitor<'a, Ctx> for Vec<u8> {
|
||||
/// The only natural implementation, as used in [`Mentionable::topology`].
|
||||
fn take<A: Mentionable<'a, Ctx>>(&mut self, point: &Point<'a, Ctx, A>) {
|
||||
fn visit<A: Mentionable<'a, Ctx>>(&mut self, point: &Point<'a, Ctx, A>) {
|
||||
self.extend(point.point)
|
||||
}
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ impl<'a, Ctx: Context<'a>, A: Atomic> Mentionable<'a, Ctx> for AtomicObject<A> {
|
||||
Ctx::hash(b"")
|
||||
}
|
||||
|
||||
fn points_typed(&self, _points: &mut impl TakesPoints<'a, Ctx>) {}
|
||||
fn points_typed(&self, _points: &mut impl PointsVisitor<'a, Ctx>) {}
|
||||
}
|
||||
|
||||
/// Generic implementation of a [Factory] for [Atomic]s.
|
||||
|
@ -42,7 +42,7 @@ impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Mentionable<'a, Ctx> for Sta
|
||||
StackNodeFactory::new(self.element.factory())
|
||||
}
|
||||
|
||||
fn points_typed(&self, points: &mut impl TakesPoints<'a, Ctx>) {
|
||||
fn points_typed(&self, points: &mut impl PointsVisitor<'a, Ctx>) {
|
||||
self.rest.points_typed(points);
|
||||
self.element.points_typed(points);
|
||||
}
|
||||
|
@ -112,7 +112,7 @@ impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Mentionable<'a, Ctx> for Nod
|
||||
NodeFactory(self.key.factory())
|
||||
}
|
||||
|
||||
fn points_typed(&self, points: &mut impl TakesPoints<'a, Ctx>) {
|
||||
fn points_typed(&self, points: &mut impl PointsVisitor<'a, Ctx>) {
|
||||
self.l.points_typed(points);
|
||||
self.r.points_typed(points);
|
||||
self.key.points_typed(points);
|
||||
@ -126,7 +126,7 @@ impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Mentionable<'a, Ctx> for Tre
|
||||
TreeFactory(self.node.factory())
|
||||
}
|
||||
|
||||
fn points_typed(&self, points: &mut impl TakesPoints<'a, Ctx>) {
|
||||
fn points_typed(&self, points: &mut impl PointsVisitor<'a, Ctx>) {
|
||||
self.node.points_typed(points);
|
||||
}
|
||||
}
|
||||
|
@ -109,7 +109,7 @@ impl<'a, Ctx: Context<'a>, SP: StaticPair<'a, Ctx>> Mentionable<'a, Ctx> for Sta
|
||||
}
|
||||
}
|
||||
|
||||
fn points_typed(&self, points: &mut impl TakesPoints<'a, Ctx>) {
|
||||
fn points_typed(&self, points: &mut impl PointsVisitor<'a, Ctx>) {
|
||||
let (a, b) = self.pair.elements();
|
||||
a.points_typed(points);
|
||||
b.points_typed(points);
|
||||
|
@ -42,10 +42,10 @@ impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Mentionable<'a, Ctx> for Nul
|
||||
}
|
||||
}
|
||||
|
||||
fn points_typed(&self, points: &mut impl TakesPoints<'a, Ctx>) {
|
||||
fn points_typed(&self, points: &mut impl PointsVisitor<'a, Ctx>) {
|
||||
match self {
|
||||
Self::Null(_) => {}
|
||||
Self::NotNull(point) => points.take(point),
|
||||
Self::NotNull(point) => points.visit(point),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,8 +23,8 @@ impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Mentionable<'a, Ctx> for Poi
|
||||
Ctx::hash(&self.point)
|
||||
}
|
||||
|
||||
fn points_typed(&self, points: &mut impl TakesPoints<'a, Ctx>) {
|
||||
points.take(self)
|
||||
fn points_typed(&self, points: &mut impl PointsVisitor<'a, Ctx>) {
|
||||
points.visit(self)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -52,8 +52,8 @@ impl<'a, Ctx: Context<'a>> Resolver<'a, Ctx> for SingularResolver<'a, Ctx> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, Ctx: Context<'a>> TakesPoints<'a, Ctx> for Vec<Rc<dyn SingularResolution<'a, Ctx>>> {
|
||||
fn take<A: Mentionable<'a, Ctx>>(&mut self, point: &Point<'a, Ctx, A>) {
|
||||
impl<'a, Ctx: Context<'a>> PointsVisitor<'a, Ctx> for Vec<Rc<dyn SingularResolution<'a, Ctx>>> {
|
||||
fn visit<A: Mentionable<'a, Ctx>>(&mut self, point: &Point<'a, Ctx, A>) {
|
||||
self.push(Rc::new(point.clone()) as Rc<dyn SingularResolution<'a, Ctx>>);
|
||||
}
|
||||
}
|
||||
|
@ -59,9 +59,9 @@ impl<'a, Ctx: Context<'a>> Mentionable<'a, Ctx> for TypelessMentionable<'a, Ctx>
|
||||
self.t_topology
|
||||
}
|
||||
|
||||
fn points_typed(&self, points: &mut impl TakesPoints<'a, Ctx>) {
|
||||
fn points_typed(&self, points: &mut impl PointsVisitor<'a, Ctx>) {
|
||||
for point in self.t_points.iter() {
|
||||
points.take(point)
|
||||
points.visit(point)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -220,12 +220,12 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, Ctx: Context<'a>> TakesPoints<'a, Ctx>
|
||||
impl<'a, Ctx: Context<'a>> PointsVisitor<'a, Ctx>
|
||||
for Vec<Point<'a, Ctx, TypelessMentionable<'a, Ctx>>>
|
||||
where
|
||||
Ctx::LookupError: From<CastError<'a>>,
|
||||
{
|
||||
fn take<A: Mentionable<'a, Ctx>>(&mut self, point: &Point<'a, Ctx, A>) {
|
||||
fn visit<A: Mentionable<'a, Ctx>>(&mut self, point: &Point<'a, Ctx, A>) {
|
||||
self.push(point.typeless());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user