Skip to main content

Module serialize

Module serialize 

Source
Expand description

Rows from any serde::Serialize values: a struct’s fields (or a map’s keys) are columns, and any other value is one value column.

Values go through serde_json’s data model, so a field is typed as JSON would type it (see RecordSource): numbers stay numbers, Options are nullable, nested structs and sequences are described in the schema and shown as compact JSON. read samples every value; source streams, sampling the first DEFAULT_SAMPLE.

use rich_data::{serialize, Value};

#[derive(serde::Serialize)]
struct Deploy { service: &'static str, replicas: u32, healthy: Option<bool> }

let rows = serialize::read([
    Deploy { service: "web", replicas: 3, healthy: Some(true) },
    Deploy { service: "db", replicas: 1, healthy: None },
])
.unwrap();
assert_eq!(rows.columns(), ["service", "replicas", "healthy"]);
assert_eq!(rows.rows()[1], [Value::from("db"), Value::Int(1), Value::Null]);
let healthy = rows.schema().unwrap().field("healthy").unwrap();
assert!(healthy.is_nullable());

Structs§

Records
Values as JSON records, numbered from 1 in errors.

Constants§

DEFAULT_SAMPLE
How many records a streaming source reads ahead to choose its columns and schema, unless told otherwise.

Functions§

read
Read items, sampling every one for the columns and schema.
source
Stream items, sampling the first DEFAULT_SAMPLE for the columns and schema.
source_with_sample
Stream items, sampling the first sample.

Type Aliases§

SerializeSource
A streaming RowSource over Serialize values.