#[cfg(feature = "std")]
use core::fmt::{Display, Formatter, Result};
use crate::node::Node;
pub type TaffyResult<T> = core::result::Result<T, TaffyError>;
#[derive(Debug)]
pub enum TaffyError {
ChildIndexOutOfBounds {
parent: Node,
child_index: usize,
child_count: usize,
},
InvalidParentNode(Node),
InvalidChildNode(Node),
InvalidInputNode(Node),
}
#[cfg(feature = "std")]
impl Display for TaffyError {
fn fmt(&self, f: &mut Formatter) -> Result {
match self {
TaffyError::ChildIndexOutOfBounds { parent, child_index, child_count } => {
write!(f, "Index (is {child_index}) should be < child_count ({child_count}) for parent node {parent:?}")
}
TaffyError::InvalidParentNode(parent) => {
write!(f, "Parent Node {parent:?} is not in the Taffy instance")
}
TaffyError::InvalidChildNode(child) => write!(f, "Child Node {child:?} is not in the Taffy instance"),
TaffyError::InvalidInputNode(node) => write!(f, "Supplied Node {node:?} is not in the Taffy instance"),
}
}
}
#[cfg(feature = "std")]
impl std::error::Error for TaffyError {}