Rust port of gram-hs pattern data structure and graph views.
This library provides a faithful port of the gram-hs reference implementation, emphasizing correctness and compatibility while adopting Rust-native idioms. The library is designed as a shared library that compiles for native Rust, WebAssembly, and other target environments.
relateby-pattern, relateby-gram@relateby/pattern, @relateby/graph, @relateby/gramrelateby-pattern with imports relateby.pattern and relateby.gramadapters/wasm/pattern-wasm (discoverable adapter, not a peer Rust library)This project provides comprehensive documentation for understanding the Pattern data structure and Gram notation:
For information on the project's testing infrastructure, see Testing Infrastructure.
This project is a port of the gram-hs reference implementation. The reference implementation is available locally at ../pattern-hs (relative to this repository root).
Key Reference Locations:
../pattern-hs/libs/ - Haskell library implementations - This is the source of truth../pattern-hs/docs/ - Up-to-date documentation about the implementation../pattern-hs/libs/*/tests/ - Test suites for behavioral equivalence verification - Shows expected behavior../pattern-hs/specs/ - Historical notes that guided incremental development (may be outdated, use for context only)All functionality is designed to faithfully replicate the behavior of the Haskell implementation. We are porting the Haskell implementation to idiomatic Rust. When porting features, developers should study the actual Haskell source code in ../pattern-hs/libs/ as the authoritative source and refer to up-to-date documentation in ../pattern-hs/docs/. The historical notes in ../pattern-hs/specs/ guided incremental development and may be useful for understanding the feature's purpose and approach, but they are NOT authoritative and may be outdated.
rustc --version)cargo --version)rustup target add wasm32-unknown-unknownClone the repository:
git clone <repository-url>
cd pattern-rs
Build the library:
cargo build
Run tests:
cargo test
Build for WASM (after installing WASM target):
cargo build --target wasm32-unknown-unknown
This project is organized as a multi-language workspace with peer Rust libraries, public package roots, and a dedicated WASM adapter:
pattern-rs/
├── Cargo.toml # Workspace root configuration
├── crates/
│ ├── pattern-core/ # Core pattern data structures
│ └── gram-codec/ # Gram notation serialization/deserialization
├── adapters/
│ └── wasm/
│ └── pattern-wasm/ # WASM adapter crate for the TypeScript surface
├── typescript/
│ └── packages/
│ ├── pattern/ # Public Pattern + StandardGraph package
│ ├── graph/ # Public graph interfaces and transforms
│ └── gram/ # Public Gram codec package
├── python/
│ └── packages/
│ └── relateby/ # Python distribution root
└── .github/workflows/ # CI/CD configuration
# Build all workspace crates (native target)
cargo build --workspace
# Build a specific crate
cargo build -p pattern-core
# Build for WebAssembly
cargo build --workspace --target wasm32-unknown-unknown
# Run all workspace tests
cargo test --workspace
# Test a specific crate
cargo test -p pattern-core
# Check all crates
cargo check --workspace
# Format all crates
cargo fmt --all
# Lint all crates
cargo clippy --workspace
Before pushing, you can run all CI checks locally:
# Run all CI checks (format, lint, build, test)
./scripts/ci-local.sh
This script runs the same checks that GitHub Actions runs, so you can catch issues before pushing. See .github/workflows/README.md for more details.
The library is designed to be WASM-compatible. All public APIs avoid blocking I/O and file system access unless explicitly feature-flagged. Platform-specific code uses conditional compilation with the wasm feature flag.
The project includes comprehensive testing infrastructure:
proptest for automated test case generationinsta for regression detectioncriterion for performance trackingSee docs/testing-infrastructure.md for detailed documentation and specs/003-test-infrastructure/quickstart.md for usage examples.
For using the gram-hs CLI tool for testing and equivalence checking, see gram-hs CLI Testing Guide.
See the examples/ directory for usage examples:
examples/README.mdexamples/archive/Cargo.toml"Solution: Ensure you're in the repository root directory
rustc"Solution:
rustc --versionrustup update stablewasm32-unknown-unknown not found"Solution: Install WASM target: rustup target add wasm32-unknown-unknown
Solution:
./scripts/ci-local.shrustup default stablecargo clean && cargo build --workspaceTip: Always run ./scripts/ci-local.sh before pushing to catch issues early.
Solution:
cargo build to fetch dependenciesCargo.toml for correct dependency declarationsSolution:
clippy.toml if project-wide configuration neededSolution:
cargo fmt to auto-format coderustfmt.toml is properly configuredWhen porting features from gram-hs, see porting guide for detailed instructions. The guide covers:
../pattern-hsQuick Start for Porting:
../pattern-hs/libs/ - This is the source of truth../pattern-hs/docs/ - Information about the implementation../pattern-hs/libs/*/tests/ - Shows expected behavior../pattern-hs/specs/XXX-feature-name/ (for context only, may be outdated)/speckit.specifyBSD-3-Clause (see LICENSE file)