name: rust-wasm
description: Rust development patterns for the FD workspace (crate structure, testing, WASM)
Rust + WASM Development Skill
Workspace Layout
fast-draft/
├── Cargo.toml # Workspace root
├── crates/
│ ├── fd-core/ # Data model, parser, emitter, layout
│ ├── fd-render/ # Vello/wgpu renderer, hit testing
│ └── fd-editor/ # Sync engine, tools, undo/redo, input
├── fd-vscode/ # VS Code extension (TypeScript + WASM)
└── examples/
└── demo.fd
Common Commands
Build & Test
cargo check --workspace # Fast type check
cargo test --workspace # Run all tests
cargo test -p fd-core # Test one crate
cargo test -- --nocapture # See println!/dbg! output
cargo clippy --workspace # Lint
cargo fmt --all # Format
WASM Build
# Install wasm-pack if needed
cargo install wasm-pack
# Build for web target
wasm-pack build crates/fd-render --target web
# Build with specific features
wasm-pack build crates/fd-render --target web -- --features wasm
Coding Patterns
Adding a New Node Type
- Add variant to
NodeKind enum in crates/fd-core/src/model.rs
- Add parsing logic in
parse_node() in crates/fd-core/src/parser.rs
- Add emission logic in
emit_node() in crates/fd-core/src/emitter.rs
- Add intrinsic size in
intrinsic_size() in crates/fd-core/src/layout.rs
- Add rendering in
paint_node() in crates/fd-render/src/paint.rs
- Add hit testing in
hit_test_node() in crates/fd-render/src/hit.rs
- Write tests for round-trip: parse → emit → re-parse
Adding a New Style Property
- Add field to
Style struct in model.rs
- Parse it in
parse_style_property() and parse_node_property() in parser.rs
- Emit it in
emit_style_block() and emit_node() in emitter.rs
- Merge it in
merge_style() in model.rs
- Apply it to rendering in
paint.rs
Adding a New Tool
- Implement the
Tool trait in crates/fd-editor/src/tools.rs
- Handle input events → produce
GraphMutation values
- Register in tool selection (future: toolbar UI)
Adding a New Constraint
- Add variant to
Constraint enum in model.rs
- Parse in
parse_constraint_line() / parse_node_property()
- Emit in
emit_constraint() in emitter.rs
- Resolve in
apply_constraint() in layout.rs
Key Dependencies
| Crate |
Purpose |
Docs |
petgraph |
DAG for scene graph |
docs.rs |
winnow |
Streaming parser |
docs.rs |
lasso |
String interning for NodeId |
docs.rs |
smallvec |
Inline small arrays |
docs.rs |
vello |
GPU 2D renderer |
docs.rs |
wgpu |
GPU abstraction |
docs.rs |
serde |
Serialization traits |
docs.rs |
Testing Conventions
- Every new parser feature must have a round-trip test
- Test files go in
examples/ as .fd files
- Use
pretty_assertions for diff-friendly assertions
- Test names:
parse_<feature>, emit_<feature>, roundtrip_<feature>, layout_<feature>