Expand description
§rusty-ts
A Rust port of the moreutils ts utility: prefix each line of stdin with
a timestamp. The CLI binary is the primary user-facing surface; this
library exposes the same line-timestamping logic for programmatic reuse.
§Quick example — library API
use rusty_ts::{TimestamperBuilder, Format, TimezoneSource};
use std::io::{BufReader, Cursor};
let mut ts = TimestamperBuilder::new()
.format(Format::Strftime("%Y-%m-%d %H:%M:%S".into()))
.timezone(TimezoneSource::Utc)
.build()
.expect("valid configuration");
let input = BufReader::new(Cursor::new(b"hello\nworld\n".to_vec()));
for chunk in ts.prefix_lines(input) {
let bytes = chunk.expect("io ok");
print!("{}", String::from_utf8_lossy(&bytes));
}§Library-without-binary
[dependencies]
rusty-ts = { version = "0.1", default-features = false }Disabling default-features drops the cli feature and skips clap,
clap_complete, and anyhow from the dependency closure.
§License
Licensed under either of Apache-2.0 or MIT at your option.
Re-exports§
pub use error::Error;pub use mode::CompatibilityMode;pub use mode::ExplicitChoice;pub use time::tz::TimezoneSource;
Modules§
- cli
cli - CLI surface — clap-derive
Clistruct, post-parse validation, and mode-aware dispatch helpers. - compat_
matrix cli - Compatibility Matrix generator.
- completions
cli completions <shell>subcommand implementation.- error
- Library error type for
rusty-ts. - mode
- Compatibility Mode resolution.
- pipeline
- The stdin → format → stdout line pipeline.
- relative
- Relative-mode (
-r) timestamp rewriter. - time
- Time-rendering machinery: format strings, timezone resolution, clock
sources. See
plan.md§Architecture (Components: Time Renderer, TZ Resolver, Clock Source).
Structs§
- Timestamper
- Configured line-timestamping engine. Cheap to construct (no IO until
prefix_linesis called). Marked#[non_exhaustive]for future evolution. - Timestamper
Builder - Builder for
Timestamper. Every chain method is#[must_use]so silent misuse is caught at compile time.build()performs post-configuration validation and returns the same typed errors the CLI’s post-parse validation produces (e.g.,Error::InvalidUtcWithNamedTzfor FR-020 mirrored at the library layer).
Enums§
- Elapsed
Anchor - Elapsed-time anchor selector.
Absoluteis the default; the other variants correspond to the CLI-i/-sflags. - Format
- Strftime format selector for
TimestamperBuilder.#[non_exhaustive]so future variants (e.g., a precompiled format) can be added in minor releases without breaking semver.
Functions§
- run
cli - Binary entry point shared by
src/main.rsandsrc/bin/ts.rs.