From 7ca1ebff463429cd4f0bbda8285238f8e9e54d64 Mon Sep 17 00:00:00 2001 From: Uwe Klotz Date: Wed, 6 Oct 2021 17:54:46 +0200 Subject: [PATCH] Remove some type aliases --- crates/msr-core/src/register/mod.rs | 2 - crates/msr-core/src/register/recording.rs | 61 +++++++++++++---------- 2 files changed, 34 insertions(+), 29 deletions(-) diff --git a/crates/msr-core/src/register/mod.rs b/crates/msr-core/src/register/mod.rs index b32109a..4f453ae 100644 --- a/crates/msr-core/src/register/mod.rs +++ b/crates/msr-core/src/register/mod.rs @@ -2,8 +2,6 @@ use std::fmt; use crate::{time::SystemTimeInstant, Measurement}; -pub use crate::{Value, ValueType as Type}; - #[cfg(feature = "csv-register-recording")] pub mod recording; diff --git a/crates/msr-core/src/register/recording.rs b/crates/msr-core/src/register/recording.rs index e75596e..6f90e22 100644 --- a/crates/msr-core/src/register/recording.rs +++ b/crates/msr-core/src/register/recording.rs @@ -20,15 +20,15 @@ use crate::{ StorageConfig, StorageDescriptor, StorageStatistics, WritableRecordPrelude, }, time::SystemTimeInstant, - ScalarType, ScalarValue, ToValueType, + ScalarType, ScalarValue, ToValueType, Value, ValueType, }; #[derive(Error, Debug)] pub enum Error { #[error("mismatching register types: expected = {expected:?}, actual = {actual:?}")] MismatchingRegisterTypes { - expected: register::Type, - actual: register::Type, + expected: ValueType, + actual: ValueType, }, #[error(transparent)] @@ -178,31 +178,38 @@ fn deserialize_scalar_value() { ); } -impl From for SerdeRegisterValue { - fn from(from: register::Value) -> Self { - use register::Value as R; +impl From for SerdeRegisterValue { + fn from(from: ScalarValue) -> Self { use ScalarValue as S; match from { - R::Scalar(val) => match val { - S::Bool(val) => Self::Bool(val), - S::I8(val) => Self::I64(i64::from(val)), - S::U8(val) => Self::U64(u64::from(val)), - S::I16(val) => Self::I64(i64::from(val)), - S::U16(val) => Self::U64(u64::from(val)), - S::I32(val) => Self::I64(i64::from(val)), - S::U32(val) => Self::U64(u64::from(val)), - S::F32(val) => Self::F64(f64::from(val)), - S::I64(val) => Self::I64(val), - S::U64(val) => Self::U64(val), - S::F64(val) => Self::F64(val), - }, - R::String(val) => Self::String(val), - _ => unimplemented!(), + S::Bool(val) => Self::Bool(val), + S::I8(val) => Self::I64(i64::from(val)), + S::U8(val) => Self::U64(u64::from(val)), + S::I16(val) => Self::I64(i64::from(val)), + S::U16(val) => Self::U64(u64::from(val)), + S::I32(val) => Self::I64(i64::from(val)), + S::U32(val) => Self::U64(u64::from(val)), + S::F32(val) => Self::F64(f64::from(val)), + S::I64(val) => Self::I64(val), + S::U64(val) => Self::U64(val), + S::F64(val) => Self::F64(val), + } + } +} + +impl From for SerdeRegisterValue { + fn from(from: Value) -> Self { + use Value as V; + match from { + V::Scalar(val) => Self::from(val), + V::String(val) => Self::String(val), + V::Duration(_) => unimplemented!(), + V::Bytes(_) => unimplemented!(), } } } -impl From for register::Value { +impl From for crate::Value { fn from(from: SerdeRegisterValue) -> Self { use ScalarValue as S; use SerdeRegisterValue::*; @@ -263,7 +270,7 @@ impl WritableRecordPrelude for StorageRecord { } struct StorageRecordDeserializer { - registers: Vec<(register::Index, register::Type)>, + registers: Vec<(register::Index, ValueType)>, } #[derive(thiserror::Error, Debug)] @@ -314,7 +321,7 @@ impl csv::StringRecordDeserializer for StorageRecordDeserializer continue; } let parsed_record_field = match register_type { - register::Type::Scalar(t) => match t { + ValueType::Scalar(t) => match t { ScalarType::Bool => record_field .parse::() .map(SerdeRegisterValue::Bool) @@ -353,7 +360,7 @@ impl csv::StringRecordDeserializer for StorageRecordDeserializer .map_err(|err| err.to_string()), _ => unimplemented!(), }, - register::Type::String => record_field + ValueType::String => record_field .parse::() .map(SerdeRegisterValue::String) .map_err(|err| err.to_string()), @@ -436,14 +443,14 @@ where #[allow(missing_debug_implementations)] pub struct CsvFileRecordStorage { - register_types: Vec, + register_types: Vec, inner: csv::FileRecordStorageWithDeserializer, } impl CsvFileRecordStorage { pub fn try_new(config: StorageConfig, base_path: PathBuf, registers_iter: I) -> Result where - I: IntoIterator, + I: IntoIterator, { let file_name_template = RollingFileNameTemplate { prefix: "record_".to_string(),