From 5b9c4d29f643f20ea8f37e94e95e05354e0e5e93 Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Wed, 30 Jun 2021 15:05:57 +0200 Subject: [PATCH] impl Domain for Arc --- implementations/rust/preserves/src/value/repr.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/implementations/rust/preserves/src/value/repr.rs b/implementations/rust/preserves/src/value/repr.rs index b89abd6..ecb5a77 100644 --- a/implementations/rust/preserves/src/value/repr.rs +++ b/implementations/rust/preserves/src/value/repr.rs @@ -11,6 +11,7 @@ use std::marker::PhantomData; use std::ops::Index; use std::ops::IndexMut; use std::string::String; +use std::sync::Arc; use std::vec::Vec; pub use std::collections::BTreeSet as Set; @@ -25,6 +26,16 @@ pub trait Domain: Sized + Debug + Clone + Eq + Hash + Ord { fn as_preserves(&self) -> IOValue; } +impl Domain for Arc { + fn from_preserves(v: IOValue) -> IOResult { + Ok(Arc::new(D::from_preserves(v)?)) + } + + fn as_preserves(&self) -> IOValue { + D::as_preserves(self) + } +} + pub trait NestedValue: Sized + Debug + Clone + Eq + Hash + Ord { fn wrap(anns: Annotations, v: Value) -> Self; @@ -1046,8 +1057,6 @@ impl<'de, Dom: Domain> serde::Deserialize<'de> for RcValue { //--------------------------------------------------------------------------- -use std::sync::Arc; - #[derive(Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] pub struct ArcValue(Arc, D>>);