Skip to content

Commit

Permalink
Add doc comments on functions
Browse files Browse the repository at this point in the history
  • Loading branch information
noritada committed Oct 31, 2023
1 parent a4ace9a commit 2123978
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,52 @@ impl Display for TemplateInfo {
}
}

/// Reads a `Grib2` instance from an I/O stream of GRIB2.
///
/// # Examples
///
/// ```
/// fn main() -> Result<(), Box<dyn std::error::Error>> {
/// let f = std::fs::File::open(
/// "testdata/icon_global_icosahedral_single-level_2021112018_000_TOT_PREC.grib2",
/// )?;
/// let f = std::io::BufReader::new(f);
/// let result = grib::from_reader(f);
///
/// assert!(result.is_ok());
/// let grib2 = result?;
/// assert_eq!(grib2.len(), 1);
/// Ok(())
/// }
/// ```
pub fn from_reader<SR: Read + Seek>(
reader: SR,
) -> Result<Grib2<SeekableGrib2Reader<SR>>, GribError> {
Grib2::<SeekableGrib2Reader<SR>>::read_with_seekable(reader)
}

/// Reads a `Grib2` instance from bytes of GRIB2.
///
/// # Examples
///
/// ```
/// use std::io::Read;
///
/// fn main() -> Result<(), Box<dyn std::error::Error>> {
/// let f = std::fs::File::open(
/// "testdata/icon_global_icosahedral_single-level_2021112018_000_TOT_PREC.grib2",
/// )?;
/// let mut f = std::io::BufReader::new(f);
/// let mut buf = Vec::new();
/// f.read_to_end(&mut buf).unwrap();
/// let result = grib::from_slice(&buf);
///
/// assert!(result.is_ok());
/// let grib2 = result?;
/// assert_eq!(grib2.len(), 1);
/// Ok(())
/// }
/// ```
pub fn from_slice(bytes: &[u8]) -> Result<Grib2<SeekableGrib2Reader<Cursor<&[u8]>>>, GribError> {
let reader = Cursor::new(bytes);
Grib2::<SeekableGrib2Reader<Cursor<&[u8]>>>::read_with_seekable(reader)
Expand Down

0 comments on commit 2123978

Please sign in to comment.