in src/results/table.rs [108:156]
fn format_element_for_cell(elem: Option<&OwnedElement>) -> Result<String> {
let elem = match elem {
None => return Ok("".to_string()),
Some(e) => e,
};
Ok(match elem.ion_type() {
IonType::Null => "null".to_string(),
IonType::Boolean => elem.as_bool().unwrap().to_string(),
IonType::Integer => match elem.as_any_int().unwrap() {
AnyInt::I64(i) => i.to_string(),
AnyInt::BigInt(i) => i.to_string(),
},
IonType::Float => elem.as_f64().unwrap().to_string(),
IonType::Decimal => {
let decimal = elem.as_decimal().unwrap();
match BigDecimal::try_from(decimal.clone()) {
Ok(big) => format!("{}", big),
Err(_) => format!("-0"),
}
}
IonType::Timestamp => {
let ts = elem.as_timestamp().unwrap().clone();
let ct: IonDateTime = ts.try_into()?;
ct.as_datetime().to_rfc3339()
}
IonType::Symbol => elem.as_sym().unwrap().text().unwrap().to_string(),
IonType::String => elem.as_str().unwrap().to_string(),
IonType::Clob | IonType::Blob => {
let bytes = elem.as_bytes().unwrap();
// 32 is a somewhat random number, but also happens to be the length
// of a QldbHash (e.g. the result of `select metadata.hash from
// _ql_committed_foo`). If you pick a number < 32, we won't render
// QldbHashes (which is a shame). Too wide, and tables aren't
// practically useful since they won't fit on a screen.
if bytes.len() <= 32 {
format!("{:02X?}", bytes)
} else {
format!("{} bytes", bytes.len())
}
}
IonType::List | IonType::SExpression => {
let seq = elem.as_sequence().unwrap();
let elems: Vec<_> = seq.iter().collect();
format_table(&elems[..])?
}
IonType::Struct => format_table(&[elem])?,
})
}