Finish transition.

This commit is contained in:
Richard Newman 2018-04-25 14:17:05 -07:00
parent a6ec3f2272
commit 3f001239d6

View file

@ -59,7 +59,7 @@ impl<T> FromRc<T> for Rc<T> where T: Sized + Clone {
fn from_arc(val: Arc<T>) -> Self {
match ::std::sync::Arc::<T>::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<T> FromRc<T> for Arc<T> where T: Sized + Clone {
fn from_rc(val: Rc<T>) -> Self {
match ::std::rc::Rc::<T>::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<T> FromRc<T> for Arc<T> where T: Sized + Clone {
}
}
impl<T> FromRc<T> for Box<T> where T: Sized + Clone {
fn from_rc(val: Rc<T>) -> Self {
match ::std::rc::Rc::<T>::try_unwrap(val) {
Ok(v) => Self::new(v),
Err(r) => Self::new(r.cloned()),
}
}
fn from_arc(val: Arc<T>) -> Self {
match ::std::sync::Arc::<T>::try_unwrap(val) {
Ok(v) => Self::new(v),
Err(r) => Self::new(r.cloned()),
}
}
}
// We do this a lot for errors.
pub trait Cloned<T> {
fn cloned(&self) -> T;
@ -94,9 +110,17 @@ impl<T: Clone> Cloned<T> for Arc<T> where T: Sized + Clone {
}
}
//
// Use Rc for values.
//
impl<T: Clone> Cloned<T> for Box<T> 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<T> = Rc<T>;
/// 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<ValueRc<NamespacedKeyword>, Binding>);
impl Binding {
@ -424,6 +448,12 @@ impl From<Rc<String>> for TypedValue {
}
}
impl From<Box<String>> for TypedValue {
fn from(value: Box<String>) -> TypedValue {
TypedValue::String(ValueRc::new(*value))
}
}
impl From<String> for TypedValue {
fn from(value: String) -> TypedValue {
TypedValue::String(ValueRc::new(value))