pub fn ensure_dependency(
cargo_toml: &Path,
name: &str,
spec: &str,
) -> Result<bool, CodegenError>Expand description
Ensure <name> = <spec> is listed under [dependencies] in a
Cargo.toml.
Ok(true) = added, Ok(false) = already there (idempotent),
Err(_) = the file has no [dependencies] section to add it to, and the
caller should report it rather than invent one.
The generator needs this because code scaffolded into a plugin crate
usually needs a dependency the plugin doesn’t have yet — a REST permission
class in plugins/blog/ doesn’t compile until plugins/blog/Cargo.toml
depends on umbral-rest. Writing the file and leaving the crate unable to
build it is a generator that produced a broken project.
String surgery, not a TOML rewrite: comments, ordering and formatting of the existing manifest all survive.