From 0aded610718dd052813b44804f0a4c69425abfe2 Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Fri, 27 Aug 2021 16:59:54 +0200 Subject: [PATCH] Take advantage of NestedValue::symbol --- .../rust/preserves-tools/src/bin/preserves-tool.rs | 10 ++++------ implementations/rust/preserves/src/symbol.rs | 4 ++-- implementations/rust/preserves/src/value/repr.rs | 2 +- .../rust/preserves/src/value/text/reader.rs | 4 ++-- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/implementations/rust/preserves-tools/src/bin/preserves-tool.rs b/implementations/rust/preserves-tools/src/bin/preserves-tool.rs index c7c5bb6..dcac6a2 100644 --- a/implementations/rust/preserves-tools/src/bin/preserves-tool.rs +++ b/implementations/rust/preserves-tools/src/bin/preserves-tool.rs @@ -454,12 +454,10 @@ fn quote(q: Quote) -> io::Result<()> { } fn quote_chunk(q: &Quote, buf: String) -> io::Result<()> { - let v = if let QuotationOutput::Symbol(_) = q.output { - Value::symbol(&buf).wrap() - } else { - Value::String(buf).wrap() - }; - output_one(q, &v) + match q.output { + QuotationOutput::Symbol(_) => output_one(q, &IOValue::symbol(&buf)), + _ => output_one(q, &IOValue::new(buf)), + } } fn quote_terminated_strings(delimiter: u8, q: &Quote, s: &StringQuotation) -> io::Result<()> { diff --git a/implementations/rust/preserves/src/symbol.rs b/implementations/rust/preserves/src/symbol.rs index 871454e..67f4a0f 100644 --- a/implementations/rust/preserves/src/symbol.rs +++ b/implementations/rust/preserves/src/symbol.rs @@ -1,11 +1,11 @@ -use crate::value::{IOValue, UnwrappedIOValue, NestedValue}; +use crate::value::{IOValue, NestedValue}; #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone)] pub struct Symbol(pub String); impl serde::Serialize for Symbol { fn serialize(&self, serializer: S) -> Result where S: serde::Serializer { - UnwrappedIOValue::symbol(&self.0).wrap().serialize(serializer) + IOValue::symbol(&self.0).serialize(serializer) } } diff --git a/implementations/rust/preserves/src/value/repr.rs b/implementations/rust/preserves/src/value/repr.rs index 3fa4edc..88e8034 100644 --- a/implementations/rust/preserves/src/value/repr.rs +++ b/implementations/rust/preserves/src/value/repr.rs @@ -746,7 +746,7 @@ impl, D: Embeddable> Value { } pub fn simple_record(label: &str, expected_arity: usize) -> Record { - Self::record(Value::symbol(label).wrap(), expected_arity) + Self::record(N::symbol(label), expected_arity) } pub fn simple_record0(label: &str) -> Value { diff --git a/implementations/rust/preserves/src/value/text/reader.rs b/implementations/rust/preserves/src/value/text/reader.rs index d761c7a..bdf455a 100644 --- a/implementations/rust/preserves/src/value/text/reader.rs +++ b/implementations/rust/preserves/src/value/text/reader.rs @@ -373,7 +373,7 @@ impl<'de, 'src, D: Embeddable, Dec: DomainParse, S: BinarySource<'de>> TextRe match c { b'(' | b')' | b'{' | b'}' | b'[' | b']' | b'<' | b'>' | b'"' | b';' | b',' | b'@' | b'#' | b':' | b'|' | b' ' => - return Ok(Value::symbol(&decode_utf8(bs)?).wrap()), + return Ok(N::symbol(&decode_utf8(bs)?)), c => { self.skip()?; bs.push(c) @@ -409,7 +409,7 @@ impl<'de, 'src, D: Embeddable, N: NestedValue, Dec: DomainParse, S: Binary } b'|' => { self.skip()?; - Value::symbol(&self.read_string(b'|')?).wrap() + N::symbol(&self.read_string(b'|')?) } b';' | b'@' => { if read_annotations {