Struct grib::Grib2SubmessageDecoder

source ·
pub struct Grib2SubmessageDecoder { /* private fields */ }
Expand description

Decoder for grid point values of GRIB2 submessages.

§Examples

use grib::Grib2SubmessageDecoder;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let f =
        std::fs::File::open("testdata/CMC_glb_TMP_ISBL_1_latlon.24x.24_2021051800_P000.grib2")?;
    let f = std::io::BufReader::new(f);
    let grib2 = grib::from_reader(f)?;
    let (_index, first_submessage) = grib2.iter().next().unwrap();

    let decoder = Grib2SubmessageDecoder::from(first_submessage)?;
    let mut decoded = decoder.dispatch()?;
    assert_eq!(decoded.size_hint(), (1126500, Some(1126500)));

    let first_value = decoded.next();
    assert_eq!(first_value.map(|f| f.round()), Some(236.0_f32));

    let last_value = decoded.nth(1126498);
    assert_eq!(last_value.map(|f| f.round()), Some(286.0_f32));

    let next_to_last_value = decoded.next();
    assert_eq!(next_to_last_value, None);
    Ok(())
}

Implementations§

source§

impl Grib2SubmessageDecoder

source

pub fn from<R: Grib2Read>( submessage: SubMessage<'_, R>, ) -> Result<Self, GribError>

Sets up a decoder for grid point values of submessage.

source

pub fn dispatch( &self, ) -> Result<Grib2DecodedValues<'_, impl Iterator<Item = f32> + '_>, GribError>

Dispatches a decoding process and gets an iterator of decoded values.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.