pub enum CanonicalValue {
Null,
Bool(bool),
Number(Number),
String(String),
Bytes(Vec<u8>),
Array(Vec<CanonicalValue>),
Object(Vec<(String, CanonicalValue)>),
}Expand description
Format-agnostic intermediate value used by the Sheeter hub.
Every reader (CSV, TSV, JSON, YAML, XML) produces a CanonicalValue, and
every writer consumes one. Adding a format requires exactly one reader and
one writer, not N-1 pairwise converters, because every spoke composes
through this hub.
Tabular data is represented as Array<Object>. XML documents are
represented as a single-key Object whose key is the root element name,
with attributes prefixed by @ and text stored under #text. Repeated
sibling elements become Array.
§Examples
use sheeter_engine::CanonicalValue;
let v = CanonicalValue::from_json(r#"[{"a":1}]"#).unwrap();
assert_eq!(v.to_csv().unwrap(), "a\n1\n");Variants§
Null
Bool(bool)
Number(Number)
String(String)
Bytes(Vec<u8>)
Array(Vec<CanonicalValue>)
Object(Vec<(String, CanonicalValue)>)
Implementations§
Source§impl CanonicalValue
impl CanonicalValue
Sourcepub fn to_json(&self) -> Result<String, Box<dyn Error>>
pub fn to_json(&self) -> Result<String, Box<dyn Error>>
Serializes the canonical hub to JSON.
§Examples
use sheeter_engine::CanonicalValue;
let v = CanonicalValue::String("x".into());
assert_eq!(v.to_json().unwrap(), r#""x""#);pub fn from_toml(input: &str) -> Result<Self, Box<dyn Error>>
pub fn to_toml(&self) -> Result<String, Box<dyn Error>>
pub fn from_xlsx_workbook( bytes: &[u8], ) -> Result<Vec<(String, Self)>, Box<dyn Error>>
pub fn to_xlsx_workbook( sheets: &[(String, Self)], ) -> Result<Vec<u8>, Box<dyn Error>>
pub fn from_sql_workbook( input: &str, dialect: SqlDialect, ) -> Result<Vec<(String, Self)>, Box<dyn Error>>
pub fn to_sql_workbook( sheets: &[(String, Self)], ) -> Result<String, Box<dyn Error>>
pub fn to_sql_with_table(&self, table: &str) -> Result<String, Box<dyn Error>>
Sourcepub fn from_csv(input: &str) -> Result<Self, Box<dyn Error>>
pub fn from_csv(input: &str) -> Result<Self, Box<dyn Error>>
Parses CSV into the canonical hub.
§Examples
use sheeter_engine::CanonicalValue;
let v = CanonicalValue::from_csv("a\n1").unwrap();
assert_eq!(v.to_json().unwrap(), r#"[{"a":"1"}]"#);Sourcepub fn to_csv(&self) -> Result<String, Box<dyn Error>>
pub fn to_csv(&self) -> Result<String, Box<dyn Error>>
Serializes the canonical hub to CSV.
§Examples
use sheeter_engine::CanonicalValue;
let v = CanonicalValue::from_json(r#"[{"a":1}]"#).unwrap();
assert_eq!(v.to_csv().unwrap(), "a\n1\n");Sourcepub fn from_tsv(input: &str) -> Result<Self, Box<dyn Error>>
pub fn from_tsv(input: &str) -> Result<Self, Box<dyn Error>>
Parses TSV into the canonical hub.
§Examples
use sheeter_engine::CanonicalValue;
let v = CanonicalValue::from_tsv("a\tb\n1\t2").unwrap();
assert_eq!(v.to_json().unwrap(), r#"[{"a":"1","b":"2"}]"#);Sourcepub fn to_tsv(&self) -> Result<String, Box<dyn Error>>
pub fn to_tsv(&self) -> Result<String, Box<dyn Error>>
Serializes the canonical hub to TSV.
§Examples
use sheeter_engine::CanonicalValue;
let v = CanonicalValue::from_json(r#"[{"a":1}]"#).unwrap();
assert_eq!(v.to_tsv().unwrap(), "a\n1\n");Sourcepub fn from_yaml(input: &str) -> Result<Self, Box<dyn Error>>
pub fn from_yaml(input: &str) -> Result<Self, Box<dyn Error>>
Parses YAML into the canonical hub.
§Examples
use sheeter_engine::CanonicalValue;
let v = CanonicalValue::from_yaml("- a: 1\n").unwrap();
assert_eq!(v.to_json().unwrap(), r#"[{"a":1}]"#);Sourcepub fn to_yaml(&self) -> Result<String, Box<dyn Error>>
pub fn to_yaml(&self) -> Result<String, Box<dyn Error>>
Serializes the canonical hub to YAML.
§Examples
use sheeter_engine::CanonicalValue;
let v = CanonicalValue::from_json(r#"[{"a":1}]"#).unwrap();
assert!(v.to_yaml().unwrap().contains("a: 1"));Sourcepub fn from_xml(input: &str) -> Result<Self, Box<dyn Error>>
pub fn from_xml(input: &str) -> Result<Self, Box<dyn Error>>
Parses XML into the canonical hub.
Attributes become @name keys, text content becomes #text, and
repeated sibling elements become arrays. The returned value is an
object with exactly one key: the root element name.
§Examples
use sheeter_engine::CanonicalValue;
let v = CanonicalValue::from_xml("<r><a>1</a><a>2</a></r>").unwrap();
assert_eq!(v.to_json().unwrap(), r#"{"r":{"a":["1","2"]}}"#);Sourcepub fn to_xml(&self) -> Result<String, Box<dyn Error>>
pub fn to_xml(&self) -> Result<String, Box<dyn Error>>
Serializes the canonical hub to XML.
§Examples
use sheeter_engine::CanonicalValue;
let v = CanonicalValue::from_json(r#"[{"a":"1"}]"#).unwrap();
let xml = v.to_xml().unwrap();
assert!(xml.contains("<root>"));
assert!(xml.contains("<a>1</a>"));Source§impl CanonicalValue
impl CanonicalValue
Sourcepub fn from_ndjson(input: &str) -> Result<Self, Box<dyn Error>>
pub fn from_ndjson(input: &str) -> Result<Self, Box<dyn Error>>
Parses NDJSON (newline-delimited JSON) into an array.
Each non-empty line must be a complete JSON value. The result is a
CanonicalValue::Array with one element per line, preserving order.
§Errors
Returns an error if any non-empty line is malformed JSON.
§Examples
use sheeter_engine::CanonicalValue;
let v = CanonicalValue::from_ndjson("{\"a\":1}\n{\"a\":2}\n").unwrap();
assert_eq!(v.to_json().unwrap(), r#"[{"a":1},{"a":2}]"#);Sourcepub fn to_ndjson(&self) -> Result<String, Box<dyn Error>>
pub fn to_ndjson(&self) -> Result<String, Box<dyn Error>>
Serializes the value as NDJSON (one JSON value per line).
Arrays become one line per element. Non-array values become a single line.
§Errors
Returns an error if serialization fails.
§Examples
use sheeter_engine::CanonicalValue;
let v = CanonicalValue::from_json(r#"[{"a":1},{"a":2}]"#).unwrap();
assert_eq!(v.to_ndjson().unwrap(), "{\"a\":1}\n{\"a\":2}\n");