use crate::metadata::{TypeInfo, TypeRegistry};
use crate::value::WireValue;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct WirePrintResult {
pub rendered: String,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub spans: Vec<WirePrintSpan>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "lowercase")]
pub enum WirePrintSpan {
Literal {
text: String,
start: usize,
end: usize,
span_id: String,
},
Value {
text: String,
start: usize,
end: usize,
span_id: String,
variable_name: Option<String>,
raw_value: Box<WireValue>,
type_info: Box<TypeInfo>,
current_format: String,
type_registry: TypeRegistry,
format_params: HashMap<String, WireValue>,
},
}
impl WirePrintResult {
pub fn simple(text: impl Into<String>) -> Self {
WirePrintResult {
rendered: text.into(),
spans: vec![],
}
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct PrintResult {
pub value: WireValue,
pub type_info: TypeInfo,
pub type_registry: TypeRegistry,
}
impl PrintResult {
pub fn new(value: WireValue, type_info: TypeInfo, type_registry: TypeRegistry) -> Self {
PrintResult {
value,
type_info,
type_registry,
}
}
pub fn from_number(n: f64) -> Self {
PrintResult {
value: WireValue::Number(n),
type_info: TypeInfo::number(),
type_registry: TypeRegistry::for_number(),
}
}
}