pub fn apply_fragment_to_file(
path: &Path,
fragment: &str,
placement: FragmentPlacement,
unique: bool,
mode: ApplyMode,
guard: Option<&PathGuard>,
) -> Result<EditResult>Expand description
Apply a freeform fragment at a required placement anchor on disk (#2032).
Strips Morph-style lazy marker lines (// ... existing code ...), then
inserts after/before the unique anchor or replaces old via the same
plan desugar path as CLI/MCP (plan_apply_fragment_to_replace → tx).
Fail-closed: missing/ambiguous anchors, empty fragment after strip,
PathGuard rejects.
§Example
use patchloom::api::{
ApplyMode, FragmentPlacement, apply_fragment_to_file,
};
use std::path::Path;
let _ = apply_fragment_to_file(
Path::new("src/lib.rs"),
"// ... existing code ...\nfn new() {}\n// ... existing code ...\n",
FragmentPlacement::After("fn foo() {".into()),
true,
ApplyMode::Apply,
None,
)?;