diff --git a/benches/main.rs b/benches/main.rs index ba2b781..59c762c 100644 --- a/benches/main.rs +++ b/benches/main.rs @@ -14,36 +14,36 @@ pub fn key_reading(c: &mut Criterion) { let msg = handle.next().unwrap().unwrap(); c.bench_function("long reading", |b| { - b.iter(|| msg.read_key(black_box("dataDate")).unwrap()) + b.iter(|| msg.read_key_dynamic(black_box("dataDate")).unwrap()) }); c.bench_function("double reading", |b| { b.iter(|| { - msg.read_key(black_box("jDirectionIncrementInDegrees")) + msg.read_key_dynamic(black_box("jDirectionIncrementInDegrees")) .unwrap() }) }); c.bench_function("double array reading", |b| { - b.iter(|| msg.read_key(black_box("values")).unwrap()) + b.iter(|| msg.read_key_dynamic(black_box("values")).unwrap()) }); c.bench_function("string reading", |b| { - b.iter(|| msg.read_key(black_box("name")).unwrap()) + b.iter(|| msg.read_key_dynamic(black_box("name")).unwrap()) }); c.bench_function("bytes reading", |b| { - b.iter(|| msg.read_key(black_box("section1Padding")).unwrap()) + b.iter(|| msg.read_key_dynamic(black_box("section1Padding")).unwrap()) }); c.bench_function("missing nul-byte termination reading", |b| { - b.iter(|| msg.read_key(black_box("experimentVersionNumber")).unwrap()) + b.iter(|| msg.read_key_dynamic(black_box("experimentVersionNumber")).unwrap()) }); c.bench_function("problematic key reading", |b| { b.iter(|| { - msg.read_key(black_box("zero")) - .unwrap_or_else(|_| msg.read_key(black_box("zeros")).unwrap()) + msg.read_key_dynamic(black_box("zero")) + .unwrap_or_else(|_| msg.read_key_dynamic(black_box("zeros")).unwrap()) }) }); } diff --git a/src/codes_handle/iterator.rs b/src/codes_handle/iterator.rs index 79cfe4c..34068e1 100644 --- a/src/codes_handle/iterator.rs +++ b/src/codes_handle/iterator.rs @@ -91,7 +91,7 @@ impl FallibleStreamingIterator for CodesHandle { mod tests { use crate::{ codes_handle::{CodesHandle, ProductKind}, - KeyType, + DynamicKeyType, }; use anyhow::{Context, Ok, Result}; use fallible_streaming_iterator::FallibleStreamingIterator; @@ -104,17 +104,17 @@ mod tests { let mut handle = CodesHandle::new_from_file(file_path, product_kind)?; let msg1 = handle.next()?.context("Message not some")?; - let key1 = msg1.read_key("typeOfLevel")?; + let key1 = msg1.read_key_dynamic("typeOfLevel")?; let msg2 = handle.next()?.context("Message not some")?; - let key2 = msg2.read_key("typeOfLevel")?; + let key2 = msg2.read_key_dynamic("typeOfLevel")?; let msg3 = handle.next()?.context("Message not some")?; - let key3 = msg3.read_key("typeOfLevel")?; + let key3 = msg3.read_key_dynamic("typeOfLevel")?; - assert_eq!(key1.value, KeyType::Str("isobaricInhPa".to_string())); - assert_eq!(key2.value, KeyType::Str("isobaricInhPa".to_string())); - assert_eq!(key3.value, KeyType::Str("isobaricInhPa".to_string())); + assert_eq!(key1.value, DynamicKeyType::Str("isobaricInhPa".to_string())); + assert_eq!(key2.value, DynamicKeyType::Str("isobaricInhPa".to_string())); + assert_eq!(key3.value, DynamicKeyType::Str("isobaricInhPa".to_string())); Ok(()) } @@ -127,10 +127,10 @@ mod tests { let mut handle = CodesHandle::new_from_file(file_path, product_kind)?; while let Some(msg) = handle.next()? { - let key = msg.read_key("shortName")?; + let key = msg.read_key_dynamic("shortName")?; match key.value { - KeyType::Str(_) => {} + DynamicKeyType::Str(_) => {} _ => panic!("Incorrect variant of string key"), } } @@ -151,9 +151,9 @@ mod tests { } for msg in handle_collected { - let key = msg.read_key("name")?; + let key = msg.read_key_dynamic("name")?; match key.value { - KeyType::Str(_) => {} + DynamicKeyType::Str(_) => {} _ => panic!("Incorrect variant of string key"), } } @@ -207,8 +207,8 @@ mod tests { let mut level = vec![]; while let Some(msg) = handle.next()? { - if msg.read_key("shortName")?.value == KeyType::Str("msl".to_string()) - && msg.read_key("typeOfLevel")?.value == KeyType::Str("surface".to_string()) + if msg.read_key_dynamic("shortName")?.value == DynamicKeyType::Str("msl".to_string()) + && msg.read_key_dynamic("typeOfLevel")?.value == DynamicKeyType::Str("surface".to_string()) { level.push(msg.try_clone()?); } @@ -218,7 +218,7 @@ mod tests { // Find nearest modifies internal KeyedMessage fields so we need mutable reference let level = &level[0]; - println!("{:?}", level.read_key("shortName")); + println!("{:?}", level.read_key_dynamic("shortName")); // Get the four nearest gridpoints of Reykjavik let nearest_gridpoints = level.codes_nearest()?.find_nearest(64.13, -21.89)?; diff --git a/src/keyed_message/mod.rs b/src/keyed_message/mod.rs index 77cc591..76482d2 100644 --- a/src/keyed_message/mod.rs +++ b/src/keyed_message/mod.rs @@ -51,11 +51,11 @@ pub struct KeyedMessage { /// Structure representing a single key in the `KeyedMessage` #[derive(Clone, Debug, PartialEq)] -pub struct Key { +pub struct DynamicKey { #[allow(missing_docs)] pub name: String, #[allow(missing_docs)] - pub value: KeyType, + pub value: DynamicKeyType, } /// Enum representing the value of [`Key`] from the `KeyedMessage` @@ -64,7 +64,7 @@ pub struct Key { /// ecCodes can return several different types of key, which are represented by this enum /// and each variant contains the respective data type. #[derive(Clone, Debug, PartialEq)] -pub enum KeyType { +pub enum DynamicKeyType { #[allow(missing_docs)] Float(f64), #[allow(missing_docs)] @@ -135,13 +135,13 @@ mod tests { let mut handle = CodesHandle::new_from_file(file_path, product_kind)?; let current_message = handle.next()?.context("Message not some")?; - let _ = current_message.read_key("validityDate")?; - let _ = current_message.read_key("validityTime")?; - let _ = current_message.read_key("level")?; - let _ = current_message.read_key("shortName")?; - let _ = current_message.read_key("units")?; - let _ = current_message.read_key("values")?; - let _ = current_message.read_key("typeOfLevel")?; + let _ = current_message.read_key_dynamic("validityDate")?; + let _ = current_message.read_key_dynamic("validityTime")?; + let _ = current_message.read_key_dynamic("level")?; + let _ = current_message.read_key_dynamic("shortName")?; + let _ = current_message.read_key_dynamic("units")?; + let _ = current_message.read_key_dynamic("values")?; + let _ = current_message.read_key_dynamic("typeOfLevel")?; Ok(()) } @@ -174,12 +174,12 @@ mod tests { drop(handle); - let _ = msg.read_key("dataDate")?; - let _ = msg.read_key("jDirectionIncrementInDegrees")?; - let _ = msg.read_key("values")?; - let _ = msg.read_key("name")?; - let _ = msg.read_key("section1Padding")?; - let _ = msg.read_key("experimentVersionNumber")?; + let _ = msg.read_key_dynamic("dataDate")?; + let _ = msg.read_key_dynamic("jDirectionIncrementInDegrees")?; + let _ = msg.read_key_dynamic("values")?; + let _ = msg.read_key_dynamic("name")?; + let _ = msg.read_key_dynamic("section1Padding")?; + let _ = msg.read_key_dynamic("experimentVersionNumber")?; Ok(()) } diff --git a/src/keyed_message/read.rs b/src/keyed_message/read.rs index 926e27a..20c8201 100644 --- a/src/keyed_message/read.rs +++ b/src/keyed_message/read.rs @@ -5,7 +5,7 @@ use crate::{ codes_get_long_array, codes_get_native_type, codes_get_size, codes_get_string, NativeKeyType, }, - Key, KeyType, KeyedMessage, + DynamicKey, DynamicKeyType, KeyedMessage, }; impl KeyedMessage { @@ -57,7 +57,7 @@ impl KeyedMessage { /// Returns [`CodesError::IncorrectKeySize`] when the size of given key is lower than 1. This indicates corrupted data file, /// bug in the crate or bug in the ecCodes library. If you encounter this error please check /// if your file is correct and report it on Github. - pub fn read_key(&self, key_name: &str) -> Result { + pub fn read_key_dynamic(&self, key_name: &str) -> Result { let key_type; unsafe { @@ -76,7 +76,7 @@ impl KeyedMessage { } match value { - Ok(val) => Ok(KeyType::Int(val)), + Ok(val) => Ok(DynamicKeyType::Int(val)), Err(err) => Err(err), } } else if key_size >= 2 { @@ -86,7 +86,7 @@ impl KeyedMessage { } match value { - Ok(val) => Ok(KeyType::IntArray(val)), + Ok(val) => Ok(DynamicKeyType::IntArray(val)), Err(err) => Err(err), } } else { @@ -104,7 +104,7 @@ impl KeyedMessage { } match value { - Ok(val) => Ok(KeyType::Float(val)), + Ok(val) => Ok(DynamicKeyType::Float(val)), Err(err) => Err(err), } } else if key_size >= 2 { @@ -114,7 +114,7 @@ impl KeyedMessage { } match value { - Ok(val) => Ok(KeyType::FloatArray(val)), + Ok(val) => Ok(DynamicKeyType::FloatArray(val)), Err(err) => Err(err), } } else { @@ -128,7 +128,7 @@ impl KeyedMessage { } match value { - Ok(val) => Ok(KeyType::Bytes(val)), + Ok(val) => Ok(DynamicKeyType::Bytes(val)), Err(err) => Err(err), } } @@ -140,14 +140,14 @@ impl KeyedMessage { } match value { - Ok(val) => Ok(KeyType::Str(val)), + Ok(val) => Ok(DynamicKeyType::Str(val)), Err(err) => Err(err), } } }; if let Ok(value) = key_value { - Ok(Key { + Ok(DynamicKey { name: key_name.to_owned(), value, }) @@ -157,9 +157,9 @@ impl KeyedMessage { value = codes_get_bytes(self.message_handle, key_name)?; } - Ok(Key { + Ok(DynamicKey { name: key_name.to_owned(), - value: KeyType::Bytes(value), + value: DynamicKeyType::Bytes(value), }) } } @@ -170,7 +170,7 @@ mod tests { use anyhow::{Context, Result}; use crate::codes_handle::{CodesHandle, ProductKind}; - use crate::{FallibleIterator, FallibleStreamingIterator, KeyType}; + use crate::{FallibleIterator, FallibleStreamingIterator, DynamicKeyType}; use std::path::Path; #[test] @@ -182,36 +182,36 @@ mod tests { let current_message = handle.next()?.context("Message not some")?; - let str_key = current_message.read_key("name")?; + let str_key = current_message.read_key_dynamic("name")?; match str_key.value { - KeyType::Str(_) => {} + DynamicKeyType::Str(_) => {} _ => panic!("Incorrect variant of string key"), } assert_eq!(str_key.name, "name"); - let double_key = current_message.read_key("jDirectionIncrementInDegrees")?; + let double_key = current_message.read_key_dynamic("jDirectionIncrementInDegrees")?; match double_key.value { - KeyType::Float(_) => {} + DynamicKeyType::Float(_) => {} _ => panic!("Incorrect variant of double key"), } assert_eq!(double_key.name, "jDirectionIncrementInDegrees"); - let long_key = current_message.read_key("numberOfPointsAlongAParallel")?; + let long_key = current_message.read_key_dynamic("numberOfPointsAlongAParallel")?; match long_key.value { - KeyType::Int(_) => {} + DynamicKeyType::Int(_) => {} _ => panic!("Incorrect variant of long key"), } assert_eq!(long_key.name, "numberOfPointsAlongAParallel"); - let double_arr_key = current_message.read_key("values")?; + let double_arr_key = current_message.read_key_dynamic("values")?; match double_arr_key.value { - KeyType::FloatArray(_) => {} + DynamicKeyType::FloatArray(_) => {} _ => panic!("Incorrect variant of double array key"), } @@ -260,7 +260,7 @@ mod tests { let mut handle = CodesHandle::new_from_file(file_path, product_kind)?; let current_message = handle.next()?.context("Message not some")?; - let missing_key = current_message.read_key("doesNotExist"); + let missing_key = current_message.read_key_dynamic("doesNotExist"); assert!(missing_key.is_err()); @@ -276,15 +276,15 @@ mod tests { let msg = handle.next()?.context("Message not some")?; - let _ = msg.read_key("dataDate")?; - let _ = msg.read_key("jDirectionIncrementInDegrees")?; - let _ = msg.read_key("values")?; - let _ = msg.read_key("name")?; - let _ = msg.read_key("section1Padding")?; - let _ = msg.read_key("experimentVersionNumber")?; + let _ = msg.read_key_dynamic("dataDate")?; + let _ = msg.read_key_dynamic("jDirectionIncrementInDegrees")?; + let _ = msg.read_key_dynamic("values")?; + let _ = msg.read_key_dynamic("name")?; + let _ = msg.read_key_dynamic("section1Padding")?; + let _ = msg.read_key_dynamic("experimentVersionNumber")?; let _ = msg - .read_key("zero") - .unwrap_or_else(|_| msg.read_key("zeros").unwrap()); + .read_key_dynamic("zero") + .unwrap_or_else(|_| msg.read_key_dynamic("zeros").unwrap()); Ok(()) } diff --git a/src/keyed_message/write.rs b/src/keyed_message/write.rs index 5fcbe50..9784dd4 100644 --- a/src/keyed_message/write.rs +++ b/src/keyed_message/write.rs @@ -6,7 +6,7 @@ use crate::{ codes_get_message, codes_set_bytes, codes_set_double, codes_set_double_array, codes_set_long, codes_set_long_array, codes_set_string, }, - Key, KeyType, KeyedMessage, + DynamicKey, DynamicKeyType, KeyedMessage, }; impl KeyedMessage { @@ -106,24 +106,24 @@ impl KeyedMessage { /// /// This method will return [`CodesInternal`](crate::errors::CodesInternal) /// when internal ecCodes function returns non-zero code. - pub fn write_key(&mut self, key: Key) -> Result<(), CodesError> { + pub fn write_key_dynamic(&mut self, key: DynamicKey) -> Result<(), CodesError> { match key.value { - KeyType::Float(val) => unsafe { + DynamicKeyType::Float(val) => unsafe { codes_set_double(self.message_handle, &key.name, val)?; }, - KeyType::Int(val) => unsafe { + DynamicKeyType::Int(val) => unsafe { codes_set_long(self.message_handle, &key.name, val)?; }, - KeyType::FloatArray(val) => unsafe { + DynamicKeyType::FloatArray(val) => unsafe { codes_set_double_array(self.message_handle, &key.name, &val)?; }, - KeyType::IntArray(val) => unsafe { + DynamicKeyType::IntArray(val) => unsafe { codes_set_long_array(self.message_handle, &key.name, &val)?; }, - KeyType::Str(val) => unsafe { + DynamicKeyType::Str(val) => unsafe { codes_set_string(self.message_handle, &key.name, &val)?; }, - KeyType::Bytes(val) => unsafe { + DynamicKeyType::Bytes(val) => unsafe { codes_set_bytes(self.message_handle, &key.name, &val)?; }, } @@ -138,7 +138,7 @@ mod tests { use crate::{ codes_handle::{CodesHandle, ProductKind}, - FallibleStreamingIterator, Key, KeyType, + FallibleStreamingIterator, DynamicKey, DynamicKeyType, }; use std::{fs::remove_file, path::Path}; @@ -204,16 +204,16 @@ mod tests { let mut handle = CodesHandle::new_from_file(file_path, product_kind)?; let mut current_message = handle.next()?.context("Message not some")?.try_clone()?; - let old_key = current_message.read_key("centre")?; + let old_key = current_message.read_key_dynamic("centre")?; - let new_key = Key { + let new_key = DynamicKey { name: "centre".to_string(), - value: KeyType::Str("cnmc".to_string()), + value: DynamicKeyType::Str("cnmc".to_string()), }; - current_message.write_key(new_key.clone())?; + current_message.write_key_dynamic(new_key.clone())?; - let read_key = current_message.read_key("centre")?; + let read_key = current_message.read_key_dynamic("centre")?; assert_eq!(new_key, read_key); assert_ne!(old_key, read_key); @@ -229,14 +229,14 @@ mod tests { let mut handle = CodesHandle::new_from_file(file_path, product_kind)?; let mut current_message = handle.next()?.context("Message not some")?.try_clone()?; - let old_key = current_message.read_key("centre")?; + let old_key = current_message.read_key_dynamic("centre")?; - let new_key = Key { + let new_key = DynamicKey { name: "centre".to_string(), - value: KeyType::Str("cnmc".to_string()), + value: DynamicKeyType::Str("cnmc".to_string()), }; - current_message.write_key(new_key.clone())?; + current_message.write_key_dynamic(new_key.clone())?; current_message.write_to_file(Path::new("./data/iceland_edit.grib"), false)?; @@ -245,7 +245,7 @@ mod tests { let mut handle = CodesHandle::new_from_file(file_path, product_kind)?; let current_message = handle.next()?.context("Message not some")?; - let read_key = current_message.read_key("centre")?; + let read_key = current_message.read_key_dynamic("centre")?; assert_eq!(new_key, read_key); assert_ne!(old_key, read_key); diff --git a/src/keys_iterator.rs b/src/keys_iterator.rs index 61c0e2d..469a47e 100644 --- a/src/keys_iterator.rs +++ b/src/keys_iterator.rs @@ -11,7 +11,7 @@ use crate::{ codes_keys_iterator_delete, codes_keys_iterator_get_name, codes_keys_iterator_new, codes_keys_iterator_next, }, - Key, KeyedMessage, + DynamicKey, KeyedMessage, }; /// Structure to iterate through keys in [`KeyedMessage`]. @@ -175,7 +175,7 @@ impl KeyedMessage { } impl FallibleIterator for KeysIterator<'_> { - type Item = Key; + type Item = DynamicKey; type Error = CodesError; fn next(&mut self) -> Result, Self::Error> { @@ -188,7 +188,7 @@ impl FallibleIterator for KeysIterator<'_> { next_item_exists = codes_keys_iterator_next(self.iterator_handle)?; } - let key = KeyedMessage::read_key(self.parent_message, &key_name)?; + let key = KeyedMessage::read_key_dynamic(self.parent_message, &key_name)?; self.next_item_exists = next_item_exists; diff --git a/src/lib.rs b/src/lib.rs index 0074eb6..dd4d5e9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -231,5 +231,5 @@ pub use codes_nearest::{CodesNearest, NearestGridpoint}; pub use errors::CodesError; pub use fallible_iterator::{FallibleIterator, IntoFallibleIterator}; pub use fallible_streaming_iterator::FallibleStreamingIterator; -pub use keyed_message::{Key, KeyType, KeyedMessage}; +pub use keyed_message::{DynamicKey, DynamicKeyType, KeyedMessage}; pub use keys_iterator::{KeysIterator, KeysIteratorFlags}; diff --git a/src/message_ndarray.rs b/src/message_ndarray.rs index 2415049..0dc842b 100644 --- a/src/message_ndarray.rs +++ b/src/message_ndarray.rs @@ -3,7 +3,7 @@ use ndarray::{s, Array2, Array3}; -use crate::{errors::MessageNdarrayError, CodesError, KeyType, KeyedMessage}; +use crate::{errors::MessageNdarrayError, CodesError, DynamicKeyType, KeyedMessage}; /// Struct returned by [`KeyedMessage::to_lons_lats_values()`] method. /// The arrays are collocated, meaning that `longitudes[i, j]` and `latitudes[i, j]` are the coordinates of `values[i, j]`. @@ -42,17 +42,17 @@ impl KeyedMessage { /// - When the number of values mismatch with the `Ni` and `Nj` keys #[cfg_attr(docsrs, doc(cfg(feature = "message_ndarray")))] pub fn to_ndarray(&self) -> Result, CodesError> { - let KeyType::Int(ni) = self.read_key("Ni")?.value else { + let DynamicKeyType::Int(ni) = self.read_key_dynamic("Ni")?.value else { return Err(MessageNdarrayError::UnexpectedKeyType("Ni".to_owned()).into()); }; let ni = usize::try_from(ni).map_err(MessageNdarrayError::from)?; - let KeyType::Int(nj) = self.read_key("Nj")?.value else { + let DynamicKeyType::Int(nj) = self.read_key_dynamic("Nj")?.value else { return Err(MessageNdarrayError::UnexpectedKeyType("Nj".to_owned()).into()); }; let nj = usize::try_from(nj).map_err(MessageNdarrayError::from)?; - let KeyType::FloatArray(vals) = self.read_key("values")?.value else { + let DynamicKeyType::FloatArray(vals) = self.read_key_dynamic("values")?.value else { return Err(MessageNdarrayError::UnexpectedKeyType("values".to_owned()).into()); }; @@ -60,7 +60,7 @@ impl KeyedMessage { return Err(MessageNdarrayError::UnexpectedValuesLength(vals.len(), ni * nj).into()); } - let KeyType::Int(j_scanning) = self.read_key("jPointsAreConsecutive")?.value else { + let DynamicKeyType::Int(j_scanning) = self.read_key_dynamic("jPointsAreConsecutive")?.value else { return Err( MessageNdarrayError::UnexpectedKeyType("jPointsAreConsecutive".to_owned()).into(), ); @@ -98,17 +98,17 @@ impl KeyedMessage { /// - When the number of values mismatch with the `Ni` and `Nj` keys #[cfg_attr(docsrs, doc(cfg(feature = "message_ndarray")))] pub fn to_lons_lats_values(&self) -> Result { - let KeyType::Int(ni) = self.read_key("Ni")?.value else { + let DynamicKeyType::Int(ni) = self.read_key_dynamic("Ni")?.value else { return Err(MessageNdarrayError::UnexpectedKeyType("Ni".to_owned()).into()); }; let ni = usize::try_from(ni).map_err(MessageNdarrayError::from)?; - let KeyType::Int(nj) = self.read_key("Nj")?.value else { + let DynamicKeyType::Int(nj) = self.read_key_dynamic("Nj")?.value else { return Err(MessageNdarrayError::UnexpectedKeyType("Nj".to_owned()).into()); }; let nj = usize::try_from(nj).map_err(MessageNdarrayError::from)?; - let KeyType::FloatArray(latlonvals) = self.read_key("latLonValues")?.value else { + let DynamicKeyType::FloatArray(latlonvals) = self.read_key_dynamic("latLonValues")?.value else { return Err(MessageNdarrayError::UnexpectedKeyType("latLonValues".to_owned()).into()); }; @@ -118,7 +118,7 @@ impl KeyedMessage { ); } - let KeyType::Int(j_scanning) = self.read_key("jPointsAreConsecutive")?.value else { + let DynamicKeyType::Int(j_scanning) = self.read_key_dynamic("jPointsAreConsecutive")?.value else { return Err( MessageNdarrayError::UnexpectedKeyType("jPointsAreConsecutive".to_owned()).into(), ); @@ -166,7 +166,7 @@ mod tests { use super::*; use crate::codes_handle::CodesHandle; use crate::FallibleStreamingIterator; - use crate::KeyType; + use crate::DynamicKeyType; use crate::ProductKind; use std::path::Path; @@ -176,7 +176,7 @@ mod tests { let mut handle = CodesHandle::new_from_file(file_path, ProductKind::GRIB)?; while let Some(msg) = handle.next()? { - if msg.read_key("shortName")?.value == KeyType::Str("2d".to_string()) { + if msg.read_key_dynamic("shortName")?.value == DynamicKeyType::Str("2d".to_string()) { let ndarray = msg.to_ndarray()?; // values from xarray @@ -202,7 +202,7 @@ mod tests { let mut handle = CodesHandle::new_from_file(file_path, ProductKind::GRIB)?; while let Some(msg) = handle.next()? { - if msg.read_key("shortName")?.value == KeyType::Str("2d".to_string()) { + if msg.read_key_dynamic("shortName")?.value == DynamicKeyType::Str("2d".to_string()) { let rmsg = msg.to_lons_lats_values()?; let vals = rmsg.values; diff --git a/tests/handle.rs b/tests/handle.rs index c753afb..328bc4e 100644 --- a/tests/handle.rs +++ b/tests/handle.rs @@ -1,7 +1,7 @@ use std::{path::Path, thread}; use anyhow::{Context, Result}; -use eccodes::{CodesHandle, FallibleStreamingIterator, KeyType, ProductKind}; +use eccodes::{CodesHandle, FallibleStreamingIterator, DynamicKeyType, ProductKind}; #[test] fn thread_safety() -> Result<()> { @@ -13,12 +13,12 @@ fn thread_safety() -> Result<()> { let current_message = handle.next()?.context("Message not some")?; for _ in 0..100 { - let _ = current_message.read_key("name")?; + let _ = current_message.read_key_dynamic("name")?; - let str_key = current_message.read_key("name")?; + let str_key = current_message.read_key_dynamic("name")?; match str_key.value { - KeyType::Str(_) => {} + DynamicKeyType::Str(_) => {} _ => panic!("Incorrect variant of string key"), } @@ -35,10 +35,10 @@ fn thread_safety() -> Result<()> { let mut handle = CodesHandle::new_from_file(file_path, ProductKind::GRIB)?; let current_message = handle.next()?.context("Message not some")?; - let long_key = current_message.read_key("numberOfPointsAlongAParallel")?; + let long_key = current_message.read_key_dynamic("numberOfPointsAlongAParallel")?; match long_key.value { - KeyType::Int(_) => {} + DynamicKeyType::Int(_) => {} _ => panic!("Incorrect variant of long key"), } diff --git a/tests/index.rs b/tests/index.rs index 84e10e0..550f3d9 100644 --- a/tests/index.rs +++ b/tests/index.rs @@ -4,7 +4,7 @@ use std::{path::Path, thread}; use anyhow::{Context, Result}; use eccodes::{ - codes_index::Select, CodesError, CodesHandle, CodesIndex, FallibleStreamingIterator, KeyType, + codes_index::Select, CodesError, CodesHandle, CodesIndex, FallibleStreamingIterator, DynamicKeyType, ProductKind, }; use rand::Rng;