Add sovereign-router source: router-server.mjs, kernel-registry, agent-registry, omega-field, MAGMA verbs
931572e verified metadata
name: rust-workspace-modules
description: >-
Set up Rust workspace with multiple crates and proper module hierarchy (lib.rs
+ mod.rs)
source: auto-skill
extracted_at: '2026-07-08T06:37:51.363Z'
Rust Workspace with Module Hierarchy
Context
Building a Rust project with multiple crates (engine + API) and deep module structure. Common pitfalls around import paths and module declarations.
Workspace Structure
project/
βββ Cargo.toml # Workspace root
βββ engine/
β βββ Cargo.toml # Library crate
β βββ src/
β βββ lib.rs # Public API exports
β βββ kernel/
β βββ mod.rs # Module declarations
β βββ checker.rs # Implementation
β βββ worm.rs # Implementation
βββ api/
β βββ Cargo.toml # Binary crate, depends on engine
β βββ src/
β βββ main.rs # Uses `engine::` imports
βββ src/
βββ lib.rs # Top-level lib (re-exports)
βββ main.rs # CLI binary
Workspace Cargo.toml
[workspace]
members = ["engine", "api"]
resolver = "2" # REQUIRED for edition 2021+
Pitfall: Without resolver = "2", you get: "virtual workspace defaulting to resolver = "1" despite one or more workspace members being on edition 2021"
Module Hierarchy Pattern
lib.rs β Top-level module tree
// src/lib.rs
pub mod kernel;
pub mod syntax;
kernel/mod.rs β Submodule declarations
// src/kernel/mod.rs
pub mod checker;
pub mod worm;
// Re-export for convenience
pub use checker::{Term, Env, infer, check, verify_proof};
pub use worm::{WormDb, ProofEntry};
Import paths in sibling modules
// src/syntax/parser.rs β importing from kernel
use crate::kernel::checker::Term; // β
Full path from crate root
// NOT: use crate::checker::Term; // β checker is inside kernel module
Binary crate importing library
// src/main.rs or api/src/main.rs
use axiom::kernel::{WormDb, Term, Env, check, verify_proof};
use axiom::syntax::parser;
Common Errors & Fixes
| Error | Cause | Fix |
|---|---|---|
unresolved import crate::checker |
Missing module path segment | Use crate::kernel::checker::Term |
no targets specified in manifest |
Missing src/main.rs or src/lib.rs |
Create the file, check path in Cargo.toml |
resolver = "1" warning |
Workspace missing resolver | Add resolver = "2" to workspace Cargo.toml |
unused import: infer |
Imported but not used in binary | Remove from use statement |
cannot find module serde_wasm_bindgen |
Missing dependency | Add serde-wasm-bindgen = "0.6" to Cargo.toml |
Cargo.toml for Library Crate
[package]
name = "axiom-proof"
version = "0.1.0"
edition = "2021"
[lib]
name = "axiom" # Crate name for imports
path = "src/lib.rs"
[[bin]]
name = "axiom"
path = "src/main.rs"
[dependencies]
sha2 = "0.10"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
Cargo.toml for Dependent Crate
[package]
name = "axiom-api"
version = "0.1.0"
edition = "2021"
[dependencies]
axiom-proof = { path = "../engine" } # Local path dependency
axum = "0.7"
tokio = { version = "1.0", features = ["full"] }
Module Declaration Rules
- lib.rs declares top-level modules β
pub mod kernel;meanssrc/kernel/mod.rs(orsrc/kernel.rs) exists - mod.rs declares submodules β
pub mod checker;insidekernel/mod.rsmeanssrc/kernel/checker.rsexists - Import from crate root β Always use
crate::prefix:use crate::kernel::checker::Term; - Re-exports for ergonomics β
pub use checker::Term;inkernel/mod.rslets users writeuse crate::kernel::Term;
Testing
# Run all tests in workspace
cargo test
# Run tests for specific crate
cargo test -p axiom-proof
# Run with output
cargo test -- --nocapture
When to Use
- Multi-crate Rust projects (engine + API + CLI)
- Projects with deep module hierarchies (kernel/syntax/tactics)
- When separating library from binary
- When one crate depends on another via path dependency