Expand description
Protocol utilities for third-party crate interoperability.
This module provides utilities for checking renderability, casting objects,
and converting types to renderable representations. It implements Rust equivalents
of Python’s __gilt__ protocol from the library.
§The __gilt__ Protocol
In Python’s library, objects can implement a __gilt__ method that returns
a renderable representation. This module brings that same concept to Rust through
the GiltCast trait.
§Key Types
GiltCast- The core trait for objects that can be converted to renderables. Implement this on your types to make them printable with gilt.IntoRenderable- A conversion trait that allows anyGiltCasttype to be converted to aBox<dyn Renderable>.gilt_cast- Attempt to downcast aBox<dyn Any>to a concrete renderable type.RenderableBox- A type-erased wrapper for renderable values.
§Examples
use gilt::protocol::{GiltCast, IntoRenderable};
use gilt::prelude::*;
// Implement GiltCast for a custom type
struct MyData {
name: String,
value: i32,
}
impl GiltCast for MyData {
fn __gilt__(self) -> Box<dyn gilt::console::Renderable> {
let text = Text::from(format!("{} = {}", self.name, self.value));
Box::new(Panel::new(text))
}
}
// Now MyData can be converted to a renderable
let data = MyData { name: "count".into(), value: 42 };
let renderable = data.into_renderable();Structs§
- Renderable
Box - A type-erased wrapper that can hold any renderable value.
Traits§
- Gilt
Cast - Trait for types that can be converted to a renderable representation.
- Into
Renderable - Trait for types that can be converted into a
Box<dyn Renderable>. - Renderable
Ext - Extension trait for types that implement
Renderable.
Functions§
- as_
renderable_ mut - Attempt to cast a mutable reference to a renderable trait object.
- as_
renderable_ ref - Attempt to cast a reference to a renderable trait object.
- gilt_
cast - Attempt to cast a
Box<dyn Any>to a concrete renderable type. - is_type
- Check if a value is a specific renderable type.