Rc -> Box

This commit is contained in:
Tony Garnock-Jones 2019-09-19 21:35:00 +01:00
parent 116b37a24f
commit 63cd853ba1
4 changed files with 10 additions and 15 deletions

View File

@ -1,6 +1,6 @@
[package]
name = "preserves"
version = "0.1.0"
version = "0.1.1"
authors = ["Tony Garnock-Jones <tonyg@leastfixedpoint.com>"]
edition = "2018"
description = "Implementation of the Preserves serialization format via serde."

View File

@ -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() {

View File

@ -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 => {

View File

@ -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<AValue>, Vec<AValue>);
pub type Record = (Box<AValue>, Vec<AValue>);
pub type Set = BTreeSet<AValue>;
@ -238,10 +237,6 @@ impl std::fmt::Debug for AValue {
//---------------------------------------------------------------------------
impl AValue {
pub fn rc(self) -> Rc<Self> {
Rc::new(self)
}
pub fn annotations(&self) -> &Vec<AValue> {
&self.0
}
@ -417,8 +412,8 @@ impl Value {
}
}
pub fn record(label: &Rc<AValue>, fields: Vec<AValue>) -> Value {
Value::Record((Rc::clone(label), fields))
pub fn record(label: AValue, fields: Vec<AValue>) -> 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<AValue>) -> 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<usize>) -> bool {