cleanup
authorBen Pfaff <blp@cs.stanford.edu>
Sat, 2 Aug 2025 16:45:23 +0000 (09:45 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Sat, 2 Aug 2025 16:45:23 +0000 (09:45 -0700)
rust/pspp/src/data.rs
rust/pspp/src/endian.rs
rust/pspp/src/format/display/mod.rs
rust/pspp/src/format/display/test.rs
rust/pspp/src/format/parse.rs
rust/pspp/src/settings.rs
rust/pspp/src/sys/cooked.rs
rust/pspp/src/sys/raw.rs
rust/pspp/src/sys/raw/records.rs
rust/pspp/src/sys/sack.rs
rust/pspp/src/sys/test.rs

index 72024799659ee141b165ecd177361cef131abbd8..70f8b733320362c9a3b266a1b9b9984be1b3bd38 100644 (file)
@@ -308,9 +308,6 @@ pub use encoded::{Encoded, EncodedString, WithEncoding};
 /// A [Datum] that owns its string data (if any).
 pub type OwnedDatum = Datum<WithEncoding<ByteString>>;
 
-/// A [Datum] that borrows its string data (if any).
-pub type BorrowedDatum<'a> = Datum<WithEncoding<ByteStr<'a>>>;
-
 /// The value of a [Variable](crate::dictionary::Variable).
 ///
 /// `RawString` is parameterized by its string type, which is either
index 07cfe886c8f70115eae09bf262ecbfbcbc20621e..b52d66d84e51a2669ae9c043e43ce5c0021d8c34 100644 (file)
 // You should have received a copy of the GNU General Public License along with
 // this program.  If not, see <http://www.gnu.org/licenses/>.
 
-use smallvec::SmallVec;
-
-pub use binrw::Endian;
-
-pub fn endian_to_smallvec<const N: usize>(
-    endian: Endian,
-    mut value: u64,
-    n: usize,
-) -> SmallVec<[u8; N]> {
-    debug_assert!(n <= 8);
-    let mut vec = SmallVec::new();
-    value <<= 8 * (8 - n);
-    for _ in 0..n {
-        vec.push((value >> 56) as u8);
-        value <<= 8;
-    }
-    if endian == Endian::Little {
-        vec.reverse();
-    }
-    vec
-}
+use binrw::Endian;
 
 pub trait ToBytes<T, const N: usize> {
     fn to_bytes(self, value: T) -> [u8; N];
index af86b33889a80493ab5de3a7ed2f462d7590ab96..4d268e1e95d0bc7708164506ea0042852336cfdb 100644 (file)
@@ -21,6 +21,7 @@ use std::{
     str::from_utf8_unchecked,
 };
 
+use binrw::Endian;
 use chrono::{Datelike, NaiveDate};
 use encoding_rs::{Encoding, UTF_8};
 use libm::frexp;
@@ -30,7 +31,7 @@ use smallvec::{Array, SmallVec};
 use crate::{
     calendar::{calendar_offset_to_gregorian, day_of_year, month_name, short_month_name},
     data::{ByteStr, Datum, EncodedString, QuotedDatum, WithEncoding},
-    endian::{endian_to_smallvec, ToBytes},
+    endian::ToBytes,
     format::{Category, DateTemplate, Decimal, Format, NumberStyle, Settings, TemplateItem, Type},
     settings::{EndianSettings, Settings as PsppSettings},
 };
@@ -1147,3 +1148,21 @@ where
         }
     }
 }
+
+pub fn endian_to_smallvec<const N: usize>(
+    endian: Endian,
+    mut value: u64,
+    n: usize,
+) -> SmallVec<[u8; N]> {
+    debug_assert!(n <= 8);
+    let mut vec = SmallVec::new();
+    value <<= 8 * (8 - n);
+    for _ in 0..n {
+        vec.push((value >> 56) as u8);
+        value <<= 8;
+    }
+    if endian == Endian::Little {
+        vec.reverse();
+    }
+    vec
+}
index 6eefc4ffd268c5997d39da1cf0116cbb1a88131e..9ddd3047f2a993e27c76be070b8431163c1f6f4f 100644 (file)
@@ -16,7 +16,7 @@
 
 use std::{fmt::Write, fs::File, io::BufRead, path::Path};
 
-use binrw::io::BufReader;
+use binrw::{io::BufReader, Endian};
 use encoding_rs::UTF_8;
 use itertools::Itertools;
 use smallstr::SmallString;
@@ -24,7 +24,6 @@ use smallvec::SmallVec;
 
 use crate::{
     data::{ByteString, Datum, WithEncoding},
-    endian::Endian,
     format::{AbstractFormat, Epoch, Format, Settings, Type, UncheckedFormat, CC},
     lex::{scan::StringScanner, segment::Syntax, Punct, Token},
     settings::EndianSettings,
index b97e280ba926bcd7f03e87a54da0b0db47d86273..a43e59bb544c96e3537f0dc655c523785eddeab8 100644 (file)
 use crate::{
     calendar::{calendar_gregorian_to_offset, DateError},
     data::{ByteString, Datum, EncodedString, OwnedDatum, RawString, WithEncoding},
-    endian::{Endian, Parse},
+    endian::Parse,
     format::{DateTemplate, Decimals, Settings, TemplateItem, Type},
     settings::{EndianSettings, Settings as PsppSettings},
 };
+use binrw::Endian;
 use encoding_rs::Encoding;
 use smallstr::SmallString;
 use std::{
@@ -916,13 +917,13 @@ mod test {
         path::Path,
     };
 
+    use binrw::Endian;
     use encoding_rs::UTF_8;
     use rand::random;
 
     use crate::{
         calendar::{days_in_month, is_leap_year},
         data::{ByteStr, Datum, EncodedString, OwnedDatum, RawString},
-        endian::Endian,
         format::{
             parse::{ParseError, ParseErrorKind, Sign},
             Epoch, Format, Settings as FormatSettings, Type,
index f4678b12363d28973c298f84a1cc7bb9876981a7..7c7678c7439154aa3c2ea2a93c85f4bc0335f4ab 100644 (file)
 
 use std::sync::{Arc, OnceLock};
 
+use binrw::Endian;
 use enum_map::EnumMap;
 
 use crate::{
-    endian::Endian,
     format::{Format, Settings as FormatSettings},
     message::Severity,
     output::pivot::Look,
index 24d5c887bd43876ab371ca288ccd8a1a0d661edd..63fca6744c6661cf3c6a78c67c4e3b598a1c0099 100644 (file)
@@ -31,7 +31,6 @@ use crate::{
         DictIndexMultipleResponseSet, DictIndexVariableSet, Dictionary, InvalidRole, MissingValues,
         MissingValuesError, MultipleResponseType, VarWidth, Variable,
     },
-    endian::Endian,
     format::{Error as FormatError, Format, UncheckedFormat},
     hexfloat::HexFloat,
     identifier::{ByIdentifier, Error as IdError, Identifier},
@@ -53,7 +52,7 @@ use crate::{
     },
 };
 use anyhow::{anyhow, Error as AnyError};
-use binrw::{BinRead, BinWrite};
+use binrw::{BinRead, BinWrite, Endian};
 use chrono::{NaiveDate, NaiveDateTime, NaiveTime};
 use encoding_rs::Encoding;
 use indexmap::set::MutableValues;
index be1f741d4828555fdc5ca02d58547555e5fffc26..14410ee03082c8a47ce19803955d0fe0dd4fc005 100644 (file)
@@ -22,7 +22,7 @@
 use crate::{
     data::{ByteStr, ByteString, Datum, RawCase},
     dictionary::{VarType, VarWidth},
-    endian::{Endian, Parse, ToBytes},
+    endian::{Parse, ToBytes},
     identifier::{Error as IdError, Identifier},
     sys::{
         encoding::{default_encoding, get_encoding, Error as EncodingError},
@@ -43,6 +43,7 @@ use crate::{
     },
 };
 
+use binrw::Endian;
 use encoding_rs::Encoding;
 use flate2::bufread::ZlibDecoder;
 use serde::Serialize;
index 296a0ac73ec0dad73312e2c9ccd3dbf02ec1079e..bd91fc7b3b06e02d0d33aaf6d4ee5eb4999d9a31 100644 (file)
@@ -17,7 +17,7 @@ use crate::{
         Alignment, Attributes, CategoryLabels, Measure, MissingValueRange, MissingValues,
         MissingValuesError, VarType, VarWidth,
     },
-    endian::{Endian, Parse},
+    endian::{Parse},
     format::{DisplayPlainF64, Format, Type},
     identifier::{Error as IdError, Identifier},
     sys::{
@@ -29,7 +29,7 @@ use crate::{
     },
 };
 
-use binrw::{binrw, BinRead, BinWrite, Error as BinError};
+use binrw::{binrw, BinRead, BinWrite, Endian, Error as BinError};
 use clap::ValueEnum;
 use encoding_rs::Encoding;
 use itertools::Itertools;
index 7a8108073d9413fe19de3bb138150bccb8e0cb56..41118e47f6acad64f95ebea2629ca748d72d07ab 100644 (file)
@@ -14,6 +14,7 @@
 // You should have received a copy of the GNU General Public License along with
 // this program.  If not, see <http://www.gnu.org/licenses/>.
 
+use binrw::Endian;
 use num::{Bounded, Zero};
 use ordered_float::OrderedFloat;
 use std::{
@@ -24,7 +25,7 @@ use std::{
     path::{Path, PathBuf},
 };
 
-use crate::endian::{Endian, ToBytes};
+use crate::endian::{ToBytes};
 
 pub type Result<T, F = Error> = std::result::Result<T, F>;
 
@@ -573,9 +574,9 @@ impl<'a> Lexer<'a> {
 
 #[cfg(test)]
 mod test {
-    use crate::endian::Endian;
     use crate::sys::sack::sack;
     use anyhow::Result;
+    use binrw::Endian;
     use hexplay::HexView;
 
     #[test]
index 49f0b94c71538e98034212a75b1228e6cbe6f0b7..5e1446d0dc7ba940a083549e3ff2d02f2f85ea66 100644 (file)
@@ -22,14 +22,14 @@ use std::{
     sync::Arc,
 };
 
+use binrw::Endian;
 use chrono::{NaiveDate, NaiveDateTime, NaiveTime};
 use encoding_rs::UTF_8;
 
 use crate::{
     crypto::EncryptedFile,
-    data::{BorrowedDatum, ByteString, Datum},
+    data::{ByteString, Datum},
     dictionary::{Dictionary, VarWidth, Variable},
-    endian::Endian,
     identifier::Identifier,
     output::{
         pivot::{test::assert_lines_eq, Axis3, Dimension, Group, PivotTable, Value},
@@ -621,7 +621,7 @@ fn write_numeric() {
             cases
                 .write_case(
                     case.into_iter()
-                        .map(|number| BorrowedDatum::Number(Some(number as f64))),
+                        .map(|number| Datum::<&str>::Number(Some(number as f64))),
                 )
                 .unwrap();
         }
@@ -677,7 +677,7 @@ fn write_long_string_value_labels() {
             cases
                 .write_case(
                     case.into_iter()
-                        .map(|number| BorrowedDatum::Number(Some(number as f64))),
+                        .map(|number| Datum::<&str>::Number(Some(number as f64))),
                 )
                 .unwrap();
         }