}
}
- pub fn as_raw(&self) -> Dat<'_> {
- match self {
- EncodedDatum::Number(number) => Dat::Number(*number),
- EncodedDatum::String(encoded_string) => {
- Dat::String(RawStr::from_bytes(encoded_string.as_bytes()))
- }
- }
- }
-
/// Constructs a new numerical [EncodedDatum] for the system-missing value.
pub const fn sysmis() -> Self {
Self::Number(None)
impl<'a> Eq for EncodedDat<'a> {}
-/// A borrowed [Datum].
-#[derive(Clone)]
-pub enum Dat<'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.
- &'a RawStr,
- ),
-}
-
-impl Dat<'_> {
- /// 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<&RawStr> {
- match self {
- Self::Number(_) => None,
- Self::String(s) => Some(s),
- }
- }
-
- pub fn as_encoded<'a>(&'a self, encoding: &'static Encoding) -> EncodedDat<'a> {
- match self {
- Self::Number(number) => EncodedDat::Number(*number),
- Self::String(raw_string) => EncodedDat::String(raw_string.as_encoded(encoding)),
- }
- }
-
- /// Returns the [VarType] corresponding to this datum.
- pub fn var_type(&self) -> VarType {
- match self {
- Self::Number(_) => VarType::Numeric,
- Self::String(_) => VarType::String,
- }
- }
-
- /// Returns the [VarWidth] corresponding to this datum.
- pub fn width(&self) -> VarWidth {
- match self {
- Self::Number(_) => VarWidth::Numeric,
- Self::String(s) => VarWidth::String(s.len().try_into().unwrap()),
- }
- }
-}
-
/// The value of a [Variable](crate::dictionary::Variable).
#[derive(Clone)]
pub enum Datum<B>
use smallvec::SmallVec;
use crate::{
- data::{Dat, Datum, EncodedDatum, RawStr, RawString},
+ data::{Datum, EncodedDatum, RawStr, RawString},
dictionary::{
Alignment, Attributes, CategoryLabels, Dictionary, Measure, MultipleResponseType,
ValueLabels, VarWidth,