Crate dampen_core

Crate dampen_core 

Source
Expand description

Dampen Core - Parser, IR, and Traits

This crate contains the core types and traits for the Dampen UI framework.

§Overview

Dampen Core provides:

  • XML Parser: Parse .gravity files into an Intermediate Representation (IR)
  • IR Types: Structured representation of UI widgets and bindings
  • Expression Engine: Evaluate binding expressions like {counter} or {if x > 0}
  • Handler Registry: Manage event handlers for UI interactions
  • Code Generation: Generate static Rust code for production builds
  • Backend Traits: Abstract interface for rendering backends

§Quick Start

use dampen_core::parse;

let xml = r#"<column><text value="Hello!" /></column>"#;
let doc = parse(xml).unwrap();
println!("Parsed {} widgets", doc.root.children.len());

§Core Concepts

§Intermediate Representation (IR)

The IR bridges XML parsing and backend rendering:

§Binding Expressions

Expressions in {braces} are parsed into Expr AST nodes:

  • Field access: {user.name}
  • Method calls: {items.len()}
  • Conditionals: {if active then 'yes' else 'no'}
  • Binary operations: {count > 0}

§Event Handlers

Handlers connect UI events to Rust functions:

§Architecture

This crate is backend-agnostic. It defines traits and types but doesn’t implement any specific UI framework. See dampen-iced for the Iced backend.

§Features

  • Zero-copy parsing with roxmltree
  • Type-safe expression evaluation
  • Error recovery with span information
  • Code generation for production builds

§Re-exports

This crate re-exports all public types from its submodules for convenience. See individual modules for detailed documentation.

Re-exports§

pub use binding::BindingValue;
pub use binding::ToBindingValue;
pub use binding::UiBindable;
pub use expr::BinaryOp;
pub use expr::BinaryOpExpr;
pub use expr::BindingError;
pub use expr::BindingErrorKind;
pub use expr::BindingExpr;
pub use expr::ConditionalExpr;
pub use expr::Expr;
pub use expr::FieldAccessExpr;
pub use expr::LiteralExpr;
pub use expr::MethodCallExpr;
pub use expr::UnaryOp;
pub use expr::UnaryOpExpr;
pub use expr::evaluate_binding_expr;
pub use expr::evaluate_expr;
pub use expr::evaluate_formatted;
pub use handler::HandlerEntry;
pub use handler::HandlerRegistry;
pub use handler::HandlerSignature;
pub use ir::AttributeValue;
pub use ir::DampenDocument;
pub use ir::EventBinding;
pub use ir::EventKind;
pub use ir::InterpolatedPart;
pub use ir::SchemaVersion;
pub use ir::Span;
pub use ir::WidgetKind;
pub use ir::WidgetNode;
pub use parser::error::ParseError;
pub use parser::error::ParseErrorKind;
pub use parser::MAX_SUPPORTED_VERSION;
pub use parser::ValidationWarning;
pub use parser::parse;
pub use parser::parse_version_string;
pub use parser::validate_version_supported;
pub use parser::validate_widget_versions;
pub use traits::Backend;
pub use codegen::CodegenError;
pub use codegen::CodegenOutput;
pub use codegen::generate_application;
pub use codegen::validate_handlers;
pub use state::AppState;
pub use expr::tokenize_binding_expr;

Modules§

binding
Binding system types
codegen
Code generation for production builds
expr
handler
Handler system for event dispatch
ir
parser
state
Application state container for Dampen UI views.
traits
Backend abstraction traits

Constants§

VERSION
Version of the Dampen framework