use std::sync::Arc;
use crate::{graph::Graph, validate::ValidationReport};
#[derive(Clone, Debug)]
pub struct PackingError {
pub(crate) graph: Arc<Graph>,
}
#[derive(Debug)]
pub enum Error {
ValidationFailed(ValidationReport),
PackingFailed(PackingError),
}
impl PackingError {
#[cfg(feature = "dot2")]
pub fn write_graph_viz(&self, path: impl AsRef<std::path::Path>) -> std::io::Result<()> {
self.graph.write_graph_viz(path)
}
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Error::ValidationFailed(report) => report.fmt(f),
Error::PackingFailed(error) => error.fmt(f),
}
}
}
impl std::fmt::Display for PackingError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"Table packing failed with {} overflows",
self.graph.find_overflows().len()
)
}
}
impl std::error::Error for PackingError {}
impl std::error::Error for Error {}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn assert_compiler_error_is_send() {
fn send_me_baby<T: Send>() {}
send_me_baby::<Error>();
}
}