From: Ben Pfaff Date: Sun, 13 Jul 2025 15:37:55 +0000 (-0700) Subject: more cleanup X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=43cbaa128db7be0612218439eeae1bc6ec62c0c6;p=pspp more cleanup --- diff --git a/rust/pspp/src/data.rs b/rust/pspp/src/data.rs index 9334eaf668..5902603996 100644 --- a/rust/pspp/src/data.rs +++ b/rust/pspp/src/data.rs @@ -401,3 +401,13 @@ impl From<&[u8]> for Datum { Self::String(value.into()) } } + +/// A case in a data set. +#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] +pub struct Case( + /// One [Datum] per variable in the corresponding [Dictionary], in the same + /// order. + /// + /// [Dictionary]: crate::dictionary::Dictionary + pub Vec, +); diff --git a/rust/pspp/src/main.rs b/rust/pspp/src/main.rs index 50eaa8adf1..f14b44570c 100644 --- a/rust/pspp/src/main.rs +++ b/rust/pspp/src/main.rs @@ -106,7 +106,7 @@ impl Convert { } for (_case_number, case) in (0..self.max_cases.unwrap_or(u64::MAX)).zip(cases) { - output.write_record(case?.into_iter().zip(dictionary.variables.iter()).map( + output.write_record(case?.0.into_iter().zip(dictionary.variables.iter()).map( |(datum, variable)| { datum .display(variable.print_format, variable.encoding) diff --git a/rust/pspp/src/sys/raw.rs b/rust/pspp/src/sys/raw.rs index b1263be32c..d9de5c2304 100644 --- a/rust/pspp/src/sys/raw.rs +++ b/rust/pspp/src/sys/raw.rs @@ -20,7 +20,7 @@ //! raw details. Most readers will want to use higher-level interfaces. use crate::{ - data::{Datum, RawStr, RawString}, + data::{Case, Datum, RawStr, RawString}, dictionary::{VarType, VarWidth}, endian::{Endian, Parse, ToBytes}, format::DisplayPlainF64, @@ -898,12 +898,12 @@ impl Datum { reader: &mut R, case_vars: &[CaseVar], endian: Endian, - ) -> Result>, Error> { + ) -> Result, Error> { fn eof( reader: &mut R, case_vars: &[CaseVar], case_start: u64, - ) -> Result>, Error> { + ) -> Result, Error> { let offset = reader.stream_position()?; if offset == case_start { Ok(None) @@ -943,7 +943,7 @@ impl Datum { } } } - Ok(Some(values)) + Ok(Some(Case(values))) } fn read_compressed_chunk( @@ -975,12 +975,12 @@ impl Datum { codes: &mut VecDeque, endian: Endian, bias: f64, - ) -> Result>, Error> { + ) -> Result, Error> { fn eof( reader: &mut R, case_start: u64, n_chunks: usize, - ) -> Result>, Error> { + ) -> Result, Error> { let offset = reader.stream_position()?; if n_chunks > 0 { Err(Error::EofInCompressedCase { @@ -1028,7 +1028,7 @@ impl Datum { } } } - Ok(Some(values)) + Ok(Some(Case(values))) } } @@ -1249,22 +1249,6 @@ where trait ReadSeek: Read + Seek {} impl ReadSeek for T where T: Read + Seek {} -/// A case in a system file. -pub struct Case( - /// One [Datum] per variable in the system file dictionary, in the same - /// order: - /// - /// - A raw [Reader] returns cases in which very long string variables - /// (those over 255 bytes wide) are still in their raw format, which means - /// that they are divided into multiple, adjacent string variables, - /// approximately one variable for each 252 bytes. - /// - /// - [Headers::decode](super::cooked::Headers::decode) returns cases in - /// which each [Dictionary](crate::dictionary::Dictionary) variable - /// corresponds to one [Datum], even for long string variables. - pub Vec, -); - #[derive(Debug)] struct StringSegment { data_bytes: usize, @@ -1328,6 +1312,15 @@ impl CaseVar { } /// Reader for cases in a system file. +/// +/// - [Reader::cases] returns [Cases] in which very long string variables (those +/// over 255 bytes wide) are still in their raw format, which means that they +/// are divided into multiple, adjacent string variables, approximately one +/// variable for each 252 bytes. +/// +/// - [Headers::decode](super::cooked::Headers::decode) returns [Cases] in +/// which each [Dictionary](crate::dictionary::Dictionary) variable +/// corresponds to one [Datum], even for long string variables. pub struct Cases { reader: Box, case_vars: Vec, @@ -1413,7 +1406,7 @@ impl Cases { } impl Iterator for Cases { - type Item = Result, Error>; + type Item = Result; fn next(&mut self) -> Option { if self.eof { diff --git a/rust/pspp/src/sys/test.rs b/rust/pspp/src/sys/test.rs index e0fb088c9e..a4f336bb7f 100644 --- a/rust/pspp/src/sys/test.rs +++ b/rust/pspp/src/sys/test.rs @@ -672,7 +672,8 @@ where case_numbers .push(Value::new_integer(Some((case_numbers.len() + 1) as f64))); data.push( - case.into_iter() + case.0 + .into_iter() .map(|datum| Value::new_datum(&datum, dictionary.encoding)) .collect::>(), );