The Render trait controls how cell outputs are displayed. Venus provides default implementations and allows custom rendering.
By default, outputs use Debug formatting:
#[venus::cell]
pub fn numbers() -> Vec<i32> {
vec![1, 2, 3, 4, 5]
}
// Output: [1, 2, 3, 4, 5]Venus provides Render for common types:
| Type | Rendering |
|---|---|
String |
Plain text |
i32, i64, f32, f64 |
Formatted number |
bool |
"true" / "false" |
Vec<T> |
Debug list |
Option<T> |
"Some(x)" / "None" |
serde_json::Value |
Pretty JSON |
Implement Render for custom types:
use venus::Render;
pub struct Report {
pub title: String,
pub data: Vec<f64>,
}
impl Render for Report {
fn render_text(&self) -> String {
format!("{}: {:?}", self.title, self.data)
}
fn render_html(&self) -> Option<String> {
Some(format!(
"<div class='report'>
<h2>{}</h2>
<pre>{:?}</pre>
</div>",
self.title, self.data
))
}
}The trait provides multiple output formats:
pub trait Render {
/// Plain text representation
fn render_text(&self) -> String;
/// HTML representation (optional)
fn render_html(&self) -> Option<String> { None }
/// Image bytes (optional, PNG/SVG)
fn render_image(&self) -> Option<Vec<u8>> { None }
/// Structured data (optional, JSON)
fn render_data(&self) -> Option<serde_json::Value> { None }
}Use Json<T> for pretty-printed JSON:
use venus::Json;
#[venus::cell]
pub fn config() -> Json<Config> {
Json(Config {
name: "Analysis".to_string(),
threshold: 0.5,
})
}Enable DataFrame rendering:
[dependencies]
venus = { version = "0.1", features = ["polars"] }use polars::prelude::*;
#[venus::cell]
pub fn data() -> DataFrame {
df! {
"name" => ["Alice", "Bob"],
"score" => [95, 87]
}.unwrap()
}
// Renders as HTML tableEnable image rendering:
[dependencies]
venus = { version = "0.1", features = ["image"] }use image::DynamicImage;
#[venus::cell]
pub fn chart() -> DynamicImage {
// Create or load image
DynamicImage::new_rgb8(100, 100)
}
// Renders as PNG in outputVenus uses outputs in this order:
render_html()- Rich web displayrender_image()- Visual contentrender_text()- Fallback text
The web UI automatically selects the best available format.