pub trait KeyRead<T> {
// Required methods
fn read_key(&self, name: &str) -> Result<T, CodesError>;
fn read_key_unchecked(&self, name: &str) -> Result<T, CodesError>;
}Expand description
Provides GRIB key reading capabilites. Implemented by CodesMessage for all possible key types.
Required Methods§
Sourcefn read_key(&self, name: &str) -> Result<T, CodesError>
fn read_key(&self, name: &str) -> Result<T, CodesError>
Tries to read a key of given name from CodesMessage. This function checks if key native type
matches the requested type (ie. you cannot read integer as string, or array as a number).
§Example
let mut file = CodesFile::new_from_file("./data/iceland.grib", ProductKind::GRIB)?;
let message = file.ref_message_iter().next()?.context("no message")?;
let short_name: String = message.read_key("shortName")?;
assert_eq!(short_name, "msl");§Errors
Returns WrongRequestedKeySize when trying to read key in non-native type (use unchecked instead).
Returns WrongRequestedKeySize when trying to read array as integer.
Returns IncorrectKeySize when key size is 0. This can indicate corrupted data.
This function will return CodesInternal if ecCodes fails to read the key.
Sourcefn read_key_unchecked(&self, name: &str) -> Result<T, CodesError>
fn read_key_unchecked(&self, name: &str) -> Result<T, CodesError>
Skips all the checks provided by read_key and directly calls ecCodes, ensuring only memory and type safety.
This function has better perfomance than read_key but all error handling and (possible)
type conversions are performed directly by ecCodes.
This function is also useful for (not usually used) keys that return incorrect native type.
§Errors
This function will return CodesInternal if ecCodes fails to read the key.