weaveback-tangle reads literate source documents in noweb style, extracts
named code chunks, and writes the resulting files to disk atomically. It is
the second stage of the weaveback pipeline — it receives the macro-expanded
text from weaveback-macro and produces the final generated source files.
Public API
The crate exports five public types:
-
Clip— high-level façade: read sources, expand chunks, write files. -
SafeFileWriter— atomic file writer with content-based modification detection. -
SafeWriterConfig— configuration struct forSafeFileWriter. -
WeavebackDb— SQLite-backed persistent store for baselines and source maps. -
NowebMapEntry— a single row of thenoweb_mapsource-map table, mapping one output line back to its origin in the literate source.
WeavebackError is the unified error type wrapping the three sub-errors
produced by the crate’s internal modules.
Module map
The crate has four modules arranged in a chain:
CLI / Clip (cli.adoc, noweb.adoc)
└─▶ ChunkStore parse chunk syntax; expand references recursively
└─▶ ChunkWriter route @file output ─▶ SafeFileWriter or direct fs
│
▼
SafeFileWriter (safe_writer.adoc)
NamedTempFile staging, formatter, atomic copy, baseline check
│
▼
WeavebackDb (db.adoc)
gen_baselines · noweb_map · src_snapshots · var/macro_defs
| Module | Role |
|---|---|
CLI entry point — argument parsing, |
|
Parse chunk definitions, expand recursively, write via |
|
Atomic writes, content-based diffs, formatter hooks, modification detection |
|
SQLite persistence: baselines, source maps, snapshots, definition spans |
|
Source lookup and line tracing — shared by trace and apply-back |
|
Integration tests for all five modules |
See architecture.adoc for the full pipeline context, including apply-back and the MCP server.
Error hierarchy
WeavebackError ├── Chunk(ChunkError) ← link:noweb.adoc[noweb.rs] — parse/expand errors ├── SafeWriter(SafeWriterError) ← link:safe_writer.adoc[safe_writer.rs] — I/O, security, formatter └── Db(DbError) ← link:db.adoc[db.rs] — SQLite errors
std::io::Error converts to WeavebackError::SafeWriter(SafeWriterError::IoError(_))
so callers can use ? on I/O operations without wrapping manually.
// <[@file weaveback-tangle/src/lib.rs]>=
pub use ChunkError;
use DbError;
use SafeWriterError;
use Error;
pub use crate;
pub use crate;
pub use crate;
pub use crateSafeFileWriter;
pub use crateSafeWriterConfig;
// @@