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;
// Provided method
fn chunk_identities_are_contiguous(&self) -> bool { ... }
}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§
Provided Methods§
Sourcefn chunk_identities_are_contiguous(&self) -> bool
fn chunk_identities_are_contiguous(&self) -> bool
Whether all chunks for one exact (source_type, path) identity are
emitted contiguously. Dispatch may use this to split unrelated routing
classes without cutting a future cross-chunk dependency.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".