tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 231Rust 9TOML 3CSS 1345 Definiciones

⎇ c16e2b68359c50134de460348f6f02a5fb10a7e6 src/tree/taffy_tree/error.rs Rust · 47 líneas · 1.8 KB Historia Quién tocó qué crudo

Add `taffy_tree` feature to opt-out of default Taffy tree (#448) fda1f88ed · Martijn Arts ·

1//! The Error types produced by Taffy.
2#[cfg(feature = "std")]
3use core::fmt::{Display, Formatter, Result};
4
5use crate::tree::NodeId;
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: NodeId,
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(NodeId),
24    /// The child node was not found in the [`Taffy`](crate::Taffy) instance.
25    InvalidChildNode(NodeId),
26    /// The supplied node was not found in the [`Taffy`](crate::Taffy) instance.
27    InvalidInputNode(NodeId),
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 {}