drop default generic
authorBen Pfaff <blp@cs.stanford.edu>
Mon, 28 Jul 2025 17:00:52 +0000 (10:00 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Mon, 28 Jul 2025 17:00:52 +0000 (10:00 -0700)
rust/pspp/src/data.rs
rust/pspp/src/dictionary.rs
rust/pspp/src/format/display/test.rs
rust/pspp/src/sys/write.rs

index 727d47786b9df40498cce89bd5e5ca4be625fd80..581197c4380d8d29e184ca960870dcdae1ef0d31 100644 (file)
@@ -279,7 +279,7 @@ pub type BorrowedEncodedDatum<'a> = EncodedDatum<BorrowedEncodedString<'a>>;
 /// The value of a [Variable](crate::dictionary::Variable), with a string
 /// encoding.
 #[derive(Clone)]
-pub enum EncodedDatum<D = OwnedEncodedString> {
+pub enum EncodedDatum<D> {
     /// A numeric value.
     Number(
         /// A number, or `None` for the system-missing value.
@@ -381,7 +381,7 @@ impl<D> EncodedDatum<D> {
     }
 }
 
-impl EncodedDatum {
+impl OwnedEncodedDatum {
     /// Resizes this datum to the given `width`.  Returns `Ok(())` if
     /// successful, if and only if this datum and `width` are both string or
     /// both numeric and, for string widths, resizing would not drop any
@@ -403,7 +403,10 @@ impl EncodedDatum {
     }
 }
 
-impl Display for EncodedDatum {
+impl<D> Display for EncodedDatum<D>
+where
+    D: Display,
+{
     fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
         match self {
             Self::Number(None) => write!(f, "SYSMIS"),
@@ -413,7 +416,10 @@ impl Display for EncodedDatum {
     }
 }
 
-impl Serialize for EncodedDatum {
+impl<D> Serialize for EncodedDatum<D>
+where
+    D: Serialize,
+{
     fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
     where
         S: serde::Serializer,
@@ -425,19 +431,19 @@ impl Serialize for EncodedDatum {
     }
 }
 
-impl From<f64> for EncodedDatum {
+impl<D> From<f64> for EncodedDatum<D> {
     fn from(number: f64) -> Self {
         Some(number).into()
     }
 }
 
-impl From<Option<f64>> for EncodedDatum {
+impl<D> From<Option<f64>> for EncodedDatum<D> {
     fn from(value: Option<f64>) -> Self {
         Self::Number(value)
     }
 }
 
-impl From<&str> for EncodedDatum {
+impl From<&str> for OwnedEncodedDatum {
     fn from(value: &str) -> Self {
         Self::String(OwnedEncodedString::from(value))
     }
@@ -691,7 +697,7 @@ where
 }
 
 impl Datum<OwnedRawString> {
-    pub fn with_encoding(self, encoding: &'static Encoding) -> EncodedDatum {
+    pub fn with_encoding(self, encoding: &'static Encoding) -> OwnedEncodedDatum {
         match self {
             Datum::Number(number) => EncodedDatum::Number(number),
             Datum::String(raw_string) => EncodedDatum::String(raw_string.with_encoding(encoding)),
@@ -778,7 +784,7 @@ where
 }
 
 impl IntoIterator for Case<Vec<Datum<OwnedRawString>>> {
-    type Item = EncodedDatum;
+    type Item = OwnedEncodedDatum;
 
     type IntoIter = CaseVecIter;
 
@@ -796,7 +802,7 @@ pub struct CaseVecIter {
 }
 
 impl Iterator for CaseVecIter {
-    type Item = EncodedDatum;
+    type Item = OwnedEncodedDatum;
 
     fn next(&mut self) -> Option<Self::Item> {
         self.iter
index 411fb244474f11b647ac168507e0ecf775e66445..9ddd5fde4228304f872141168942240c7dfc005f 100644 (file)
@@ -40,7 +40,7 @@ use thiserror::Error as ThisError;
 use unicase::UniCase;
 
 use crate::{
-    data::{BorrowedEncodedDatum, Datum, EncodedDatum, OwnedRawString},
+    data::{BorrowedEncodedDatum, Datum, OwnedEncodedDatum, OwnedRawString},
     format::{DisplayPlain, Format},
     identifier::{ByIdentifier, HasIdentifier, Identifier},
     output::pivot::{
@@ -1957,7 +1957,7 @@ impl Hash for ValueLabels {
 #[derive(Clone, Default, Serialize)]
 pub struct MissingValues {
     /// Individual missing values, up to 3 of them.
-    values: Vec<EncodedDatum>,
+    values: Vec<OwnedEncodedDatum>,
 
     /// Optional range of missing values.
     range: Option<MissingValueRange>,
@@ -2003,7 +2003,7 @@ impl MissingValues {
     pub fn clear(&mut self) {
         *self = Self::default();
     }
-    pub fn values(&self) -> &[EncodedDatum] {
+    pub fn values(&self) -> &[OwnedEncodedDatum] {
         &self.values
     }
 
@@ -2012,7 +2012,7 @@ impl MissingValues {
     }
 
     pub fn new(
-        mut values: Vec<EncodedDatum>,
+        mut values: Vec<OwnedEncodedDatum>,
         range: Option<MissingValueRange>,
     ) -> Result<Self, MissingValuesError> {
         if values.len() > 3 {
index 4b2fe81c7d95e25940aa4ab385c7c63e9d5eff9e..c65697f9cdceca38ce00220b152ce00eb6238fb0 100644 (file)
@@ -23,7 +23,7 @@ use smallstr::SmallString;
 use smallvec::SmallVec;
 
 use crate::{
-    data::{EncodedDatum, OwnedEncodedDatum},
+    data::OwnedEncodedDatum,
     endian::Endian,
     format::{AbstractFormat, Epoch, Format, Settings, Type, UncheckedFormat, CC},
     lex::{scan::StringScanner, segment::Syntax, Punct, Token},
@@ -183,7 +183,7 @@ fn leading_zeros() {
         }
 
         fn test_with_settings(value: f64, expected: [&str; 2], settings: &Settings) {
-            let value = EncodedDatum::from(value);
+            let value = OwnedEncodedDatum::from(value);
             for (expected, d) in expected.into_iter().zip([2, 1].into_iter()) {
                 assert_eq!(
                     &value
@@ -214,7 +214,7 @@ fn leading_zeros() {
 fn non_ascii_cc() {
     fn test(settings: &Settings, value: f64, expected: &str) {
         assert_eq!(
-            &EncodedDatum::from(value)
+            &OwnedEncodedDatum::from(value)
                 .display(Format::new(Type::CC(CC::A), 10, 2).unwrap())
                 .with_settings(settings)
                 .to_string(),
index d3a128d1da9f79d63744561d1da35fabf4ea174a..7a808e699657061a182cccb66e3794a846b029f8 100644 (file)
@@ -1,5 +1,5 @@
 use std::{
-    borrow::{Cow},
+    borrow::Cow,
     collections::HashMap,
     fmt::Write as _,
     fs::File,
@@ -17,7 +17,7 @@ use itertools::zip_eq;
 use smallvec::SmallVec;
 
 use crate::{
-    data::{Datum, EncodedDatum, OwnedRawString, },
+    data::{Datum, OwnedEncodedDatum, OwnedRawString},
     dictionary::{
         Alignment, Attributes, CategoryLabels, Dictionary, Measure, MultipleResponseType,
         ValueLabels, VarWidth,
@@ -690,7 +690,7 @@ impl BinWrite for Datum<OwnedRawString> {
     }
 }
 
-impl BinWrite for EncodedDatum {
+impl BinWrite for OwnedEncodedDatum {
     type Args<'a> = ();
 
     fn write_options<W: Write + Seek>(