}
}
-/// 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<f64>,
- ),
- /// 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<Option<f64>> {
- 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<EncodedString<&'a BorrowedRawString>> {
- 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<EncodedString<&'a mut BorrowedRawString>> {
- 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<'_> {
}
}
-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<OwnedRawString>;
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},
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},