file-editor 0.2.0

Clean, elegant API for creating and editing text files
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use file_editor::Editor;

#[test]
fn insert_after_inline_multiline_same_indent() -> std::io::Result<()> {
    let dir = tempfile::tempdir()?;
    let path = dir.path().join("final.txt");

    // marker inside a single line, no surrounding whitespace
    Editor::create(&path)?
        .append("fooBARbaz") // <- marker “BAR” inline
        .insert_after("BAR", "X\ny", /*same_indent=*/ true)
        .save()?;

    // one space auto-inserted before 'X', newline re-indented with zero spaces
    assert_eq!(std::fs::read_to_string(path)?, "fooBAR X\nybaz");
    Ok(())
}