hey it compiles again
[pspp] / rust / src / cooked.rs
index 2cea33074024b7b67739c82f1ba0cb9fa617bc05..b3c0ff74bf585aaed00f0974a8560d1806c039d1 100644 (file)
@@ -8,7 +8,7 @@ use crate::{
     endian::Endian,
     format::{Error as FormatError, Spec, UncheckedSpec},
     identifier::{Error as IdError, Identifier},
-    raw::{self, UnencodedStr, VarType},
+    raw::{self, RawStr, RawString, VarType},
 };
 use chrono::{NaiveDate, NaiveDateTime, NaiveTime};
 use encoding_rs::{DecoderResult, Encoding};
@@ -212,9 +212,9 @@ pub struct Decoder {
 
 #[derive(Default)]
 struct Headers<'a> {
-    header: Option<&'a raw::HeaderRecord>,
-    variables: Vec<&'a raw::VariableRecord>,
-    value_labels: Vec<&'a raw::ValueLabelRecord>,
+    header: Option<&'a raw::HeaderRecord<RawString>>,
+    variables: Vec<&'a raw::VariableRecord<RawString, RawStr<8>>>,
+    value_labels: Vec<&'a raw::ValueLabelRecord<RawStr<8>, RawString>>,
     document: Option<&'a raw::DocumentRecord>,
     integer_info: Option<&'a raw::IntegerInfoRecord>,
     float_info: Option<&'a raw::FloatInfoRecord>,
@@ -519,8 +519,8 @@ pub trait Decode<Input>: Sized {
     fn decode(decoder: &Decoder, input: &Input, warn: impl Fn(Error)) -> Self;
 }
 
-impl<const N: usize> Decode<UnencodedStr<N>> for String {
-    fn decode(decoder: &Decoder, input: &UnencodedStr<N>, warn: impl Fn(Error)) -> Self {
+impl<const N: usize> Decode<RawStr<N>> for String {
+    fn decode(decoder: &Decoder, input: &RawStr<N>, warn: impl Fn(Error)) -> Self {
         decoder.decode_string(&input.0, &warn)
     }
 }
@@ -540,7 +540,7 @@ fn trim_end_spaces(mut s: String) -> String {
 }
 
 impl TryDecode for HeaderRecord {
-    type Input = crate::raw::HeaderRecord;
+    type Input = crate::raw::HeaderRecord<RawString>;
 
     fn try_decode(
         decoder: &mut Decoder,
@@ -658,8 +658,12 @@ pub struct MissingValues {
     pub range: Option<(Value, Value)>,
 }
 
-impl Decode<raw::MissingValues> for MissingValues {
-    fn decode(decoder: &Decoder, input: &raw::MissingValues, _warn: impl Fn(Error)) -> Self {
+impl Decode<raw::MissingValues<RawStr<8>>> for MissingValues {
+    fn decode(
+        decoder: &Decoder,
+        input: &raw::MissingValues<RawStr<8>>,
+        _warn: impl Fn(Error),
+    ) -> Self {
         MissingValues {
             values: input
                 .values
@@ -686,11 +690,11 @@ fn decode_format(raw: raw::Spec, width: VarWidth, warn: impl Fn(Spec, FormatErro
 }
 
 impl TryDecode for VariableRecord {
-    type Input = raw::VariableRecord;
+    type Input = raw::VariableRecord<RawString, RawStr<8>>;
 
     fn try_decode(
         decoder: &mut Decoder,
-        input: &crate::raw::VariableRecord,
+        input: &Self::Input,
         warn: impl Fn(Error),
     ) -> Result<Option<VariableRecord>, Error> {
         let width = match input.width {
@@ -836,11 +840,11 @@ impl<T> WarnOnError<T> for Result<T, Error> {
 #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
 pub enum Value {
     Number(Option<OrderedFloat<f64>>),
-    String(Box<str>),
+    String(String),
 }
 
 impl Value {
-    pub fn decode(raw: &raw::Value, decoder: &Decoder) -> Self {
+    pub fn decode(raw: &raw::Value<RawStr<8>>, decoder: &Decoder) -> Self {
         match raw {
             raw::Value::Number(x) => Value::Number(x.map(|x| x.into())),
             raw::Value::String(s) => Value::String(decoder.decode_exact_length(&s.0).into()),
@@ -862,7 +866,7 @@ pub struct ValueLabelRecord {
 }
 
 impl TryDecode for ValueLabelRecord {
-    type Input = crate::raw::ValueLabelRecord;
+    type Input = crate::raw::ValueLabelRecord<RawStr<8>, RawString>;
     fn try_decode(
         decoder: &mut Decoder,
         input: &Self::Input,
@@ -908,10 +912,10 @@ impl TryDecode for ValueLabelRecord {
         let labels = input
             .labels
             .iter()
-            .map(|(value, label)| {
+            .map(|raw::ValueLabel { value, label }| {
                 let label = decoder.decode_string(&label.0, &warn);
                 let value = Value::decode(
-                    &raw::Value::from_raw(value, var_type, decoder.endian),
+                    value,
                     decoder,
                 );
                 ValueLabel { value, label }