pub trait Source: Send + Sync {
// Required methods
fn open(&self) -> Result<Box<dyn SourceIterator>>;
fn name(&self) -> &str;
// Provided method
fn len_hint(&self) -> Option<u64> { ... }
}Expand description
A source of training data.
Sources are lazy - they describe WHERE data comes from, not the data itself. Data is only loaded when the pipeline pulls from the source.
§Implementing a Source
use tenshift_core::source::{Source, SourceIterator};
use tenshift_core::sample::Sample;
use tenshift_core::error::Result;
struct MyDatabase {
connection_string: String,
}
impl Source for MyDatabase {
fn open(&self) -> Result<Box<dyn SourceIterator>> {
// Open connection, return iterator over rows
}
fn len_hint(&self) -> Option<u64> {
None // unknown size
}
fn name(&self) -> &str {
"my_database"
}
}Required Methods§
Sourcefn open(&self) -> Result<Box<dyn SourceIterator>>
fn open(&self) -> Result<Box<dyn SourceIterator>>
Create an iterator over samples from this source.
Called once per epoch. The iterator is consumed by the pipeline’s worker threads.
§Errors
Returns an error if the source cannot be opened (e.g., file not found, network unreachable, invalid credentials).
Provided Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".