src/source/mod.rs

//! Input source abstractions.
//!
//! A [`Source`] yields lines asynchronously. Implementations exist for files,
//! stdin, and a "merged" multi-source that round-robins several sources and
//! tags each line with its origin.

pub mod file;
pub mod multi;
pub mod stdin;

use anyhow::Result;

/// A single line delivered by a source.
#[derive(Debug, Clone)]
pub struct LineItem {
    /// The line payload, without trailing newline.
    pub line: String,
    /// Path or label of the producing source, used for color hashing.
    pub origin: String,
    /// Monotonic counter, used for relative ordering when timestamps are
    /// unavailable.
    pub seq: u64,
}

/// A source of log lines.
#[async_trait::async_trait]
pub trait Source: Send {
    /// Pull the next line. Returns `Ok(None)` on clean EOF.
    async fn next_line(&mut self) -> Result<Option<LineItem>>;

    /// A stable label for this source, shown in the origin column.
    fn label(&self) -> &str;
}