Expand description
Serialization module for converting external data formats to Lemma values.
These functions convert data from external formats (JSON, MsgPack, Protobuf)
into typed LiteralValues ready for use with ExecutionPlan::with_typed_values().
The serializers are flexible about input formats while being strict about output types:
- Text facts accept any JSON type (strings pass through, others serialize to JSON)
- Number facts accept JSON numbers or parseable strings
- Percentage facts accept JSON numbers or strings (with or without %)
- Boolean facts accept JSON booleans or keyword strings
- null values are skipped (treated as “fact not provided”)
§Example
ⓘ
use lemma::serialization::from_json;
let json = br#"{"discount": 21, "config": {"key": "value"}, "name": null}"#;
let values = from_json(json, &execution_plan)?;
// discount -> Percentage(21)
// config -> Text("{\"key\":\"value\"}") (if config is a text fact)
// name -> skipped (null)
let plan = execution_plan.with_typed_values(values, &limits)?;Functions§
- deserialize_
fact_ doc_ ref_ map - Custom deserializer for HashMap<FactPath, String> (document references)
- deserialize_
fact_ path_ map - Custom deserializer for HashMap<FactPath, LemmaFact>
- deserialize_
fact_ path_ set - Custom deserializer for HashSet
- deserialize_
fact_ source_ map - Custom deserializer for HashMap<FactPath, Source> (fact sources)
- deserialize_
fact_ type_ map - Custom deserializer for HashMap<FactPath, LemmaType>
- deserialize_
fact_ value_ map - Custom deserializer for HashMap<FactPath, LiteralValue>
- from_
json - Convert JSON values to typed Lemma values using the ExecutionPlan for type information.
- from_
msgpack - Convert MsgPack values to typed Lemma values using the ExecutionPlan for type information.
- from_
protobuf - Convert Protobuf values to typed Lemma values using the ExecutionPlan for type information.
- serialize_
fact_ doc_ ref_ map - Custom serializer for HashMap<FactPath, String> (document references)
- serialize_
fact_ path_ map - Custom serializer for HashMap<FactPath, LemmaFact>
- serialize_
fact_ path_ set - Custom serializer for HashSet
- serialize_
fact_ source_ map - Custom serializer for HashMap<FactPath, Source> (fact sources)
- serialize_
fact_ type_ map - Custom serializer for HashMap<FactPath, LemmaType>
- serialize_
fact_ value_ map - Custom serializer for HashMap<FactPath, LiteralValue>
- serialize_
literal_ value - Custom serializer for LiteralValue that outputs type and value
- serialize_
operation_ result - Custom serializer for OperationResult