From 8410d6ad7f410e3cb68fe39deae4378106d1b57e Mon Sep 17 00:00:00 2001 From: timofey Date: Sun, 7 May 2023 17:04:47 +0000 Subject: [PATCH] detached `std::{typeless,cast}` from `points` --- src/std/cast.rs | 4 ++-- src/std/typeless.rs | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/std/cast.rs b/src/std/cast.rs index 2e61363..c223c60 100644 --- a/src/std/cast.rs +++ b/src/std/cast.rs @@ -87,7 +87,7 @@ where |resolved| match resolved { Ok(mentionable) => { let resolver: Rc> = Rc::new(CastResolver { - points: mentionable.points_vec(), + points: mentionable.points_vec_2(), }); Ok((mentionable.bytes(), resolver)) } @@ -117,7 +117,7 @@ where factory.parse_slice( &self.bytes(), map_resolver(Rc::new(CastResolver { - points: self.points_vec(), + points: self.points_vec_2(), })), ) } diff --git a/src/std/typeless.rs b/src/std/typeless.rs index e4956e6..7e1db8c 100644 --- a/src/std/typeless.rs +++ b/src/std/typeless.rs @@ -101,3 +101,30 @@ impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Point<'a, Ctx, A> { } } } + +pub trait MentionableExt2<'a, Ctx: 'a + Context>: Mentionable<'a, Ctx> { + /// References ([Point]s) to other objects. Typeless. + fn points_typeless(&self, points: &mut Vec>>); + /// [Vec] of [Point]s as used by [`Mentionable::topology`]. + fn points_vec_2(&self) -> Vec>>; +} + +impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> MentionableExt2<'a, Ctx> for A { + fn points_typeless(&self, points: &mut Vec>>) { + self.points_typed(points) + } + + fn points_vec_2(&self) -> Vec>> { + let mut points = Vec::new(); + self.points_typeless(&mut points); + points + } +} + +impl<'a, Ctx: 'a + Context> TakesPoints<'a, Ctx> + for Vec>> +{ + fn take>(&mut self, point: &Point<'a, Ctx, A>) { + self.push(point.typeless()); + } +}