trident_explorer/
display.rs1use crate::error::Result;
2use serde::Serialize;
3use std::fmt;
4
5#[derive(Clone, Copy)]
6pub enum DisplayFormat {
7 Cli,
8 JSONPretty,
9 JSON,
10}
11
12impl DisplayFormat {
13 pub fn formatted_string<T>(&self, item: &T) -> Result<String>
14 where
15 T: fmt::Display + Serialize,
16 {
17 match self {
18 DisplayFormat::Cli => Ok(format!("{item}")),
19 DisplayFormat::JSONPretty => Ok(serde_json::to_string_pretty(&item)?),
20 DisplayFormat::JSON => Ok(serde_json::to_string(&item)?),
21 }
22 }
23}