rawstr -> rawstrarray in plans for rawstr(&[u8])
authorBen Pfaff <blp@cs.stanford.edu>
Sun, 13 Apr 2025 18:10:12 +0000 (11:10 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Sun, 13 Apr 2025 18:10:12 +0000 (11:10 -0700)
rust/pspp/src/cooked.rs
rust/pspp/src/raw.rs

index 7c68d47c8b664a56f559e89986f263b5be5661ea..cc1194b726da2593931ecb2d9f53ea08c3fa1428 100644 (file)
@@ -14,7 +14,7 @@ use crate::{
         self, Cases, DecodedRecord, DocumentRecord, EncodingRecord, Extension, FileAttributeRecord,
         FloatInfoRecord, HeaderRecord, IntegerInfoRecord, LongName, LongNamesRecord,
         LongStringMissingValueRecord, LongStringValueLabelRecord, MissingValues,
-        MultipleResponseRecord, NumberOfCasesRecord, ProductInfoRecord, RawStr, RawWidth,
+        MultipleResponseRecord, NumberOfCasesRecord, ProductInfoRecord, RawStrArray, RawWidth,
         ValueLabel, ValueLabelRecord, VarDisplayRecord, VariableAttributeRecord, VariableRecord,
         VariableSetRecord, VeryLongStringsRecord, ZHeader, ZTrailer,
     },
@@ -175,7 +175,7 @@ pub enum Error {
 pub struct Headers {
     pub header: HeaderRecord<String>,
     pub variable: Vec<VariableRecord<String>>,
-    pub value_label: Vec<ValueLabelRecord<RawStr<8>, String>>,
+    pub value_label: Vec<ValueLabelRecord<RawStrArray<8>, String>>,
     pub document: Vec<DocumentRecord<String>>,
     pub integer_info: Option<IntegerInfoRecord>,
     pub float_info: Option<FloatInfoRecord>,
index 5144b6286e1665a7cdc59f72a8c6612a0a5a262b..62ba39f0e03115b44d875887f69a846b82343e8c 100644 (file)
@@ -221,7 +221,7 @@ impl From<IoError> for Warning {
 pub enum Record {
     Header(HeaderRecord<RawString>),
     Variable(VariableRecord<RawString>),
-    ValueLabel(ValueLabelRecord<RawStr<8>, RawString>),
+    ValueLabel(ValueLabelRecord<RawStrArray<8>, RawString>),
     Document(DocumentRecord<RawDocumentLine>),
     IntegerInfo(IntegerInfoRecord),
     FloatInfo(FloatInfoRecord),
@@ -243,7 +243,7 @@ pub enum Record {
 pub enum DecodedRecord {
     Header(HeaderRecord<String>),
     Variable(VariableRecord<String>),
-    ValueLabel(ValueLabelRecord<RawStr<8>, String>),
+    ValueLabel(ValueLabelRecord<RawStrArray<8>, String>),
     Document(DocumentRecord<String>),
     IntegerInfo(IntegerInfoRecord),
     FloatInfo(FloatInfoRecord),
@@ -657,12 +657,12 @@ impl TryFrom<RawWidth> for VarWidth {
     }
 }
 
-type RawValue = Value<RawStr<8>>;
+type RawValue = Value<RawStrArray<8>>;
 
 impl RawValue {
     pub fn from_raw(raw: &UntypedValue, var_type: VarType, endian: Endian) -> Self {
         match var_type {
-            VarType::String => Value::String(RawStr(raw.0)),
+            VarType::String => Value::String(RawStrArray(raw.0)),
             VarType::Numeric => Value::Number(endian.parse(raw.0)),
         }
     }
@@ -723,7 +723,7 @@ impl RawValue {
                     1..=251 => match var_type {
                         VarType::Numeric => break Self::Number(Some(code as f64 - bias)),
                         VarType::String => {
-                            break Self::String(RawStr(endian.to_bytes(code as f64 - bias)))
+                            break Self::String(RawStrArray(endian.to_bytes(code as f64 - bias)))
                         }
                     },
                     252 => {
@@ -741,7 +741,7 @@ impl RawValue {
                         break Self::from_raw(&UntypedValue(read_bytes(reader)?), var_type, endian)
                     }
                     254 => match var_type {
-                        VarType::String => break Self::String(RawStr(*b"        ")), // XXX EBCDIC
+                        VarType::String => break Self::String(RawStrArray(*b"        ")), // XXX EBCDIC
                         VarType::Numeric => {
                             return Err(Error::CompressedStringExpected {
                                 offset: case_start,
@@ -1404,15 +1404,15 @@ impl Debug for RawString {
 }
 
 #[derive(Copy, Clone)]
-pub struct RawStr<const N: usize>(pub [u8; N]);
+pub struct RawStrArray<const N: usize>(pub [u8; N]);
 
-impl<const N: usize> From<[u8; N]> for RawStr<N> {
+impl<const N: usize> From<[u8; N]> for RawStrArray<N> {
     fn from(source: [u8; N]) -> Self {
         Self(source)
     }
 }
 
-impl<const N: usize> Debug for RawStr<N> {
+impl<const N: usize> Debug for RawStrArray<N> {
     fn fmt(&self, f: &mut Formatter) -> FmtResult {
         write!(f, "{:?}", default_decode(&self.0))
     }
@@ -1477,7 +1477,7 @@ where
     pub const MAX_INDEXES: u32 = u32::MAX / 8;
 }
 
-impl ValueLabelRecord<RawStr<8>, RawString> {
+impl ValueLabelRecord<RawStrArray<8>, RawString> {
     fn read<R: Read + Seek>(
         r: &mut R,
         endian: Endian,
@@ -1586,7 +1586,7 @@ impl ValueLabelRecord<RawStr<8>, RawString> {
         })))
     }
 
-    fn decode(self, decoder: &Decoder) -> ValueLabelRecord<RawStr<8>, String> {
+    fn decode(self, decoder: &Decoder) -> ValueLabelRecord<RawStrArray<8>, String> {
         let labels = self
             .labels
             .iter()
@@ -1616,7 +1616,7 @@ where
     pub lines: Vec<S>,
 }
 
-pub type RawDocumentLine = RawStr<DOC_LINE_LEN>;
+pub type RawDocumentLine = RawStrArray<DOC_LINE_LEN>;
 
 /// Length of a line in a document.  Document lines are fixed-length and
 /// padded on the right with spaces.
@@ -1640,7 +1640,7 @@ impl DocumentRecord<RawDocumentLine> {
         } else {
             let mut lines = Vec::with_capacity(n);
             for _ in 0..n {
-                lines.push(RawStr(read_bytes(r)?));
+                lines.push(RawStrArray(read_bytes(r)?));
             }
             let end_offset = r.stream_position()?;
             Ok(Record::Document(DocumentRecord {
@@ -2036,7 +2036,7 @@ where
     pub var_name: N,
 
     /// Missing values.
-    pub missing_values: Vec<RawStr<8>>,
+    pub missing_values: Vec<RawStrArray<8>>,
 }
 
 impl LongStringMissingValues<RawString> {
@@ -2088,7 +2088,7 @@ impl ExtensionRecord for LongStringMissingValueRecord<RawString> {
                 } else {
                     value
                 };
-                missing_values.push(RawStr(value));
+                missing_values.push(RawStrArray(value));
             }
             missing_value_set.push(LongStringMissingValues {
                 var_name,