constructo-runtime 0.1.1

The syntax of Constructo data-values: the lexer, parser and printer that generated code depends on
Documentation
  • Coverage
  • 100%
    202 out of 202 items documented0 out of 86 items with examples
  • Size
  • Source code size: 145.9 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.1 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 2s Average build duration of successful builds.
  • all releases: 2s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • sfkleach/constructo
    0 0 2
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • sfkleach

constructo-runtime

The syntax of Constructo data-values: the lexer, the parser, the tree of a value, the printer of values, and what the codecs that constructo codegen writes call.

Who needs it

A program that uses Rust code generated by constructo codegen --lang=rust depends on this crate. The first lines of the generated file name the version that it needs:

//! It needs the crate constructo-runtime 0.1.

and the program adds that version to its own Cargo.toml:

[dependencies]
constructo-runtime = "0.1"

The generated code reads and writes values with this crate, so that it reads the same syntax as constructo check. How the generated code is used is in the spec of constructo codegen.

The tree of a value

A program can also read values without generated code, as a tree that is not checked against any type:

use constructo_runtime::codec::{parse, write_text};

// In a function that returns a `Result`, such as `fn main() -> Result<(), Box<dyn std::error::Error>>`.
let values = parse("Move { x: 1, y: -2, by: \"me\" };")?;
assert_eq!(values[0].tag(), Some("Move"));
assert_eq!(values[0].require_field("by")?.as_str()?, "me");
assert_eq!(values[0].require_field("x")?.as_i64()?, 1);
assert_eq!(write_text(&values), "Move { x: 1, y: -2, by: \"me\" };\n");

A Value has accessors, so a program can read the parts it wants without a match on its kind. The lookups tag, members and field give an Option. require_field and the conversions as_str, as_array, as_bool, as_u64, as_i64 and as_f64 give a Result, whose error says what was wrong and where, in the words of constructo check, such as Missing field by in Move or Expected String but found Nat.

Versions

The version of this crate is that of constructo, since the two are released together, and constructo depends on exactly that version. Before 1.0, as Cargo's rules for compatibility allow, a change to the API that could break a program is made only in a new minor version, and an addition comes in a patch version, so a generated file that names 0.1 works with every 0.1.x.

Licence

MIT, as in LICENSE.