summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2023-03-02 19:44:17 +0100
committerHampusM <hampus@hampusmat.com>2023-03-02 19:44:17 +0100
commitbea6e9cccab30ba915a5d3888a0bd1cd02c9fabd (patch)
tree6db88df0f4c961cb530185e7026b9d07b75591ee
parent656ca92bc5958752d6a12e2a659fe17809fe5e86 (diff)
fix: make informal table align optional
-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),