Skip to main content

Crate rusty_ts

Crate rusty_ts 

Source
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§

clicli
CLI surface — clap-derive Cli struct, post-parse validation, and mode-aware dispatch helpers.
compat_matrixcli
Compatibility Matrix generator.
completionscli
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_lines is called). Marked #[non_exhaustive] for future evolution.
TimestamperBuilder
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::InvalidUtcWithNamedTz for FR-020 mirrored at the library layer).

Enums§

ElapsedAnchor
Elapsed-time anchor selector. Absolute is the default; the other variants correspond to the CLI -i / -s flags.
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§

runcli
Binary entry point shared by src/main.rs and src/bin/ts.rs.