crate-seq-manifest
Overview
crate-seq-manifest provides safe Cargo.toml manipulation that preserves comments and formatting. It supports version rewriting and path dependency scanning. Used by crate-seq-core during the publish pipeline to set version fields and validate manifests.
Version rewriting — rewrite.rs
rewrite_version
pub fn rewrite_version(
cargo_toml_path: &Path,
version: &semver::Version,
) -> Result<(), Error>Unconditionally rewrites the [package].version field in the specified Cargo.toml to match version. All other fields, comments, and formatting are left intact. The write is idempotent — if the version already matches, the file is still rewritten for consistency. Uses an atomic write for crash safety.
Atomic write
- Writes content to
{path}.toml.tmp - Calls
fs::renameto atomically replace the original - If rename fails, removes the
.tmpfile before returning the error
This ensures a crash mid-write never leaves a corrupted Cargo.toml.
Error conditions
Error::Io— file cannot be read or writtenError::Toml— file is not valid TOMLError::MissingVersion—[package]table orversionkey is absent
Path dependency scanning — deps.rs
path_dependencies
pub fn path_dependencies(
cargo_toml_path: &Path,
) -> Result<Vec<PathDep>, Error>Scans [dependencies], [dev-dependencies], and [build-dependencies] for entries with a path = "..." field. Returns an empty Vec when no path dependencies are present. Handles both inline tables (dep = { path = "...", version = "..." }) and regular tables ([dependencies.dep] with a path key).
PathDep
pub struct PathDep {
pub name: String, // dependency name as declared
pub path: PathBuf, // the path value from the table
}Error type — error.rs
#[derive(Debug, thiserror::Error)]
pub enum Error {
Io { path: PathBuf, source: std::io::Error },
Toml { path: PathBuf, source: toml_edit::TomlError },
MissingVersion(PathBuf),
PathDependency { name: String, path: PathBuf },
}All I/O and TOML errors carry the path that triggered them for actionable diagnostics.
Source files
| File | Responsibility |
|---|---|
rewrite.rs |
Atomic [package].version rewriting with format preservation |
deps.rs |
Path dependency scanning across all dependency tables |
error.rs |
Crate error enum |
lib.rs |
Module declarations and re-exports |