Skip to main content

Crate crdt_codegen

Crate crdt_codegen 

Source
Expand description

§crdt-codegen

Code generation from TOML schema definitions for crdt-kit.

Reads a crdt-schema.toml file and generates a complete persistence layer organized for Clean Architecture / Hexagonal Architecture:

  • models/ — Versioned Rust structs with #[crdt_schema] annotations
  • migrations/ — Migration functions with #[migration] annotations + helpers
  • repositories/ — Repository traits (ports) and CrdtDb-backed implementations (adapters)
  • store.rs — Unified Persistence<S> entry point with scoped repository access
  • events/ — Event sourcing types, snapshots, and policies (optional)
  • sync/ — Delta sync and state-based merge helpers for CRDT entities (optional)

All generated files contain a header marking them as auto-generated.

§Example

use crdt_codegen::generate_from_str;

let toml = r#"
[config]
output = "src/persistence"

[[entity]]
name = "Task"
table = "tasks"

[[entity.versions]]
version = 1
fields = [
    { name = "title", type = "String" },
    { name = "done", type = "bool" },
]
"#;

let output = generate_from_str(toml).unwrap();
assert_eq!(output.output_dir, "src/persistence");
assert!(!output.files.is_empty());

Modules§

templates

Structs§

Entity
A single entity definition with one or more versioned schemas.
EntityVersion
A specific version of an entity’s schema.
Field
A single field within an entity version.
GeneratedFile
A single generated file ready to be written to disk.
GeneratedOutput
The complete output of the code-generation process.
SchemaConfig
Global code-generation configuration.
SchemaFile
Top-level schema file structure parsed from crdt-schema.toml.
ValidationError
A single validation error with context about where it occurred.

Enums§

CodegenError
Error type for the code-generation process.

Functions§

generate
Parse a TOML schema file from disk and generate all code.
generate_from_schema
Generate code from an already-parsed schema.
generate_from_str
Parse a TOML string and generate all code.
validate_schema
Validate a parsed schema file. Returns Ok(()) if valid, or a list of errors.