fontcull_write_fonts/
error.rs1use std::sync::Arc;
4
5use crate::{graph::Graph, validate::ValidationReport};
6
7#[derive(Clone)]
15pub struct PackingError {
16 pub(crate) graph: Arc<Graph>,
18}
19
20#[derive(Debug, Clone)]
22pub enum Error {
23 ValidationFailed(ValidationReport),
29 PackingFailed(PackingError),
35}
36
37impl PackingError {
38 #[cfg(feature = "dot2")]
42 pub fn write_graph_viz(&self, path: impl AsRef<std::path::Path>) -> std::io::Result<()> {
43 self.graph.write_graph_viz(path)
44 }
45}
46
47impl std::fmt::Display for Error {
48 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
49 match self {
50 Error::ValidationFailed(report) => report.fmt(f),
51 Error::PackingFailed(error) => error.fmt(f),
52 }
53 }
54}
55
56impl std::fmt::Display for PackingError {
57 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
58 write!(
59 f,
60 "Table packing failed with {} overflows",
61 self.graph.find_overflows().len()
62 )
63 }
64}
65
66impl std::fmt::Debug for PackingError {
67 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
68 write!(f, "{self}")
69 }
70}
71
72impl std::error::Error for PackingError {}
73impl std::error::Error for Error {}
74
75impl From<ValidationReport> for Error {
76 fn from(value: ValidationReport) -> Self {
77 Error::ValidationFailed(value)
78 }
79}
80
81#[cfg(test)]
82mod tests {
83 use super::*;
84
85 #[test]
87 fn assert_compiler_error_is_send() {
88 fn send_me_baby<T: Send>() {}
89 send_me_baby::<Error>();
90 }
91}