From bea6e9cccab30ba915a5d3888a0bd1cd02c9fabd Mon Sep 17 00:00:00 2001 From: HampusM Date: Thu, 2 Mar 2023 19:44:17 +0100 Subject: fix: make informal table align optional --- src/informal_table.rs | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/src/informal_table.rs b/src/informal_table.rs index bd633fc..624118b 100644 --- a/src/informal_table.rs +++ b/src/informal_table.rs @@ -49,7 +49,7 @@ pub enum Error pub struct TableGroup { cols: u32, - align: String, + align: Option, column_specs: Vec, head: Vec, body: Vec, @@ -66,9 +66,9 @@ impl TableGroup /// Returns the column alignment. #[must_use] - pub fn align(&self) -> &str + pub fn align(&self) -> Option<&str> { - &self.align + self.align.as_deref() } /// Returns the column specifications. @@ -110,16 +110,13 @@ impl TableGroup .parse::() .map_err(|_| TableGroupError::ColsNotNumber)?; - let align = String::from_utf8( - element - .attributes() - .iter() - .find(|attr| attr.key == "align") - .ok_or(TableGroupError::MissingAlign)? - .value - .clone(), - ) - .map_err(|_| TableGroupError::AlignNotUTF8)?; + let align = match element.attributes().iter().find(|attr| attr.key == "align") { + Some(attr) => Some( + String::from_utf8(attr.value.clone()) + .map_err(|_| TableGroupError::AlignNotUTF8)?, + ), + None => None, + }; let column_specs = element .child_elements() @@ -168,10 +165,6 @@ pub enum TableGroupError #[error("Missing cols")] MissingCols, - /// Missing align element attribute. - #[error("Missing align")] - MissingAlign, - /// Invalid column specification. #[error("Invalid column specification")] InvalidColumnSpec(#[from] ColumnSpecError), -- cgit v1.2.3-18-g5258