summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/informal_table.rs27
1 files 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<String>,
column_specs: Vec<ColumnSpec>,
head: Vec<TableRow>,
body: Vec<TableRow>,
@@ -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::<u32>()
.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),