pub trait Render<T> {
// Required method
fn render(data: &T) -> Result<String, ViewRenderError>;
}Expand description
Trait for rendering command output data into a string.
Implementors transform a DTO (T) into a displayable or parseable string.
The Result return type is required even for infallible renderers (e.g., TextView)
so that all renderers share a uniform interface and callers can use ? unconditionally.
§Examples
ⓘ
use crate::presentation::cli::views::{Render, ViewRenderError};
// JSON view — calls serde_json, theoretically fallible
impl Render<ConfigureDetailsData> for JsonView {
fn render(data: &ConfigureDetailsData) -> Result<String, ViewRenderError> {
Ok(serde_json::to_string_pretty(data)?)
}
}
// Text view — pure string formatting, always Ok
impl Render<ConfigureDetailsData> for TextView {
fn render(data: &ConfigureDetailsData) -> Result<String, ViewRenderError> {
Ok(format!("Configuration completed for '{}'", data.environment_name))
}
}Required Methods§
Sourcefn render(data: &T) -> Result<String, ViewRenderError>
fn render(data: &T) -> Result<String, ViewRenderError>
Render data into a string representation.
§Errors
Returns a ViewRenderError if rendering fails. Text renderers always
return Ok; JSON renderers return Err only if serialization fails
(which is unreachable for plain #[derive(Serialize)] types).
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".