diff --git a/experiments/2024-12-09/src/geometry/operation.rs b/experiments/2024-12-09/src/geometry/operation.rs index 8fab33b81..79e4e91a6 100644 --- a/experiments/2024-12-09/src/geometry/operation.rs +++ b/experiments/2024-12-09/src/geometry/operation.rs @@ -8,6 +8,41 @@ pub trait Operation: fmt::Display { fn children(&self) -> Vec; } +#[derive(Debug, Eq, Ord, PartialEq, PartialOrd)] +pub struct Handle { + inner: Rc, +} + +impl Handle { + pub fn new(inner: T) -> Self { + Self { + inner: Rc::new(inner), + } + } + + pub fn to_any(&self) -> HandleAny + where + T: Operation + 'static, + { + self.clone().into_any() + } + + pub fn into_any(self) -> HandleAny + where + T: Operation + 'static, + { + HandleAny { inner: self.inner } + } +} + +impl Clone for Handle { + fn clone(&self) -> Self { + Self { + inner: self.inner.clone(), + } + } +} + #[derive(Clone)] pub struct HandleAny { inner: Rc, diff --git a/experiments/2024-12-09/src/geometry/shape.rs b/experiments/2024-12-09/src/geometry/shape.rs index f5c36bec3..66352e254 100644 --- a/experiments/2024-12-09/src/geometry/shape.rs +++ b/experiments/2024-12-09/src/geometry/shape.rs @@ -2,7 +2,10 @@ use std::fmt; use tuples::CombinRight; -use super::{operation::HandleAny, Operation, Triangle, Vertex}; +use super::{ + operation::{Handle, HandleAny}, + Operation, Triangle, Vertex, +}; #[derive(Default)] pub struct Shape { @@ -33,11 +36,11 @@ impl Shape { pub fn triangle( &mut self, triangle: impl Into, - ) -> OperationResult<(Triangle,)> { - let triangle = triangle.into(); + ) -> OperationResult<(Handle,)> { + let triangle = Handle::new(triangle.into()); self.operations.push(OperationInSequence { - operation: HandleAny::new(triangle.clone()), + operation: triangle.to_any(), previous: self .operations .last() @@ -138,7 +141,7 @@ impl<'r, T> OperationResult<'r, T> { triangle: impl Into, ) -> OperationResult<'r, T::Out> where - T: CombinRight, + T: CombinRight>, { let OperationResult { results: (triangle,),