endian::Endian,
format::{Error as FormatError, Spec, UncheckedSpec},
identifier::{Error as IdError, Identifier},
- raw::{self, UnencodedStr, VarType},
+ raw::{self, RawStr, RawString, VarType},
};
use chrono::{NaiveDate, NaiveDateTime, NaiveTime};
use encoding_rs::{DecoderResult, Encoding};
#[derive(Default)]
struct Headers<'a> {
- header: Option<&'a raw::HeaderRecord>,
- variables: Vec<&'a raw::VariableRecord>,
- value_labels: Vec<&'a raw::ValueLabelRecord>,
+ header: Option<&'a raw::HeaderRecord<RawString>>,
+ variables: Vec<&'a raw::VariableRecord<RawString, RawStr<8>>>,
+ value_labels: Vec<&'a raw::ValueLabelRecord<RawStr<8>, RawString>>,
document: Option<&'a raw::DocumentRecord>,
integer_info: Option<&'a raw::IntegerInfoRecord>,
float_info: Option<&'a raw::FloatInfoRecord>,
fn decode(decoder: &Decoder, input: &Input, warn: impl Fn(Error)) -> Self;
}
-impl<const N: usize> Decode<UnencodedStr<N>> for String {
- fn decode(decoder: &Decoder, input: &UnencodedStr<N>, warn: impl Fn(Error)) -> Self {
+impl<const N: usize> Decode<RawStr<N>> for String {
+ fn decode(decoder: &Decoder, input: &RawStr<N>, warn: impl Fn(Error)) -> Self {
decoder.decode_string(&input.0, &warn)
}
}
}
impl TryDecode for HeaderRecord {
- type Input = crate::raw::HeaderRecord;
+ type Input = crate::raw::HeaderRecord<RawString>;
fn try_decode(
decoder: &mut Decoder,
pub range: Option<(Value, Value)>,
}
-impl Decode<raw::MissingValues> for MissingValues {
- fn decode(decoder: &Decoder, input: &raw::MissingValues, _warn: impl Fn(Error)) -> Self {
+impl Decode<raw::MissingValues<RawStr<8>>> for MissingValues {
+ fn decode(
+ decoder: &Decoder,
+ input: &raw::MissingValues<RawStr<8>>,
+ _warn: impl Fn(Error),
+ ) -> Self {
MissingValues {
values: input
.values
}
impl TryDecode for VariableRecord {
- type Input = raw::VariableRecord;
+ type Input = raw::VariableRecord<RawString, RawStr<8>>;
fn try_decode(
decoder: &mut Decoder,
- input: &crate::raw::VariableRecord,
+ input: &Self::Input,
warn: impl Fn(Error),
) -> Result<Option<VariableRecord>, Error> {
let width = match input.width {
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum Value {
Number(Option<OrderedFloat<f64>>),
- String(Box<str>),
+ String(String),
}
impl Value {
- pub fn decode(raw: &raw::Value, decoder: &Decoder) -> Self {
+ pub fn decode(raw: &raw::Value<RawStr<8>>, decoder: &Decoder) -> Self {
match raw {
raw::Value::Number(x) => Value::Number(x.map(|x| x.into())),
raw::Value::String(s) => Value::String(decoder.decode_exact_length(&s.0).into()),
}
impl TryDecode for ValueLabelRecord {
- type Input = crate::raw::ValueLabelRecord;
+ type Input = crate::raw::ValueLabelRecord<RawStr<8>, RawString>;
fn try_decode(
decoder: &mut Decoder,
input: &Self::Input,
let labels = input
.labels
.iter()
- .map(|(value, label)| {
+ .map(|raw::ValueLabel { value, label }| {
let label = decoder.decode_string(&label.0, &warn);
let value = Value::decode(
- &raw::Value::from_raw(value, var_type, decoder.endian),
+ value,
decoder,
);
ValueLabel { value, label }