From 3f001239d61d78b434b3df90da7b7f981f3f1917 Mon Sep 17 00:00:00 2001 From: Richard Newman Date: Wed, 25 Apr 2018 14:17:05 -0700 Subject: [PATCH] Finish transition. --- core/src/types.rs | 42 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/core/src/types.rs b/core/src/types.rs index 57df0a99..31b5723c 100644 --- a/core/src/types.rs +++ b/core/src/types.rs @@ -59,7 +59,7 @@ impl FromRc for Rc where T: Sized + Clone { fn from_arc(val: Arc) -> Self { match ::std::sync::Arc::::try_unwrap(val) { Ok(v) => Self::new(v), - Err(r) => Self::new((*r.as_ref()).clone()), + Err(r) => Self::new(r.cloned()), } } } @@ -68,7 +68,7 @@ impl FromRc for Arc where T: Sized + Clone { fn from_rc(val: Rc) -> Self { match ::std::rc::Rc::::try_unwrap(val) { Ok(v) => Self::new(v), - Err(r) => Self::new((*r.as_ref()).clone()), + Err(r) => Self::new(r.cloned()), } } @@ -77,6 +77,22 @@ impl FromRc for Arc where T: Sized + Clone { } } +impl FromRc for Box where T: Sized + Clone { + fn from_rc(val: Rc) -> Self { + match ::std::rc::Rc::::try_unwrap(val) { + Ok(v) => Self::new(v), + Err(r) => Self::new(r.cloned()), + } + } + + fn from_arc(val: Arc) -> Self { + match ::std::sync::Arc::::try_unwrap(val) { + Ok(v) => Self::new(v), + Err(r) => Self::new(r.cloned()), + } + } +} + // We do this a lot for errors. pub trait Cloned { fn cloned(&self) -> T; @@ -94,9 +110,17 @@ impl Cloned for Arc where T: Sized + Clone { } } -// -// Use Rc for values. -// +impl Cloned for Box where T: Sized + Clone { + fn cloned(&self) -> T { + self.as_ref().clone() + } +} + +/// +/// This type alias exists to allow us to use different boxing mechanisms for values. +/// This type must implement `FromRc` and `Cloned`, and a `From` implementation must exist for +/// `TypedValue`. +/// pub type ValueRc = Rc; /// Represents one entid in the entid space. @@ -284,7 +308,7 @@ impl Binding { /// /// We entirely support the former, and partially support the latter -- you can alias /// using a different keyword only. -#[derive(Debug, Eq, PartialEq)] +#[derive(Clone, Debug, Eq, PartialEq)] pub struct StructuredMap(IndexMap, Binding>); impl Binding { @@ -424,6 +448,12 @@ impl From> for TypedValue { } } +impl From> for TypedValue { + fn from(value: Box) -> TypedValue { + TypedValue::String(ValueRc::new(*value)) + } +} + impl From for TypedValue { fn from(value: String) -> TypedValue { TypedValue::String(ValueRc::new(value))