Skip to main content

Render

Trait Render 

Source
pub trait Render: Display + Serialize { }
Expand description

A value that can be rendered as both human-readable text and JSON.

Render is the core pattern for command output in mz-deploy. Instead of branching on json_output_enabled() at every call site, commands define a single struct that implements both Display (for humans) and Serialize (for machines), then hand it to output():

#[derive(serde::Serialize)]
struct MyResult { name: String, count: usize }

impl fmt::Display for MyResult {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "  ✓ Processed {} items for '{}'", self.count, self.name)
    }
}

log::output(&MyResult { name, count });

Guidelines:

  • Use output() with a Render struct when a command has a single result that should be available in both text and JSON form. This is the default.
  • Use output_json() for paths with no human representation, like NDJSON streaming or machine-only pre-execution plan dumps.
  • Use info!() for supplementary stderr messages (hints, progress) that shouldn’t appear in JSON output.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§