tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 583HTML 275Markdown 8TOML 41586 Definiciones

⎇ 0.3.x src/error.rs Rust · 47 líneas · 1.9 KB Historia Quién tocó qué crudo

Fix benchmark measurement (#279) fb07aa8a6 · Nico Burns ·

1//! The Error types produced by Taffy.
2#[cfg(feature = "std")]
3use core::fmt::{Display, Formatter, Result};
4
5use crate::node::Node;
6
7/// The error Taffy generates on invalid operations
8pub type TaffyResult<T> = core::result::Result<T, TaffyError>;
9
10/// An error that occurs while trying to access or modify a [`Node`]'s children by index.
11#[derive(Debug)]
12pub enum TaffyError {
13    /// The parent [`Node`] does not have a child at `child_index`. It only has `child_count` children
14    ChildIndexOutOfBounds {
15        /// The parent node whose child was being looked up
16        parent: Node,
17        /// The index that was looked up
18        child_index: usize,
19        /// The total number of children the parent has
20        child_count: usize,
21    },
22    /// The parent [`Node`] was not found in the [`Taffy`](crate::Taffy) instance.
23    InvalidParentNode(Node),
24    /// The child [`Node`] was not found in the [`Taffy`](crate::Taffy) instance.
25    InvalidChildNode(Node),
26    /// The supplied [`Node`] was not found in the [`Taffy`](crate::Taffy) instance.
27    InvalidInputNode(Node),
28}
29
30#[cfg(feature = "std")]
31impl Display for TaffyError {
32    fn fmt(&self, f: &mut Formatter) -> Result {
33        match self {
34            TaffyError::ChildIndexOutOfBounds { parent, child_index, child_count } => {
35                write!(f, "Index (is {child_index}) should be < child_count ({child_count}) for parent node {parent:?}")
36            }
37            TaffyError::InvalidParentNode(parent) => {
38                write!(f, "Parent Node {parent:?} is not in the Taffy instance")
39            }
40            TaffyError::InvalidChildNode(child) => write!(f, "Child Node {child:?} is not in the Taffy instance"),
41            TaffyError::InvalidInputNode(node) => write!(f, "Supplied Node {node:?} is not in the Taffy instance"),
42        }
43    }
44}
45
46#[cfg(feature = "std")]
47impl std::error::Error for TaffyError {}