diff --git a/implementations/rust/Cargo.toml b/implementations/rust/Cargo.toml index 8551660..c0134f2 100644 --- a/implementations/rust/Cargo.toml +++ b/implementations/rust/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "preserves" -version = "0.1.0" +version = "0.1.1" authors = ["Tony Garnock-Jones "] edition = "2018" description = "Implementation of the Preserves serialization format via serde." diff --git a/implementations/rust/src/lib.rs b/implementations/rust/src/lib.rs index d757ee9..561e0f1 100644 --- a/implementations/rust/src/lib.rs +++ b/implementations/rust/src/lib.rs @@ -156,10 +156,10 @@ mod value_tests { } #[test] fn record_mut() { - let says = Value::symbol("says").wrap().rc(); - let mut r = Value::record(&says, vec![Value::from("Tony").wrap(), Value::from("Hello!").wrap()]); + let says = Value::symbol("says").wrap(); + let mut r = Value::record(says.clone(), vec![Value::from("Tony").wrap(), Value::from("Hello!").wrap()]); r.as_record_mut().unwrap().1[0] = Value::from("Alice").wrap(); - assert_eq!(r, Value::record(&says, vec![Value::from("Alice").wrap(), Value::from("Hello!").wrap()])); + assert_eq!(r, Value::record(says, vec![Value::from("Alice").wrap(), Value::from("Hello!").wrap()])); } #[test] fn sequence_mut() { diff --git a/implementations/rust/src/value/decoder.rs b/implementations/rust/src/value/decoder.rs index 766d119..1ae0e89 100644 --- a/implementations/rust/src/value/decoder.rs +++ b/implementations/rust/src/value/decoder.rs @@ -180,8 +180,8 @@ impl<'a, R: Read> Decoder<'a, R> { if pieces.len() == 0 { Err(Error::Syntax("Too few elements in encoded record")) } else { - let label = pieces.remove(0).rc(); - Ok(Value::record(&label, pieces).wrap()) + let label = pieces.remove(0); + Ok(Value::record(label, pieces).wrap()) }, CompoundMinor::Sequence => Ok(Value::from(pieces).wrap()), CompoundMinor::Set => { diff --git a/implementations/rust/src/value/value.rs b/implementations/rust/src/value/value.rs index 249ae6f..8418f95 100644 --- a/implementations/rust/src/value/value.rs +++ b/implementations/rust/src/value/value.rs @@ -1,7 +1,6 @@ use std::hash::{Hash,Hasher}; use std::cmp::{Ordering}; use num::bigint::BigInt; -use std::rc::Rc; use std::vec::Vec; use std::string::String; use std::collections::BTreeSet; @@ -40,7 +39,7 @@ pub struct Float(pub f32); pub struct Double(pub f64); /// A Record `Value` -pub type Record = (Rc, Vec); +pub type Record = (Box, Vec); pub type Set = BTreeSet; @@ -238,10 +237,6 @@ impl std::fmt::Debug for AValue { //--------------------------------------------------------------------------- impl AValue { - pub fn rc(self) -> Rc { - Rc::new(self) - } - pub fn annotations(&self) -> &Vec { &self.0 } @@ -417,8 +412,8 @@ impl Value { } } - pub fn record(label: &Rc, fields: Vec) -> Value { - Value::Record((Rc::clone(label), fields)) + pub fn record(label: AValue, fields: Vec) -> Value { + Value::Record((Box::new(label), fields)) } pub fn is_record(&self) -> bool { @@ -442,7 +437,7 @@ impl Value { } pub fn simple_record(label: &str, fields: Vec) -> Value { - Value::record(&Rc::new(Value::symbol(label).wrap()), fields) + Value::record(Value::symbol(label).wrap(), fields) } pub fn is_simple_record(&self, label: &str, arity: Option) -> bool {