Skip to content

Commit

Permalink
Implementing Display for Section1v4 (#6)
Browse files Browse the repository at this point in the history
* Implementing Display for Section1v4

* fix: writeln should be a Result

* Title for lib documentation
  • Loading branch information
castelao committed May 5, 2023
1 parent 377daf1 commit b9111e7
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion bufr-lib/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//#![deny(missing_docs)]

//! BUFR binary data format
//!
//! Module level docs

mod tables;
Expand Down Expand Up @@ -95,7 +97,10 @@ pub enum Section1 {

impl fmt::Display for Section1 {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
writeln!(f, "{:?}", self)
match self {
Section1::V3(_) => writeln!(f, "{:?}", self),
Section1::V4(s) => writeln!(f, "{}", s),
}
}
}

Expand Down Expand Up @@ -315,6 +320,38 @@ impl Section1v4 {
}
}

impl fmt::Display for Section1v4 {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
writeln!(f, "Section 1 (v4)")?;
writeln!(f, " Section length: {}", self.length())?;
writeln!(
f,
" Master table: {} (version: {})",
self.master_table(),
self.master_table_version()
)?;
writeln!(f, " Sub-center: {}", self.sub_center())?;
writeln!(f, " Center: {}", self.center())?;
writeln!(f, " Update version: {}", self.update_version())?;
writeln!(f, " Optional section: {}", self.optional_section())?;
writeln!(f, " Data category: {}", self.data_category())?;
writeln!(f, " Data sub-category: {}", self.data_subcategory())?;
writeln!(f, " Local sub-category: {}", self.local_subcategory())?;
writeln!(f, " Local table version: {}", self.local_table_version())?;
writeln!(
f,
" Time: {}-{}-{}T{}:{}:{}",
self.year(),
self.month(),
self.day(),
self.hour(),
self.minute(),
self.second()
)?;
writeln!(f, " Local use: {:x?}", self.local_use())
}
}

#[cfg(test)]
mod test_section1 {
use super::Section1v4;
Expand Down

0 comments on commit b9111e7

Please sign in to comment.