From: Ben Pfaff Date: Mon, 28 Jul 2025 16:53:32 +0000 (-0700) Subject: get rid of encodeddat X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bf4c676dd6526e51c270047abbc28a91076a7f30;p=pspp get rid of encodeddat --- diff --git a/rust/pspp/src/data.rs b/rust/pspp/src/data.rs index 2bca7c2c99..727d47786b 100644 --- a/rust/pspp/src/data.rs +++ b/rust/pspp/src/data.rs @@ -443,67 +443,6 @@ impl From<&str> for EncodedDatum { } } -/// A borrowed [Datum] with a string encoding. -#[derive(Copy, Clone)] -pub enum EncodedDat<'a> { - /// A numeric value. - Number( - /// A number, or `None` for the system-missing value. - Option, - ), - /// A string value. - String( - /// The value, in the variable's encoding. - BorrowedEncodedString<'a>, - ), -} - -impl<'a> EncodedDat<'a> { - /// Constructs a new numerical [Datum] for the system-missing value. - pub const fn sysmis() -> Self { - Self::Number(None) - } - - /// Returns the number inside this datum, or `None` if this is a string - /// datum. - pub fn as_number(&self) -> Option> { - match self { - Self::Number(number) => Some(*number), - Self::String(_) => None, - } - } - - /// Returns the string inside this datum, or `None` if this is a numeric - /// datum. - pub fn as_string(&self) -> Option> { - match self { - Self::Number(_) => None, - Self::String(s) => Some(*s), - } - } - - /* - /// Returns the string inside this datum as a mutable borrow, or `None` if - /// this is a numeric datum. - pub fn as_string_mut(&'a mut self) -> Option> { - match self { - Self::Number(_) => None, - Self::String(s) => Some(*s), - } - }*/ - - pub fn eq_ignore_trailing_spaces<'b>(&self, other: EncodedDat<'b>) -> bool { - match (self, other) { - (Self::String(a), EncodedDat::String(b)) => a.eq_ignore_trailing_spaces(&b), - _ => *self == other, - } - } - - pub fn quoted(&self) -> QuotedEncodedDatum<'a> { - todo!() - } -} - pub struct QuotedEncodedDatum<'a>(BorrowedEncodedDatum<'a>); impl Display for QuotedEncodedDatum<'_> { @@ -516,31 +455,6 @@ impl Display for QuotedEncodedDatum<'_> { } } -impl Display for EncodedDat<'_> { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - match self { - Self::Number(None) => write!(f, "SYSMIS"), - Self::Number(Some(number)) => number.display_plain().fmt(f), - Self::String(string) => write!(f, "{string}"), - } - } -} - -impl<'a> PartialEq for EncodedDat<'a> { - fn eq(&self, other: &Self) -> bool { - match (self, other) { - (Self::Number(Some(l0)), Self::Number(Some(r0))) => { - OrderedFloat(*l0) == OrderedFloat(*r0) - } - (Self::Number(None), Self::Number(None)) => true, - (Self::String(l0), Self::String(r0)) => l0 == r0, - _ => false, - } - } -} - -impl<'a> Eq for EncodedDat<'a> {} - /// A [Datum] that owns its string data (if any). pub type OwnedDatum = Datum; diff --git a/rust/pspp/src/format/display/mod.rs b/rust/pspp/src/format/display/mod.rs index fe69aba6c6..236ada8b8a 100644 --- a/rust/pspp/src/format/display/mod.rs +++ b/rust/pspp/src/format/display/mod.rs @@ -31,8 +31,7 @@ use smallvec::{Array, SmallVec}; use crate::{ calendar::{calendar_offset_to_gregorian, day_of_year, month_name, short_month_name}, data::{ - BorrowedEncodedDatum, BorrowedRawString, EncodedDat, EncodedDatum, EncodedString, - QuotedEncodedDatum, + BorrowedEncodedDatum, BorrowedRawString, EncodedDatum, EncodedString, QuotedEncodedDatum, }, endian::{endian_to_smallvec, ToBytes}, format::{Category, DateTemplate, Decimal, Format, NumberStyle, Settings, TemplateItem, Type}, diff --git a/rust/pspp/src/output/pivot/mod.rs b/rust/pspp/src/output/pivot/mod.rs index 1d6cd96d22..f55df6c141 100644 --- a/rust/pspp/src/output/pivot/mod.rs +++ b/rust/pspp/src/output/pivot/mod.rs @@ -69,8 +69,7 @@ use tlo::parse_tlo; use crate::{ data::{ - BorrowedRawString, Datum, EncodedDat, EncodedDatum, EncodedString, OwnedEncodedDatum, - OwnedRawString, + BorrowedRawString, Datum, EncodedDatum, EncodedString, OwnedEncodedDatum, OwnedRawString, }, dictionary::{VarType, Variable}, format::{Decimal, Format, Settings as FormatSettings, Type, UncheckedFormat},