use smol_bytes::Utf8Bytes;
use super::{EdgeId, NodeId};
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct EdgeEndpointError {
edge: EdgeId,
node: NodeId,
node_count: usize,
}
impl EdgeEndpointError {
#[inline]
pub(crate) const fn new(edge: EdgeId, node: NodeId, node_count: usize) -> Self {
Self {
edge,
node,
node_count,
}
}
#[inline]
pub const fn edge(&self) -> EdgeId {
self.edge
}
#[inline]
pub const fn node(&self) -> NodeId {
self.node
}
#[inline]
pub const fn node_count(&self) -> usize {
self.node_count
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DirectFanoutError {
node: NodeId,
name: Utf8Bytes,
out_count: usize,
}
impl DirectFanoutError {
#[inline]
pub(crate) const fn new(node: NodeId, name: Utf8Bytes, out_count: usize) -> Self {
Self {
node,
name,
out_count,
}
}
#[inline]
pub const fn node(&self) -> NodeId {
self.node
}
#[inline]
pub fn name(&self) -> &str {
self.name.as_str()
}
#[inline]
pub const fn out_count(&self) -> usize {
self.out_count
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct CycleError {
node: NodeId,
name: Utf8Bytes,
}
impl CycleError {
#[inline]
pub(crate) const fn new(node: NodeId, name: Utf8Bytes) -> Self {
Self { node, name }
}
#[inline]
pub const fn node(&self) -> NodeId {
self.node
}
#[inline]
pub fn name(&self) -> &str {
self.name.as_str()
}
}
#[derive(
Debug,
Clone,
PartialEq,
Eq,
derive_more::Display,
derive_more::IsVariant,
derive_more::Unwrap,
derive_more::TryUnwrap,
)]
#[unwrap(ref, ref_mut)]
#[try_unwrap(ref, ref_mut)]
#[non_exhaustive]
pub enum ArrangeError {
#[display(
"{} endpoint {} is out of range; the graph declares {} node(s)",
_0.edge(), _0.node(), _0.node_count()
)]
EdgeEndpointOutOfRange(EdgeEndpointError),
#[display(
"{} (`{}`) has {} out-edges including a Direct edge; Direct must be exclusive",
_0.node(), _0.name(), _0.out_count()
)]
DirectFanout(DirectFanoutError),
#[display("graph cycle through {} (`{}`)", _0.node(), _0.name())]
Cycle(CycleError),
}
impl core::error::Error for ArrangeError {}
#[cfg(test)]
mod tests;