shape_wire/
print_result.rs1use crate::metadata::{TypeInfo, TypeRegistry};
7use crate::value::WireValue;
8use serde::{Deserialize, Serialize};
9use std::collections::HashMap;
10
11#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13pub struct WirePrintResult {
14 pub rendered: String,
16
17 #[serde(default, skip_serializing_if = "Vec::is_empty")]
19 pub spans: Vec<WirePrintSpan>,
20}
21
22#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
24#[serde(tag = "type", rename_all = "lowercase")]
25pub enum WirePrintSpan {
26 Literal {
28 text: String,
29 start: usize,
30 end: usize,
31 span_id: String,
32 },
33 Value {
35 text: String,
36 start: usize,
37 end: usize,
38 span_id: String,
39 variable_name: Option<String>,
40 raw_value: Box<WireValue>,
41 type_info: Box<TypeInfo>,
42 current_format: String,
44 type_registry: TypeRegistry,
46 format_params: HashMap<String, WireValue>,
48 },
49}
50
51impl WirePrintResult {
52 pub fn simple(text: impl Into<String>) -> Self {
54 WirePrintResult {
55 rendered: text.into(),
56 spans: vec![],
57 }
58 }
59}
60
61#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
63pub struct PrintResult {
64 pub value: WireValue,
66 pub type_info: TypeInfo,
68 pub type_registry: TypeRegistry,
70}
71
72impl PrintResult {
73 pub fn new(value: WireValue, type_info: TypeInfo, type_registry: TypeRegistry) -> Self {
75 PrintResult {
76 value,
77 type_info,
78 type_registry,
79 }
80 }
81
82 pub fn from_number(n: f64) -> Self {
84 PrintResult {
85 value: WireValue::Number(n),
86 type_info: TypeInfo::number(),
87 type_registry: TypeRegistry::for_number(),
88 }
89 }
90}