1 unstable release
Uses new Rust 2024
new 0.1.0 | Apr 26, 2025 |
---|
#155 in Text editors
16KB
155 lines
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 file_editor::Editor;
fn main() -> std::io::Result<()> {
Editor::create("notes.txt")? // new file
.append("Rust 🦀 is fun\n")
.prepend("# My Notes\n")
.insert_after("# My Notes", "========\n", true)
.replace("fun", "blazingly fast")
.save()?; // explicit flush
Ok(())
}
Feature table
Verb | Method | Notes |
---|---|---|
Create / open | Editor::create , Editor::open |
|
Rename | rename |
|
Prepend / append | prepend , append |
|
Insert before / after |
insert_before , insert_after same_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
cargo add file-editor # latest on crates.io
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:
cargo run --example insert_after
Contributing
- Fork & clone
cargo fmt --check && cargo clippy --all-targets -- -D warnings
- Add or update tests in
tests/
(use thetempfile
crate) - 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
.