file-editor
Clean, chain-friendly text-file editing for Rust • edition 2024
file-editor is a zero-dependency library that makes it painless to create,
modify and query UTF-8 text files.
All mutating methods return &mut self, so edits compose naturally:
use Editor;
Feature table
| Verb | Method | Notes |
|---|---|---|
| Create / open | Editor::create, Editor::open |
|
| Rename | rename |
|
| Prepend / append | prepend, append |
|
| Insert before / after | insert_before, insert_aftersame_indent flag keeps indentation |
|
| Replace one marker | replace_marker |
|
| Search pattern | find_lines → 1-based line numbers |
|
| Erase, replace, mask | erase, replace, mask |
|
| Save to disk | save |
Road-map → regex feature, streaming mode, companion CLI.
Install
Requires Rust 1.85 (edition 2024) or newer.
Workflow
| Task | Command |
|---|---|
| Build | cargo build |
| Run all tests & doctests | cargo test |
| Format | cargo fmt --all |
| Lint (deny warnings) | cargo clippy --all-targets -- -D warnings |
| Coverage (HTML) | cargo llvm-cov --workspace --open(one-time cargo install cargo-llvm-cov) |
| Generate docs | cargo doc --no-deps --open |
CI executes the same steps (see .github/workflows/ci.yml).
Runnable examples
All live in examples/ and write their output to
examples/sandbox/ (ignored by git):
| Example | Demonstrates |
|---|---|
basic.rs |
End-to-end mini workflow |
create.rs |
create + append |
open_rename.rs |
open, rename |
prepend.rs, append.rs |
header / footer insertion |
insert_before.rs |
block insertion above a marker |
insert_after.rs |
block insertion below a marker |
replace_marker.rs |
in-place marker replacement |
find_lines.rs |
pattern search |
erase.rs |
deleting fragments |
replace.rs, mask.rs |
global replacements / masking |
Run any of them with:
Contributing
- Fork & clone
cargo fmt --check && cargo clippy --all-targets -- -D warnings- Add or update tests in
tests/(use thetempfilecrate) - Open a PR describing what and why
All contributions are released under the MIT licence.
Licence
Copyright © 2025
Licensed under the MIT License. See LICENSE.