Skip to main content

Source

Trait Source 

Source
pub trait Source: Send + Sync {
    // Required methods
    fn name(&self) -> &str;
    fn chunks(
        &self,
    ) -> Box<dyn Iterator<Item = Result<Chunk, SourceError>> + '_>;
    fn as_any(&self) -> &dyn Any;
}
Expand description

Produces chunks of text for the scanner to process. Each implementation handles a different input source.

§Examples

use keyhog_core::{Chunk, ChunkMetadata, Source, SourceError};

struct StaticSource;

impl Source for StaticSource {
    fn name(&self) -> &str {
        "static"
    }

    fn chunks(&self) -> Box<dyn Iterator<Item = Result<Chunk, SourceError>> + '_> {
        Box::new(std::iter::once(Ok(Chunk {
            data: "TOKEN=value".into(),
            metadata: ChunkMetadata {
                source_type: "static".into(),
                ..Default::default()
            },
        })))
    }

    fn as_any(&self) -> &dyn std::any::Any {
        self
    }
}

let source = StaticSource;
assert_eq!(source.name(), "static");

Required Methods§

Source

fn name(&self) -> &str

Human-readable source name used in warnings and telemetry.

Source

fn chunks(&self) -> Box<dyn Iterator<Item = Result<Chunk, SourceError>> + '_>

Yield all readable chunks from this source.

Source

fn as_any(&self) -> &dyn Any

Support downcasting to concrete types.

Implementors§