Skip to main content

apply

Function apply 

Source
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:

  1. If existing is None, return Created with the managed block as the entire body.
  2. Locate one managed-section begin/end pair. Zero pairs -> append the managed block to the file. Multiple pairs -> error.
  3. Validate the existing begin marker: adapter id matches and template_version is not newer than ours.
  4. If the existing block byte-equals rendered.managed_block, return NoOp.
  5. If the existing template_version is older, return StaleReplaced with the section substituted.
  6. Otherwise, return Updated with the section substituted.