Skip to main content

Crate rusty_sponge

Crate rusty_sponge 

Source
Expand description

§rusty-sponge

A Rust port of the moreutils sponge utility: soak up all of stdin and write it atomically to a file. The library is the canonical surface; the CLI binary is a thin wrapper around run.

§Quick start

use rusty_sponge::{SpongeBuilder, Target, CompatibilityMode};
use std::io::Cursor;
use std::path::PathBuf;

let mut sponge = SpongeBuilder::new()
    .target(Target::File(PathBuf::from("output.txt")))
    .append(false)
    .compat(CompatibilityMode::Default)
    .build()?;

sponge.run(Cursor::new(b"hello\nworld\n"))?;

§Stability (lockstep SemVer)

The library and binary share a single crate version. Within the 0.x series, minor version bumps may introduce breaking changes per standard Cargo semantics. Every public enum and struct is #[non_exhaustive] so that variant additions are not breaking changes once 1.0 lands.

§Atomic-safety guarantee

When writing to a regular non-symlink file, Sponge::run writes to a sibling tempfile in the target’s parent directory and atomically renames into place. Mid-write failures (panic, IO error, signal) leave the original file untouched. Symlink targets and the cross-volume fallback path explicitly forgo this guarantee — see the crate README for the full compatibility statement.

Re-exports§

pub use error::Error;

Modules§

atomic
Atomic in-place file rewrite: sibling tempfile + atomic rename.
buffer
Hybrid in-memory + tempfile-spill buffer for soaking up stdin.
cli
Command-line interface for rusty-sponge.
error
Library-level error type for rusty_sponge.
mode
Compatibility mode resolution.
signal
Signal-driven cleanup so an in-progress sibling tempfile is removed before the process exits on SIGINT/SIGTERM/SIGHUP (Unix) or CTRL_C_EVENT / CTRL_BREAK_EVENT / CTRL_CLOSE_EVENT (Windows).
strict
Strict moreutils-compat mode entry point.
writethrough
Non-atomic write-through path for symlink and reparse-point targets (FR-010).

Structs§

Sponge
Runtime engine for one sponge invocation. Constructed via SpongeBuilder.
SpongeBuilder
Builder for Sponge. All chain methods are #[must_use].

Enums§

CompatibilityMode
Whether to apply Default-mode ergonomic extensions or Strict moreutils parity.
Target
Where the buffered input should be delivered.

Constants§

DEFAULT_SPILL_THRESHOLD
Default spill threshold (128 MiB).

Functions§

run
Binary entry-point helper used by both src/main.rs and src/bin/sponge.rs.