//! 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,
reader: &mut R,
case_vars: &[CaseVar],
endian: Endian,
- ) -> Result<Option<Vec<Self>>, Error> {
+ ) -> Result<Option<Case>, Error> {
fn eof<R: Seek>(
reader: &mut R,
case_vars: &[CaseVar],
case_start: u64,
- ) -> Result<Option<Vec<Datum>>, Error> {
+ ) -> Result<Option<Case>, Error> {
let offset = reader.stream_position()?;
if offset == case_start {
Ok(None)
}
}
}
- Ok(Some(values))
+ Ok(Some(Case(values)))
}
fn read_compressed_chunk<R: Read>(
codes: &mut VecDeque<u8>,
endian: Endian,
bias: f64,
- ) -> Result<Option<Vec<Self>>, Error> {
+ ) -> Result<Option<Case>, Error> {
fn eof<R: Seek>(
reader: &mut R,
case_start: u64,
n_chunks: usize,
- ) -> Result<Option<Vec<Datum>>, Error> {
+ ) -> Result<Option<Case>, Error> {
let offset = reader.stream_position()?;
if n_chunks > 0 {
Err(Error::EofInCompressedCase {
}
}
}
- Ok(Some(values))
+ Ok(Some(Case(values)))
}
}
trait ReadSeek: Read + Seek {}
impl<T> 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<Datum>,
-);
-
#[derive(Debug)]
struct StringSegment {
data_bytes: usize,
}
/// 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<dyn ReadSeek>,
case_vars: Vec<CaseVar>,
}
impl Iterator for Cases {
- type Item = Result<Vec<Datum>, Error>;
+ type Item = Result<Case, Error>;
fn next(&mut self) -> Option<Self::Item> {
if self.eof {