diff --git a/Cargo.toml b/Cargo.toml
index 9259b389a..1da808481 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -17,7 +17,6 @@ maintenance = { status = "experimental" }
[dependencies]
libm = "0.1.2"
-simple-error = "0.1"
[features]
default = ["std"]
diff --git a/src/algo.rs b/src/algo.rs
index 8b402c904..09a34e066 100644
--- a/src/algo.rs
+++ b/src/algo.rs
@@ -3,8 +3,6 @@ use alloc::{vec, vec::Vec};
#[cfg(not(feature = "std"))]
use libm::F32Ext;
-use simple_error::SimpleError;
-
use core::f32;
use crate::layout;
@@ -16,6 +14,8 @@ use crate::style::*;
use crate::number::Number::*;
use crate::number::*;
+use crate::result::Result;
+
use crate::geometry::{Point, Rect, Size};
#[derive(Debug, Clone)]
@@ -61,7 +61,7 @@ struct FlexLine<'a> {
offset_cross: f32,
}
-pub fn compute(root: &style::Node, size: Size<Number>) -> Result<layout::Node, SimpleError> {
+pub fn compute(root: &style::Node, size: Size<Number>) -> Result<layout::Node> {
let has_root_min_max = root.min_size.width.is_defined()
|| root.min_size.height.is_defined()
|| root.max_size.width.is_defined()
@@ -130,7 +130,7 @@ fn compute_internal(
node_size: Size<Number>,
parent_size: Size<Number>,
perform_layout: bool,
-) -> Result<ComputeResult, SimpleError> {
+) -> Result<ComputeResult> {
// First we check if we have a result for the given input
{
let layout_cache = node.layout_cache.borrow();
@@ -268,7 +268,7 @@ fn compute_internal(
// TODO - this does not follow spec. See commented out code below
// 3. Determine the flex base size and hypothetical main size of each item:
- flex_items.iter_mut().try_for_each(|child| -> Result<(), SimpleError> {
+ flex_items.iter_mut().try_for_each(|child| -> Result<()> {
// A. If the item has a definite used flex basis, that’s the flex base size.
let flex_basis = child.node.flex_basis.resolve(node_inner_size.main(dir));
@@ -350,7 +350,7 @@ fn compute_internal(
// The hypothetical main size is the item’s flex base size clamped according to its
// used min and max main sizes (and flooring the content box size at zero).
- flex_items.iter_mut().try_for_each(|child| -> Result<(), SimpleError> {
+ flex_items.iter_mut().try_for_each(|child| -> Result<()> {
child.inner_flex_basis = child.flex_basis - child.padding.main(dir) - child.border.main(dir);
// TODO - not really spec abiding but needs to be done somewhere. probably somewhere else though.
@@ -428,7 +428,7 @@ fn compute_internal(
//
// 9.7. Resolving Flexible Lengths
- flex_lines.iter_mut().try_for_each(|line| -> Result<(), SimpleError> {
+ flex_lines.iter_mut().try_for_each(|line| -> Result<()> {
// 1. Determine the used flex factor. Sum the outer hypothetical main sizes of all
// items on the line. If the sum is less than the flex container’s inner main size,
// use the flex grow factor for the rest of this algorithm; otherwise, use the
@@ -445,7 +445,7 @@ fn compute_internal(
// - If using the flex shrink factor: any item that has a flex base size
// smaller than its hypothetical main size
- line.items.iter_mut().try_for_each(|child| -> Result<(), SimpleError> {
+ line.items.iter_mut().try_for_each(|child| -> Result<()> {
// TODO - This is not found by reading the spec. Maybe this can be done in some other place
// instead. This was found by trail and error fixing tests to align with webkit output.
if node_inner_size.main(dir).is_undefined() && is_row {
@@ -589,7 +589,7 @@ fn compute_internal(
// item’s target main size was made smaller by this, it’s a max violation.
// If the item’s target main size was made larger by this, it’s a min violation.
- let total_violation = unfrozen.iter_mut().try_fold(0.0, |acc, child| -> Result<f32, SimpleError> {
+ let total_violation = unfrozen.iter_mut().try_fold(0.0, |acc, child| -> Result<f32> {
// TODO - not really spec abiding but needs to be done somewhere. probably somewhere else though.
// The following logic was developed not from the spec but by trail and error looking into how
// webkit handled various scenarios. Can probably be solved better by passing in
@@ -661,7 +661,7 @@ fn compute_internal(
// used main size and the available space, treating auto as fit-content.
flex_lines.iter_mut().try_for_each(|line| {
- line.items.iter_mut().try_for_each(|child| -> Result<(), SimpleError> {
+ line.items.iter_mut().try_for_each(|child| -> Result<()> {
let child_cross =
child.size.cross(dir).maybe_max(child.min_size.cross(dir)).maybe_min(child.max_size.cross(dir));
@@ -705,7 +705,7 @@ fn compute_internal(
};
flex_lines.iter_mut().try_for_each(|line| {
- line.items.iter_mut().try_for_each(|child| -> Result<(), SimpleError> {
+ line.items.iter_mut().try_for_each(|child| -> Result<()> {
let result = compute_internal(
child.node,
Size {
@@ -1106,12 +1106,12 @@ fn compute_internal(
let mut lines: Vec<Vec<layout::Node>> = vec![];
let mut total_offset_cross = padding_border.cross_start(dir);
- let layout_line = |line: &mut FlexLine| -> Result<(), SimpleError> {
+ let layout_line = |line: &mut FlexLine| -> Result<()> {
let mut children: Vec<layout::Node> = vec![];
let mut total_offset_main = padding_border.main_start(dir);
let line_offset_cross = line.offset_cross;
- let layout_item = |child: &mut FlexItem| -> Result<(), SimpleError> {
+ let layout_item = |child: &mut FlexItem| -> Result<()> {
let result = compute_internal(
child.node,
child.target_size.map(|s| s.to_number()),
@@ -1176,7 +1176,7 @@ fn compute_internal(
};
// Before returning we perform absolute layout on all absolutely positioned children
- let absolute_children: Vec<Result<layout::Node, SimpleError>> = node
+ let absolute_children: Vec<Result<layout::Node>> = node
.children
.iter()
.enumerate()
diff --git a/src/lib.rs b/src/lib.rs
index 005ac93fb..fc6369c67 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -6,6 +6,7 @@ extern crate alloc;
pub mod geometry;
pub mod layout;
pub mod number;
+pub mod result;
pub mod style;
mod algo;
diff --git a/src/result.rs b/src/result.rs
new file mode 100644
index 000000000..c5d2510ad
--- /dev/null
+++ b/src/result.rs
@@ -0,0 +1,3 @@
+use core::any::Any;
+
+pub type Result<T> = core::result::Result<T, Box<Any>>;
diff --git a/src/style.rs b/src/style.rs
index d917074e9..2ca373f71 100644
--- a/src/style.rs
+++ b/src/style.rs
@@ -3,11 +3,10 @@ use alloc::boxed::Box;
#[cfg(not(feature = "std"))]
use alloc::{vec, vec::Vec};
-use simple_error::SimpleError;
-
use crate::algo;
use crate::geometry::{Rect, Size};
use crate::number::Number;
+use crate::result::Result;
#[derive(Copy, Clone, PartialEq, Debug)]
pub enum AlignItems {
@@ -207,7 +206,7 @@ impl Default for Size<Dimension> {
}
}
-type MeasureFunc = Box<Fn(Size<Number>) -> Result<Size<f32>, SimpleError>>;
+type MeasureFunc = Box<Fn(Size<Number>) -> Result<Size<f32>>>;
#[derive(Debug, Clone)]
pub struct LayoutCache {
diff --git a/tests/measure.rs b/tests/measure.rs
index 33d2ee78f..9191c146d 100644
--- a/tests/measure.rs
+++ b/tests/measure.rs
@@ -1,6 +1,5 @@
#[cfg(test)]
mod measure {
- use simple_error::SimpleError;
use stretch::number::OrElse;
#[test]
@@ -480,7 +479,7 @@ mod measure {
},
children: vec![stretch::style::Node {
flex_grow: 1.0,
- measure: Some(Box::new(|_| Err(SimpleError::new("")))),
+ measure: Some(Box::new(|_| Err(Box::new("")))),
..Default::default()
}],
..Default::default()