Skip to main content

Timestamper

Struct Timestamper 

Source
#[non_exhaustive]
pub struct Timestamper { /* private fields */ }
Expand description

Configured line-timestamping engine. Cheap to construct (no IO until prefix_lines is called). Marked #[non_exhaustive] for future evolution.

§Example

use rusty_ts::{TimestamperBuilder, Format, TimezoneSource};
use std::io::Cursor;

let ts = TimestamperBuilder::new()
    .format(Format::Strftime("[%H:%M:%S]".into()))
    .utc(true)
    .build()
    .unwrap();

let input = Cursor::new(b"hello\n".to_vec());
let chunks: Vec<Vec<u8>> = ts
    .prefix_lines(input)
    .collect::<Result<_, _>>()
    .unwrap();
assert!(chunks[0].ends_with(b" hello\n"));

Implementations§

Source§

impl Timestamper

Source

pub fn prefix_lines<R: BufRead>( &self, reader: R, ) -> impl Iterator<Item = Result<Vec<u8>, Error>>

Drive a BufRead line source through the timestamper. Returns an iterator over byte-typed output chunks (Vec<u8>); non-UTF-8 payload bytes pass through unchanged per FR-011.

The returned iterator yields one Result<Vec<u8>, io::Error> per input line. Each chunk is the timestamp prefix followed by a two-space separator followed by the payload (including any trailing newline that was present in the input).

Source

pub fn prefix_string_lines<I>(&self, lines: I) -> impl Iterator<Item = String>
where I: IntoIterator<Item = String>,

Convenience adapter for callers who already have UTF-8 String lines. Returns prefixed String chunks. Non-UTF-8 input is impossible at this surface — use prefix_lines if you need byte fidelity.

Source

pub fn format_spec(&self) -> &str

Return the effective strftime format spec — either the builder’s supplied spec or the moreutils default. Used by the iterator implementations.

Source

pub fn compat(&self) -> CompatibilityMode

Return the configured compatibility mode.

Source

pub fn timezone(&self) -> &TimezoneSource

Return a reference to the configured timezone source.

Source

pub fn elapsed_anchor(&self) -> ElapsedAnchor

Return the configured elapsed-time anchor.

Trait Implementations§

Source§

impl Clone for Timestamper

Source§

fn clone(&self) -> Timestamper

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Timestamper

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.