pub fn apply(
existing: Option<&str>,
rendered: &RenderedSourceFile,
) -> Result<ApplyResult, ApplyError>Expand description
Apply rendered against existing (the current file body, or
None if the file does not exist). Returns the new body to write
and a classification of what changed.
Algorithm:
- If
existingisNone, returnCreatedwith the managed block as the entire body. - Locate one managed-section begin/end pair. Zero pairs -> append the managed block to the file. Multiple pairs -> error.
- Validate the existing begin marker: adapter id matches and
template_versionis not newer than ours. - If the existing block byte-equals
rendered.managed_block, returnNoOp. - If the existing
template_versionis older, returnStaleReplacedwith the section substituted. - Otherwise, return
Updatedwith the section substituted.