What's the role of manual pointer and vtable management in Anyhow?

64 points findepi 22 comments

anyhow is a popular error-handling library (https://crates.io/crates/anyhow). From API perspective it does not matter how it's internally implemented. Still, the main logic of the ErrorImpl internal type uses manual vtable-like object and explicit pointer management, and so it's also heavily decorated with unsafe.

From the look of it (and simplifying), the public Error is a (thin) owning pointer ErrorImpl (like Box<ErrorImpl>) and ErrorImpl is a reference into generic E associated with some operations (like Box<dyn ETrait>).

What's the role of explicit pointer and vtable management in Anyhow?
What does it achieve that safe Rust cannot do?