Contract documents#
parcel_core::ContractDoc represents a parsed YAML or JSON contract. Related types are in parcel_core::document.
ContractDoc::parse#
pub fn parse(source: &str) -> Result<ContractDoc, Diagnostic>;
source is document text, not a filename. Returns the parsed document or a diagnostic for invalid syntax or document structure. Column and expression checking happens during check_contract or compile.
use parcel_core::ContractDoc;
let source = std::fs::read_to_string("orders.yaml")?;
let doc = ContractDoc::parse(&source)?;
println!("{} v{}", doc.contract, doc.version);
The example is intended inside a function returning Result; both file errors and Diagnostic implement standard error reporting.
ContractDoc::parse_all#
pub fn parse_all(source: &str) -> Result<ContractDoc, Vec<Diagnostic>>;
Returns every structural problem at once instead of the first: unknown or misspelled fields, a missing space after a colon, a rule without its op or on_fail, and values of the wrong kind. Each diagnostic carries the line it is about and, where parcel has one, a suggested fix in help. parse returns the first of these.
Public fields#
Field |
Type |
Meaning |
|---|---|---|
|
|
Contract name. |
|
|
Semantic version ( |
|
|
Owner of the data; selects the owner-specific functions available to the contract. |
|
|
Parent contract name. |
|
|
Data location; may be inherited. |
|
|
Optional data-placement requirements. |
|
|
Output columns; may be inherited. |
|
|
Rules in document order. |
|
|
Types for custom namespace fields. |
|
|
Calculations producing custom row fields. |
|
|
Constants or aggregates producing custom dataset fields. |
Data location and columns#
Type |
Public fields or variants |
Methods |
|---|---|---|
|
|
— |
|
|
— |
|
|
|
|
|
— |
|
|
|
|
|
— |
|
|
— |
Rules#
Rule has six variants, each wrapping its matching document type:
Variant |
Wrapped type and public fields |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
Every rule type also has message: Option<String>, and Rule::message() returns it. AssertOnFail variants are Drop, Deny, and Report. GuaranteeOnFail variants are Deny and Annotate.
impl Rule {
pub fn id(&self) -> &str;
pub fn op_name(&self) -> &'static str;
}
id borrows the rule’s identifier. op_name returns its operation name, such as "assert". For each operation’s behavior and examples, see Rules.
json_schema#
pub fn json_schema() -> serde_json::Value;
Returns the JSON Schema describing contract document structure, for editor and tooling integration.