term_wm_render/lib.rs
1/// Opaque render backend trait with downcasting capability.
2/// Core crate defines this trait; UI crates downcast to concrete implementations.
3/// This enables true backend independence — core compiles without Ratatui.
4pub trait RenderBackend: std::any::Any {
5 /// Downcast to concrete backend type.
6 fn as_any_mut(&mut self) -> &mut dyn std::any::Any;
7}
8
9/// Abstraction over the terminal output backend.
10/// Uses trait objects (dyn) at the compositor boundary for runtime flexibility.
11/// Performance: vtable indirection is dispatched once per frame/window, not per cell.
12pub trait RenderTarget {
13 fn enter(&mut self) -> std::io::Result<()>;
14 fn exit(&mut self) -> std::io::Result<()>;
15 fn draw<F>(&mut self, f: F) -> std::io::Result<()>
16 where
17 F: FnOnce(&mut dyn RenderBackend);
18 fn repair(&mut self) -> std::io::Result<()> {
19 self.exit()?;
20 self.enter()
21 }
22}