summaryrefslogtreecommitdiff
path: root/library
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2023-06-12 16:43:49 +0200
committerLaurenz <laurmaedje@gmail.com>2023-06-12 16:47:46 +0200
commitd3b4d7da9a801dac3af6a3cf52eb55af83adc5f5 (patch)
tree72ab79ed75dddfb7b97ddf02ba4d19c4efc9ea5a /library
parent378ebe5f5601f11c3f428c17bed492012feb251e (diff)
More `bail!` usage
Diffstat (limited to 'library')
-rw-r--r--library/src/compute/construct.rs8
-rw-r--r--library/src/compute/data.rs4
-rw-r--r--library/src/layout/enum.rs2
-rw-r--r--library/src/layout/list.rs2
-rw-r--r--library/src/layout/page.rs2
-rw-r--r--library/src/layout/terms.rs2
-rw-r--r--library/src/math/accent.rs2
-rw-r--r--library/src/meta/bibliography.rs2
-rw-r--r--library/src/meta/numbering.rs2
-rw-r--r--library/src/meta/outline.rs5
-rw-r--r--library/src/text/mod.rs4
-rw-r--r--library/src/visualize/image.rs2
-rw-r--r--library/src/visualize/path.rs2
13 files changed, 19 insertions, 20 deletions
diff --git a/library/src/compute/construct.rs b/library/src/compute/construct.rs
index 5ccefb18..cbb50fd6 100644
--- a/library/src/compute/construct.rs
+++ b/library/src/compute/construct.rs
@@ -171,12 +171,12 @@ cast! {
Component,
v: i64 => match v {
0 ..= 255 => Self(v as u8),
- _ => Err("number must be between 0 and 255")?,
+ _ => bail!("number must be between 0 and 255"),
},
v: Ratio => if (0.0 ..= 1.0).contains(&v.get()) {
Self((v.get() * 255.0).round() as u8)
} else {
- Err("ratio must be between 0% and 100%")?
+ bail!("ratio must be between 0% and 100%");
},
}
@@ -375,7 +375,7 @@ cast! {
v: Ratio => if (0.0 ..= 1.0).contains(&v.get()) {
Self((v.get() * 255.0).round() as u8)
} else {
- Err("ratio must be between 0% and 100%")?
+ bail!("ratio must be between 0% and 100%");
},
}
@@ -437,7 +437,7 @@ cast! {
let mut iter = array.into_iter();
match (iter.next(), iter.next(), iter.next()) {
(Some(a), Some(b), None) => Self(a.cast()?, b.cast()?),
- _ => Err("point array must contain exactly two entries")?,
+ _ => bail!("point array must contain exactly two entries"),
}
},
}
diff --git a/library/src/compute/data.rs b/library/src/compute/data.rs
index 1238c3c3..0d4d4865 100644
--- a/library/src/compute/data.rs
+++ b/library/src/compute/data.rs
@@ -105,11 +105,11 @@ cast! {
let mut chars = v.chars();
let first = chars.next().ok_or("delimiter must not be empty")?;
if chars.next().is_some() {
- Err("delimiter must be a single character")?
+ bail!("delimiter must be a single character");
}
if !first.is_ascii() {
- Err("delimiter must be an ASCII character")?
+ bail!("delimiter must be an ASCII character");
}
Self(first)
diff --git a/library/src/layout/enum.rs b/library/src/layout/enum.rs
index 2204b284..91866d15 100644
--- a/library/src/layout/enum.rs
+++ b/library/src/layout/enum.rs
@@ -294,7 +294,7 @@ cast! {
let mut iter = array.into_iter();
let (number, body) = match (iter.next(), iter.next(), iter.next()) {
(Some(a), Some(b), None) => (a.cast()?, b.cast()?),
- _ => Err("array must contain exactly two entries")?,
+ _ => bail!("array must contain exactly two entries"),
};
Self::new(body).with_number(number)
},
diff --git a/library/src/layout/list.rs b/library/src/layout/list.rs
index a11b019f..9dce466d 100644
--- a/library/src/layout/list.rs
+++ b/library/src/layout/list.rs
@@ -216,7 +216,7 @@ cast! {
v: Content => Self::Content(vec![v]),
array: Array => {
if array.is_empty() {
- Err("array must contain at least one marker")?;
+ bail!("array must contain at least one marker");
}
Self::Content(array.into_iter().map(Value::display).collect())
},
diff --git a/library/src/layout/page.rs b/library/src/layout/page.rs
index 9789b468..3b81f92c 100644
--- a/library/src/layout/page.rs
+++ b/library/src/layout/page.rs
@@ -595,7 +595,7 @@ cast! {
v: GenAlign => match v {
GenAlign::Specific(Align::Left) => Self::Left,
GenAlign::Specific(Align::Right) => Self::Right,
- _ => Err("must be `left` or `right`")?,
+ _ => bail!("must be `left` or `right`"),
},
}
diff --git a/library/src/layout/terms.rs b/library/src/layout/terms.rs
index 8b8a7223..d693f100 100644
--- a/library/src/layout/terms.rs
+++ b/library/src/layout/terms.rs
@@ -158,7 +158,7 @@ cast! {
let mut iter = array.into_iter();
let (term, description) = match (iter.next(), iter.next(), iter.next()) {
(Some(a), Some(b), None) => (a.cast()?, b.cast()?),
- _ => Err("array must contain exactly two entries")?,
+ _ => bail!("array must contain exactly two entries"),
};
Self::new(term, description)
},
diff --git a/library/src/math/accent.rs b/library/src/math/accent.rs
index 4a12f5c5..27397911 100644
--- a/library/src/math/accent.rs
+++ b/library/src/math/accent.rs
@@ -134,6 +134,6 @@ cast! {
v: char => Self::new(v),
v: Content => match v.to::<TextElem>() {
Some(elem) => Value::Str(elem.text().into()).cast()?,
- None => Err("expected text")?,
+ None => bail!("expected text"),
},
}
diff --git a/library/src/meta/bibliography.rs b/library/src/meta/bibliography.rs
index f020f730..661257b4 100644
--- a/library/src/meta/bibliography.rs
+++ b/library/src/meta/bibliography.rs
@@ -633,7 +633,7 @@ fn parse_bib(path_str: &str, src: &str) -> StrResult<Vec<hayagriva::Entry>> {
.map(|error| format_biblatex_error(path_str, src, error))
.unwrap_or_else(|| eco_format!("failed to parse {path_str}"))
}),
- _ => Err("unknown bibliography format (must be .yml/.yaml or .bib)".into()),
+ _ => bail!("unknown bibliography format (must be .yml/.yaml or .bib)"),
}
}
diff --git a/library/src/meta/numbering.rs b/library/src/meta/numbering.rs
index 08d35458..ed71c1be 100644
--- a/library/src/meta/numbering.rs
+++ b/library/src/meta/numbering.rs
@@ -218,7 +218,7 @@ impl FromStr for NumberingPattern {
let suffix = pattern[handled..].into();
if pieces.is_empty() {
- Err("invalid numbering pattern")?;
+ return Err("invalid numbering pattern");
}
Ok(Self { pieces, suffix, trimmed: false })
diff --git a/library/src/meta/outline.rs b/library/src/meta/outline.rs
index 3ba1b2e5..b78cd765 100644
--- a/library/src/meta/outline.rs
+++ b/library/src/meta/outline.rs
@@ -407,9 +407,8 @@ cast! {
/// == Setup
/// ```
///
-/// To completely customize an entry's line, you can also build it from
-/// scratch by accessing the `level`, `element`, `outline`, and `fill`
-/// fields on the entry.
+/// To completely customize an entry's line, you can also build it from scratch
+/// by accessing the `level`, `element`, `body`, and `fill` fields on the entry.
///
/// Display: Outline Entry
/// Category: meta
diff --git a/library/src/text/mod.rs b/library/src/text/mod.rs
index 6090094a..bde5dbac 100644
--- a/library/src/text/mod.rs
+++ b/library/src/text/mod.rs
@@ -644,7 +644,7 @@ cast! {
self => self.0.into_value(),
v: Smart<Dir> => {
if v.map_or(false, |dir| dir.axis() == Axis::Y) {
- Err("text direction must be horizontal")?;
+ bail!("text direction must be horizontal");
}
Self(v)
},
@@ -703,7 +703,7 @@ cast! {
self => self.0.into_value(),
v: i64 => match v {
1 ..= 20 => Self::new(v as u8),
- _ => Err("stylistic set must be between 1 and 20")?,
+ _ => bail!("stylistic set must be between 1 and 20"),
},
}
diff --git a/library/src/visualize/image.rs b/library/src/visualize/image.rs
index 7ea3c871..43983e07 100644
--- a/library/src/visualize/image.rs
+++ b/library/src/visualize/image.rs
@@ -185,7 +185,7 @@ fn load(
"jpg" | "jpeg" => ImageFormat::Raster(RasterFormat::Jpg),
"gif" => ImageFormat::Raster(RasterFormat::Gif),
"svg" | "svgz" => ImageFormat::Vector(VectorFormat::Svg),
- _ => return Err("unknown image format".into()),
+ _ => bail!("unknown image format"),
};
Image::with_fonts(buffer, format, world, fallback_family, alt)
}
diff --git a/library/src/visualize/path.rs b/library/src/visualize/path.rs
index 641095c5..d78abce1 100644
--- a/library/src/visualize/path.rs
+++ b/library/src/visualize/path.rs
@@ -205,7 +205,7 @@ cast! {
(Some(a), Some(b), Some(c), None) => {
AllControlPoints(a.cast()?, b.cast()?, c.cast()?)
},
- _ => Err("path vertex must have 1, 2, or 3 points")?,
+ _ => bail!("path vertex must have 1, 2, or 3 points"),
}
},
}