a little cleanup
authorBen Pfaff <blp@cs.stanford.edu>
Sat, 2 Aug 2025 16:34:05 +0000 (09:34 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Sat, 2 Aug 2025 16:34:05 +0000 (09:34 -0700)
rust/pspp/src/data.rs
rust/pspp/src/data/encoded.rs
rust/pspp/src/dictionary.rs
rust/pspp/src/format/display/mod.rs
rust/pspp/src/format/parse.rs
rust/pspp/src/output/pivot/mod.rs
rust/pspp/src/sys/cooked.rs
rust/pspp/src/sys/test.rs
rust/pspp/src/sys/write.rs

index 02e0c8cb5c94bc03d6fd63d4b352efca3095dffd..72024799659ee141b165ecd177361cef131abbd8 100644 (file)
@@ -48,7 +48,7 @@ use crate::{
     format::DisplayPlain,
 };
 
-pub trait RawStringTrait: Debug + PartialEq + Eq + PartialOrd + Ord + Hash {
+pub trait RawString: Debug + PartialEq + Eq + PartialOrd + Ord + Hash {
     fn raw_string_bytes(&self) -> &[u8];
 
     /// Compares this string and `other` for equality, ignoring trailing ASCII
@@ -59,7 +59,7 @@ pub trait RawStringTrait: Debug + PartialEq + Eq + PartialOrd + Ord + Hash {
     /// known).
     fn eq_ignore_trailing_spaces<R>(&self, other: &R) -> bool
     where
-        R: RawStringTrait,
+        R: RawString,
     {
         self.raw_string_bytes()
             .iter()
@@ -108,24 +108,24 @@ pub trait RawStringTrait: Debug + PartialEq + Eq + PartialOrd + Ord + Hash {
     }
 }
 
-pub trait MutRawString: RawStringTrait {
+pub trait MutRawString: RawString {
     fn resize(&mut self, new_len: usize) -> Result<(), ResizeError>;
     fn trim_end(&mut self);
 }
 
-impl RawStringTrait for &'_ str {
+impl RawString for &'_ str {
     fn raw_string_bytes(&self) -> &[u8] {
         self.as_bytes()
     }
 }
 
-impl RawStringTrait for String {
+impl RawString for String {
     fn raw_string_bytes(&self) -> &[u8] {
         self.as_bytes()
     }
 }
 
-impl RawStringTrait for &'_ String {
+impl RawString for &'_ String {
     fn raw_string_bytes(&self) -> &[u8] {
         self.as_bytes()
     }
@@ -134,7 +134,7 @@ impl RawStringTrait for &'_ String {
 #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
 pub struct ByteStr<'a>(pub &'a [u8]);
 
-impl RawStringTrait for ByteStr<'_> {
+impl RawString for ByteStr<'_> {
     fn raw_string_bytes(&self) -> &[u8] {
         self.0
     }
@@ -190,7 +190,7 @@ impl Serialize for ByteCow<'_> {
     }
 }
 
-impl RawStringTrait for ByteCow<'_> {
+impl RawString for ByteCow<'_> {
     fn raw_string_bytes(&self) -> &[u8] {
         &self.0
     }
@@ -242,7 +242,7 @@ impl<const N: usize> From<[u8; N]> for ByteString {
     }
 }
 
-impl RawStringTrait for ByteString {
+impl RawString for ByteString {
     fn raw_string_bytes(&self) -> &[u8] {
         self.0.as_slice()
     }
@@ -303,7 +303,7 @@ impl MutRawString for ByteString {
 }
 
 mod encoded;
-pub use encoded::{Encoded, EncodedStringTrait, WithEncoding};
+pub use encoded::{Encoded, EncodedString, WithEncoding};
 
 /// A [Datum] that owns its string data (if any).
 pub type OwnedDatum = Datum<WithEncoding<ByteString>>;
@@ -349,7 +349,7 @@ impl<'a> Datum<WithEncoding<ByteCow<'a>>> {
 
 impl<T> Datum<T>
 where
-    T: EncodedStringTrait,
+    T: EncodedString,
 {
     pub fn as_borrowed(&self) -> Datum<WithEncoding<ByteStr<'_>>> {
         match self {
@@ -496,7 +496,7 @@ impl<B> Datum<B> {
 
 impl<T> Datum<T>
 where
-    T: RawStringTrait,
+    T: RawString,
 {
     /// Returns true if this datum can be resized to the given `width` without
     /// loss, which is true only if this datum and `width` are both string or
@@ -523,7 +523,7 @@ where
     /// comparison.
     pub fn eq_ignore_trailing_spaces<R>(&self, other: &Datum<R>) -> bool
     where
-        R: RawStringTrait,
+        R: RawString,
     {
         match (self, other) {
             (Self::String(a), Datum::String(b)) => a.eq_ignore_trailing_spaces(b),
@@ -549,7 +549,7 @@ where
 
 impl<B> Datum<B>
 where
-    B: EncodedStringTrait,
+    B: EncodedString,
 {
     pub fn quoted<'a>(&'a self) -> QuotedDatum<'a, B> {
         QuotedDatum(self)
index 7e3262730b0acb030c697c8f78d2d6e69b4808e7..a12eccb9bf15bfc8fbdbe628706139d75383c9c6 100644 (file)
@@ -8,9 +8,7 @@ use std::{
 use encoding_rs::{Encoding, UTF_8};
 use serde::Serialize;
 
-use crate::data::{
-    ByteCow, ByteStr, ByteString, MutRawString, Quoted, RawStringTrait, ResizeError,
-};
+use crate::data::{ByteCow, ByteStr, ByteString, MutRawString, Quoted, RawString, ResizeError};
 
 pub trait Encoded {
     fn encoding(&self) -> &'static Encoding;
@@ -76,7 +74,7 @@ where
 
 impl<T> Serialize for WithEncoding<T>
 where
-    WithEncoding<T>: EncodedStringTrait,
+    WithEncoding<T>: EncodedString,
 {
     fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
     where
@@ -86,7 +84,7 @@ where
     }
 }
 
-pub trait EncodedStringTrait: Encoded + RawStringTrait + Display + Debug {
+pub trait EncodedString: Encoded + RawString + Display + Debug {
     fn as_str(&self) -> Cow<'_, str>;
     fn into_string(self) -> String
     where
@@ -109,7 +107,7 @@ pub trait EncodedStringTrait: Encoded + RawStringTrait + Display + Debug {
     }
 }
 
-impl<'a> EncodedStringTrait for &'a str {
+impl<'a> EncodedString for &'a str {
     fn as_str(&self) -> Cow<'_, str> {
         Cow::from(*self)
     }
@@ -119,7 +117,7 @@ impl<'a> EncodedStringTrait for &'a str {
     }
 }
 
-impl EncodedStringTrait for String {
+impl EncodedString for String {
     fn as_str(&self) -> Cow<'_, str> {
         Cow::from(String::as_str(&self))
     }
@@ -129,7 +127,7 @@ impl EncodedStringTrait for String {
     }
 }
 
-impl EncodedStringTrait for &'_ String {
+impl EncodedString for &'_ String {
     fn as_str(&self) -> Cow<'_, str> {
         Cow::from(String::as_str(&self))
     }
@@ -139,9 +137,9 @@ impl EncodedStringTrait for &'_ String {
     }
 }
 
-impl<T> RawStringTrait for WithEncoding<T>
+impl<T> RawString for WithEncoding<T>
 where
-    T: RawStringTrait,
+    T: RawString,
 {
     fn raw_string_bytes(&self) -> &[u8] {
         self.inner.raw_string_bytes()
@@ -161,9 +159,9 @@ where
     }
 }
 
-impl<T> EncodedStringTrait for WithEncoding<T>
+impl<T> EncodedString for WithEncoding<T>
 where
-    T: RawStringTrait,
+    T: RawString,
 {
     /// Returns this string recoded in UTF-8.  Invalid characters will be
     /// replaced by [REPLACEMENT_CHARACTER].
@@ -203,7 +201,7 @@ impl<T> Encoded for WithEncoding<T> {
 
 impl<T> Display for WithEncoding<T>
 where
-    T: RawStringTrait,
+    T: RawString,
 {
     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
         f.write_str(&self.as_str())
index d45ff5614174f3930377dceb472d3e35188908ef..2d206eb8ad9159dc257c5a05f11afcddfdf926e0 100644 (file)
@@ -40,7 +40,7 @@ use thiserror::Error as ThisError;
 use unicase::UniCase;
 
 use crate::{
-    data::{ByteString, Datum, EncodedStringTrait, ResizeError, WithEncoding},
+    data::{ByteString, Datum, EncodedString, ResizeError, WithEncoding},
     format::{DisplayPlain, Format},
     identifier::{ByIdentifier, HasIdentifier, Identifier},
     output::pivot::{
@@ -2137,7 +2137,7 @@ impl MissingValues {
 
     pub fn contains<S>(&self, value: &Datum<S>) -> bool
     where
-        S: EncodedStringTrait,
+        S: EncodedString,
     {
         if self
             .values
index 337d5136d56ba90b6629b3eff412e5bb09a201bb..af86b33889a80493ab5de3a7ed2f462d7590ab96 100644 (file)
@@ -29,7 +29,7 @@ use smallvec::{Array, SmallVec};
 
 use crate::{
     calendar::{calendar_offset_to_gregorian, day_of_year, month_name, short_month_name},
-    data::{ByteStr, Datum, EncodedStringTrait, QuotedDatum, WithEncoding},
+    data::{ByteStr, Datum, EncodedString, QuotedDatum, WithEncoding},
     endian::{endian_to_smallvec, ToBytes},
     format::{Category, DateTemplate, Decimal, Format, NumberStyle, Settings, TemplateItem, Type},
     settings::{EndianSettings, Settings as PsppSettings},
@@ -82,27 +82,9 @@ impl Display for DisplayPlainF64 {
     }
 }
 
-/*
-impl<R> EncodedDatum<EncodedString<R>>
-where
-    R: Borrow<BorrowedRawString>,
-{
-    /// Returns an object that implements [Display] for printing this
-    /// [EncodedDatum] as `format`.
-    ///
-    /// [Display]: std::fmt::Display
-    pub fn display(&self, format: Format) -> DisplayDatum {
-        DisplayDatum::new(format, self.borrowed())
-    }
-
-    pub fn display_plain(&self) -> QuotedEncodedDatum<'_> {
-        self.quoted()
-    }
-}*/
-
 impl<'a, D> Datum<D>
 where
-    D: EncodedStringTrait,
+    D: EncodedString,
 {
     /// Returns an object that implements [Display] for printing this
     /// [EncodedDatum] as `format`.
@@ -119,7 +101,7 @@ where
 
 impl<'a, 'b, B> Display for DisplayDatum<'b, B>
 where
-    B: EncodedStringTrait,
+    B: EncodedString,
 {
     fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
         let number = match &self.datum {
@@ -184,7 +166,7 @@ where
 
 impl<'b, B> DisplayDatum<'b, B>
 where
-    B: EncodedStringTrait,
+    B: EncodedString,
 {
     pub fn new(format: Format, datum: Datum<B>) -> Self {
         let settings = PsppSettings::global();
index 8a2a3c9c6b9364952ddcedfd6d8a3243bce4ee55..b97e280ba926bcd7f03e87a54da0b0db47d86273 100644 (file)
@@ -16,7 +16,7 @@
 
 use crate::{
     calendar::{calendar_gregorian_to_offset, DateError},
-    data::{ByteString, Datum, EncodedStringTrait, OwnedDatum, RawStringTrait, WithEncoding},
+    data::{ByteString, Datum, EncodedString, OwnedDatum, RawString, WithEncoding},
     endian::{Endian, Parse},
     format::{DateTemplate, Decimals, Settings, TemplateItem, Type},
     settings::{EndianSettings, Settings as PsppSettings},
@@ -190,7 +190,7 @@ impl<'a> ParseValue<'a> {
     /// input into UTF-8, but this will screw up parsing of binary formats,
     /// because recoding bytes from (e.g.) windows-1252 into UTF-8, and then
     /// interpreting them as a binary number yields nonsense.
-    pub fn parse(&self, input: impl EncodedStringTrait) -> Result<OwnedDatum, ParseError> {
+    pub fn parse(&self, input: impl EncodedString) -> Result<OwnedDatum, ParseError> {
         if input.is_empty() {
             return Ok(self
                 .type_
@@ -921,7 +921,7 @@ mod test {
 
     use crate::{
         calendar::{days_in_month, is_leap_year},
-        data::{ByteStr, Datum, EncodedStringTrait, OwnedDatum, RawStringTrait},
+        data::{ByteStr, Datum, EncodedString, OwnedDatum, RawString},
         endian::Endian,
         format::{
             parse::{ParseError, ParseErrorKind, Sign},
index 1361765dec6be57878e35f61d504c6f82f6a4fc1..7dd634f18a31ee79c0222c217ee3a496fad5317e 100644 (file)
@@ -67,7 +67,7 @@ use thiserror::Error as ThisError;
 use tlo::parse_tlo;
 
 use crate::{
-    data::{ByteString, Datum, EncodedStringTrait, RawStringTrait},
+    data::{ByteString, Datum, EncodedString, RawString},
     dictionary::{VarType, Variable},
     format::{Decimal, Format, Settings as FormatSettings, Type, UncheckedFormat},
     settings::{Settings, Show},
@@ -1861,7 +1861,7 @@ impl Value {
     }
     pub fn new_datum<B>(value: &Datum<B>) -> Self
     where
-        B: EncodedStringTrait,
+        B: EncodedString,
     {
         match value {
             Datum::Number(number) => Self::new_number(*number),
index 044985146fbfe23ed490bcf3c7bb901d8d270ac7..24d5c887bd43876ab371ca288ccd8a1a0d661edd 100644 (file)
@@ -26,7 +26,7 @@ use std::{
 use crate::{
     calendar::date_time_to_pspp,
     crypto::EncryptedFile,
-    data::{ByteString, Case, Datum, MutRawString, RawStringTrait},
+    data::{ByteString, Case, Datum, MutRawString, RawString},
     dictionary::{
         DictIndexMultipleResponseSet, DictIndexVariableSet, Dictionary, InvalidRole, MissingValues,
         MissingValuesError, MultipleResponseType, VarWidth, Variable,
index 1b5fe0f193a8ae649e7264f719621733fc60bbaf..49f0b94c71538e98034212a75b1228e6cbe6f0b7 100644 (file)
@@ -27,7 +27,7 @@ use encoding_rs::UTF_8;
 
 use crate::{
     crypto::EncryptedFile,
-    data::{BorrowedDatum, ByteString, Datum, OwnedDatum},
+    data::{BorrowedDatum, ByteString, Datum},
     dictionary::{Dictionary, VarWidth, Variable},
     endian::Endian,
     identifier::Identifier,
index 4c59603c73c7f58e22b9292aea43993d302e59bb..d7d7b84dfe92bc565e3b4d0299223252af1555bd 100644 (file)
@@ -17,7 +17,7 @@ use itertools::zip_eq;
 use smallvec::SmallVec;
 
 use crate::{
-    data::{Datum, RawStringTrait},
+    data::{Datum, RawString},
     dictionary::{
         Alignment, Attributes, CategoryLabels, Dictionary, Measure, MultipleResponseType,
         ValueLabels, VarWidth,
@@ -713,7 +713,7 @@ impl BinWrite for Pad {
 
 impl<B> BinWrite for Datum<B>
 where
-    B: RawStringTrait,
+    B: RawString,
 {
     type Args<'a> = ();
 
@@ -873,7 +873,7 @@ where
         case: impl Iterator<Item = Datum<B>>,
     ) -> Result<(), BinError>
     where
-        B: RawStringTrait,
+        B: RawString,
     {
         for (var, datum) in zip_eq(self.case_vars, case) {
             match var {
@@ -899,7 +899,7 @@ where
         case: impl Iterator<Item = Datum<B>>,
     ) -> Result<(), BinError>
     where
-        B: RawStringTrait,
+        B: RawString,
     {
         for (var, datum) in zip_eq(self.case_vars, case) {
             match var {
@@ -1028,7 +1028,7 @@ where
         case: impl IntoIterator<Item = Datum<B>>,
     ) -> Result<(), BinError>
     where
-        B: RawStringTrait,
+        B: RawString,
     {
         match self.inner.as_mut().unwrap() {
             Either::Left(inner) => {