From: Ben Pfaff Date: Mon, 28 Jul 2025 17:00:52 +0000 (-0700) Subject: drop default generic X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=26b9d1abd67f7ba2296efeaf53c23cf3336d1b61;p=pspp drop default generic --- diff --git a/rust/pspp/src/data.rs b/rust/pspp/src/data.rs index 727d47786b..581197c438 100644 --- a/rust/pspp/src/data.rs +++ b/rust/pspp/src/data.rs @@ -279,7 +279,7 @@ pub type BorrowedEncodedDatum<'a> = EncodedDatum>; /// The value of a [Variable](crate::dictionary::Variable), with a string /// encoding. #[derive(Clone)] -pub enum EncodedDatum { +pub enum EncodedDatum { /// A numeric value. Number( /// A number, or `None` for the system-missing value. @@ -381,7 +381,7 @@ impl EncodedDatum { } } -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 Display for EncodedDatum +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 Serialize for EncodedDatum +where + D: Serialize, +{ fn serialize(&self, serializer: S) -> Result where S: serde::Serializer, @@ -425,19 +431,19 @@ impl Serialize for EncodedDatum { } } -impl From for EncodedDatum { +impl From for EncodedDatum { fn from(number: f64) -> Self { Some(number).into() } } -impl From> for EncodedDatum { +impl From> for EncodedDatum { fn from(value: Option) -> 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 { - 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>> { - 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.iter diff --git a/rust/pspp/src/dictionary.rs b/rust/pspp/src/dictionary.rs index 411fb24447..9ddd5fde42 100644 --- a/rust/pspp/src/dictionary.rs +++ b/rust/pspp/src/dictionary.rs @@ -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, + values: Vec, /// Optional range of missing values. range: Option, @@ -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, + mut values: Vec, range: Option, ) -> Result { if values.len() > 3 { diff --git a/rust/pspp/src/format/display/test.rs b/rust/pspp/src/format/display/test.rs index 4b2fe81c7d..c65697f9cd 100644 --- a/rust/pspp/src/format/display/test.rs +++ b/rust/pspp/src/format/display/test.rs @@ -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(), diff --git a/rust/pspp/src/sys/write.rs b/rust/pspp/src/sys/write.rs index d3a128d1da..7a808e6996 100644 --- a/rust/pspp/src/sys/write.rs +++ b/rust/pspp/src/sys/write.rs @@ -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 { } } -impl BinWrite for EncodedDatum { +impl BinWrite for OwnedEncodedDatum { type Args<'a> = (); fn write_options(