summaryrefslogtreecommitdiff
path: root/src/library/structure
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-09-20 19:49:47 +0200
committerLaurenz <laurmaedje@gmail.com>2022-09-20 19:49:47 +0200
commit3760748fddd3b793c79c370398a9d4a3fc5afc04 (patch)
treeb1a615e510aa231cfe9757a9c0a35a375e32e3ba /src/library/structure
parent757a701c1aa2a6fb80033c7e75666661818da6f9 (diff)
Refactor error handling
Diffstat (limited to 'src/library/structure')
-rw-r--r--src/library/structure/doc.rs6
-rw-r--r--src/library/structure/heading.rs8
-rw-r--r--src/library/structure/list.rs8
-rw-r--r--src/library/structure/reference.rs4
-rw-r--r--src/library/structure/table.rs10
5 files changed, 20 insertions, 16 deletions
diff --git a/src/library/structure/doc.rs b/src/library/structure/doc.rs
index cabdb4dc..ba848b64 100644
--- a/src/library/structure/doc.rs
+++ b/src/library/structure/doc.rs
@@ -7,7 +7,11 @@ pub struct DocNode(pub StyleVec<PageNode>);
impl DocNode {
/// Layout the document into a sequence of frames, one per page.
- pub fn layout(&self, world: &dyn World, styles: StyleChain) -> TypResult<Vec<Frame>> {
+ pub fn layout(
+ &self,
+ world: &dyn World,
+ styles: StyleChain,
+ ) -> SourceResult<Vec<Frame>> {
let mut frames = vec![];
for (page, map) in self.0.iter() {
let number = 1 + frames.len();
diff --git a/src/library/structure/heading.rs b/src/library/structure/heading.rs
index c177481f..855c0503 100644
--- a/src/library/structure/heading.rs
+++ b/src/library/structure/heading.rs
@@ -60,7 +60,7 @@ impl HeadingNode {
/// Whether the heading is numbered.
pub const NUMBERED: bool = true;
- fn construct(_: &mut Vm, args: &mut Args) -> TypResult<Content> {
+ fn construct(_: &mut Vm, args: &mut Args) -> SourceResult<Content> {
Ok(Content::show(Self {
body: args.expect("body")?,
level: args.named("level")?.unwrap_or(NonZeroUsize::new(1).unwrap()),
@@ -82,7 +82,7 @@ impl Show for HeadingNode {
}
}
- fn realize(&self, _: &dyn World, _: StyleChain) -> TypResult<Content> {
+ fn realize(&self, _: &dyn World, _: StyleChain) -> SourceResult<Content> {
Ok(Content::block(self.body.clone()))
}
@@ -91,7 +91,7 @@ impl Show for HeadingNode {
world: &dyn World,
styles: StyleChain,
mut realized: Content,
- ) -> TypResult<Content> {
+ ) -> SourceResult<Content> {
macro_rules! resolve {
($key:expr) => {
styles.get($key).resolve(world, self.level)?
@@ -149,7 +149,7 @@ pub enum Leveled<T> {
impl<T: Cast + Clone> Leveled<T> {
/// Resolve the value based on the level.
- pub fn resolve(&self, world: &dyn World, level: NonZeroUsize) -> TypResult<T> {
+ pub fn resolve(&self, world: &dyn World, level: NonZeroUsize) -> SourceResult<T> {
Ok(match self {
Self::Value(value) => value.clone(),
Self::Mapping(mapping) => mapping(level),
diff --git a/src/library/structure/list.rs b/src/library/structure/list.rs
index e9365cd6..f63374f3 100644
--- a/src/library/structure/list.rs
+++ b/src/library/structure/list.rs
@@ -56,7 +56,7 @@ impl<const L: ListKind> ListNode<L> {
#[property(resolve)]
pub const SPACING: BlockSpacing = Ratio::one().into();
- fn construct(_: &mut Vm, args: &mut Args) -> TypResult<Content> {
+ fn construct(_: &mut Vm, args: &mut Args) -> SourceResult<Content> {
Ok(Content::show(Self {
start: args.named("start")?.unwrap_or(1),
tight: args.named("tight")?.unwrap_or(true),
@@ -100,7 +100,7 @@ impl<const L: ListKind> Show for ListNode<L> {
}
}
- fn realize(&self, world: &dyn World, styles: StyleChain) -> TypResult<Content> {
+ fn realize(&self, world: &dyn World, styles: StyleChain) -> SourceResult<Content> {
let mut cells = vec![];
let mut number = self.start;
@@ -148,7 +148,7 @@ impl<const L: ListKind> Show for ListNode<L> {
_: &dyn World,
styles: StyleChain,
realized: Content,
- ) -> TypResult<Content> {
+ ) -> SourceResult<Content> {
let mut above = styles.get(Self::ABOVE);
let mut below = styles.get(Self::BELOW);
@@ -211,7 +211,7 @@ impl Label {
world: &dyn World,
kind: ListKind,
number: usize,
- ) -> TypResult<Content> {
+ ) -> SourceResult<Content> {
Ok(match self {
Self::Default => match kind {
UNORDERED => Content::Text('•'.into()),
diff --git a/src/library/structure/reference.rs b/src/library/structure/reference.rs
index 22dbec01..5d1dab38 100644
--- a/src/library/structure/reference.rs
+++ b/src/library/structure/reference.rs
@@ -6,7 +6,7 @@ pub struct RefNode(pub EcoString);
#[node(showable)]
impl RefNode {
- fn construct(_: &mut Vm, args: &mut Args) -> TypResult<Content> {
+ fn construct(_: &mut Vm, args: &mut Args) -> SourceResult<Content> {
Ok(Content::show(Self(args.expect("label")?)))
}
}
@@ -22,7 +22,7 @@ impl Show for RefNode {
}
}
- fn realize(&self, _: &dyn World, _: StyleChain) -> TypResult<Content> {
+ fn realize(&self, _: &dyn World, _: StyleChain) -> SourceResult<Content> {
Ok(Content::Text(format_eco!("@{}", self.0)))
}
}
diff --git a/src/library/structure/table.rs b/src/library/structure/table.rs
index 08fa5386..f1ca7e03 100644
--- a/src/library/structure/table.rs
+++ b/src/library/structure/table.rs
@@ -30,7 +30,7 @@ impl TableNode {
#[property(resolve, shorthand(around))]
pub const BELOW: Option<BlockSpacing> = Some(Ratio::one().into());
- fn construct(_: &mut Vm, args: &mut Args) -> TypResult<Content> {
+ fn construct(_: &mut Vm, args: &mut Args) -> SourceResult<Content> {
let columns = args.named("columns")?.unwrap_or_default();
let rows = args.named("rows")?.unwrap_or_default();
let base_gutter: Vec<TrackSizing> = args.named("gutter")?.unwrap_or_default();
@@ -72,7 +72,7 @@ impl Show for TableNode {
}
}
- fn realize(&self, world: &dyn World, styles: StyleChain) -> TypResult<Content> {
+ fn realize(&self, world: &dyn World, styles: StyleChain) -> SourceResult<Content> {
let fill = styles.get(Self::FILL);
let stroke = styles.get(Self::STROKE).map(RawStroke::unwrap_or_default);
let padding = styles.get(Self::PADDING);
@@ -98,7 +98,7 @@ impl Show for TableNode {
Ok(child)
})
- .collect::<TypResult<_>>()?;
+ .collect::<SourceResult<_>>()?;
Ok(Content::block(GridNode {
tracks: self.tracks.clone(),
@@ -113,7 +113,7 @@ impl Show for TableNode {
_: &dyn World,
styles: StyleChain,
realized: Content,
- ) -> TypResult<Content> {
+ ) -> SourceResult<Content> {
Ok(realized.spaced(styles.get(Self::ABOVE), styles.get(Self::BELOW)))
}
}
@@ -129,7 +129,7 @@ pub enum Celled<T> {
impl<T: Cast + Clone> Celled<T> {
/// Resolve the value based on the cell position.
- pub fn resolve(&self, world: &dyn World, x: usize, y: usize) -> TypResult<T> {
+ pub fn resolve(&self, world: &dyn World, x: usize, y: usize) -> SourceResult<T> {
Ok(match self {
Self::Value(value) => value.clone(),
Self::Func(func, span) => {